using Jacobi.Vst.Core; using Jacobi.Vst.Core.Host; using System; using System.Diagnostics; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor.VST; public class HostCommandStub : IVstHostCommandStub { public VstTimeInfo myVstTimeInfo = new VstTimeInfo() { //SmpteFrameRate = VstSmpteFrameRate.VstSmpteFrameRate.Smpte249fps. PpqPosition = 0, NanoSeconds = 0, SamplePosition = 0, SampleRate = 44100, TimeSignatureNumerator = 4, TimeSignatureDenominator = 4, BarStartPosition = 1, CycleStartPosition = 0, CycleEndPosition = 0, SmpteOffset = 0, SamplesToNearestClock = 0, Tempo = 60, Flags = nonPlayingFlags }; public delegate void ChangeWindowSize(int width, int height); public ChangeWindowSize? WindowSizeChanged; public HostCommandStub() { Commands = new HostCommands(this); } public event EventHandler PluginCalled; private void RaisePluginCalled(string message) { PluginCalled?.Invoke(this, new PluginCalledEventArgs(message)); } #region IVstHostCommandsStub Members public IVstPluginContext PluginContext { get; set; } public IVstHostCommands20 Commands { get; private set; } #endregion private class HostCommands : IVstHostCommands20 { private readonly HostCommandStub _cmdStub; public HostCommands(HostCommandStub cmdStub) { _cmdStub = cmdStub; } #region IVstHostCommands20 Members public bool BeginEdit(int index) { _cmdStub.RaisePluginCalled("BeginEdit(" + index + ")"); return false; } public bool EndEdit(int index) { _cmdStub.RaisePluginCalled("EndEdit(" + index + ")"); return false; } public VstCanDoResult CanDo(string cando) { Debug.WriteLine("cando queried: " + cando); _cmdStub.RaisePluginCalled("CanDo(" + cando + ")"); return VstCanDoResult.Unknown; } public VstAutomationStates GetAutomationState() { _cmdStub.RaisePluginCalled("GetAutomationState()"); return Jacobi.Vst.Core.VstAutomationStates.Off; } public int GetBlockSize() { Debug.WriteLine("got block size:" + projPlayer.blockSize); _cmdStub.RaisePluginCalled("GetBlockSize()"); return projPlayer.blockSize; } /// public string GetDirectory() { _cmdStub.RaisePluginCalled("GetDirectory()"); return null; } /// public int GetInputLatency() { _cmdStub.RaisePluginCalled("GetInputLatency()"); return 0; } /// public int GetOutputLatency() { _cmdStub.RaisePluginCalled("GetOutputLatency()"); return 0; } /// public Jacobi.Vst.Core.VstProcessLevels GetProcessLevel() { //Debug.WriteLine("got process level"); _cmdStub.RaisePluginCalled("GetProcessLevel()"); return Jacobi.Vst.Core.VstProcessLevels.Unknown; } public float GetSampleRate() { //Debug.WriteLine("got SAMPLE rate"); _cmdStub.RaisePluginCalled("GetSampleRate()"); //return 44.8f; return 44.1f; } public VstTimeInfo GetTimeInfo(VstTimeInfoFlags filterFlags) { _cmdStub.RaisePluginCalled("GetTimeInfo(" + filterFlags + ")"); return _cmdStub.myVstTimeInfo; } public VstHostLanguage GetLanguage() {_cmdStub.RaisePluginCalled("GetLanguage()"); return VstHostLanguage.NotSupported; } public string GetProductString() { _cmdStub.RaisePluginCalled("GetProductString()"); return "QuikDaw, a .NET mixing editor"; } public string GetVendorString() { _cmdStub.RaisePluginCalled("GetVendorString()"); return "QuikDaw Editor"; } public int GetVendorVersion() { _cmdStub.RaisePluginCalled("GetVendorVersion()"); return 1000; } public int GetVersion() { _cmdStub.RaisePluginCalled("GetVersion()"); return 1100; } public bool IoChanged() { _cmdStub.RaisePluginCalled("IoChanged()"); return false; } public bool OpenFileSelector(VstFileSelect fileSelect) { _cmdStub.RaisePluginCalled("OpenFileSelector(" + fileSelect.Command + ")"); return false; } public bool CloseFileSelector(VstFileSelect fileSelect) { _cmdStub.RaisePluginCalled("CloseFileSelector(" + fileSelect.Command + ")"); return false; } /// public bool ProcessEvents(VstEvent[] events) { _cmdStub.RaisePluginCalled("ProcessEvents(" + events.Length + ")"); return false; } public bool SizeWindow(int width, int height) { _cmdStub.RaisePluginCalled("SizeWindow(" + width + ", " + height + ")"); _cmdStub.WindowSizeChanged(width, height); return true; } /// public bool UpdateDisplay() { _cmdStub.RaisePluginCalled("UpdateDisplay()"); return false; } #endregion #region IVstHostCommands10 Members /// public int GetCurrentPluginID() { _cmdStub.RaisePluginCalled("GetCurrentPluginID()"); return _cmdStub.PluginContext.PluginInfo.PluginID; } /// public void ProcessIdle() { _cmdStub.RaisePluginCalled("ProcessIdle()"); } /// public void SetParameterAutomated(int index, float value) { _cmdStub.RaisePluginCalled("SetParameterAutomated(" + index + ", " + value + ")"); } #endregion } } public class PluginCalledEventArgs : EventArgs { /// /// Constructs a new instance with a . /// /// public PluginCalledEventArgs(string message) { Message = message; } public string Message { get; private set; } }