static void StartVstHost(string pluginPath, string waveInputFilePath, string fxpFilePath, string waveOutputFilePath, bool doPlay) { VstHost host = VstHost.Instance; var hcs = new HostCommandStub(); host.OpenPlugin(pluginPath, hcs); host.InputWave = waveInputFilePath; // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. const int sampleRate = 44100; const int blockSize = 8192; const int channels = 2; host.Init(blockSize, sampleRate, channels); System.Diagnostics.Debug.WriteLine(host.getPluginInfo()); host.LoadFXP(fxpFilePath); if (doPlay) { var playback = new VstPlaybackNAudio(host); playback.Play(); Console.WriteLine("Started Audio Playback"); // make sure to play while the stream is playing if (playback.PlaybackDevice.PlaybackState == PlaybackState.Playing) { Thread.Sleep(5000); } Console.WriteLine("Ending Audio Playback"); playback.Stop(); Console.WriteLine("Stopped Audio Playback"); playback.Dispose(); } if (waveOutputFilePath != "") { var fileWriter = new VstFileWriter(host); fileWriter.CreateWaveFile(waveOutputFilePath); } }
void MidiNoteCheckboxCheckedChanged(object sender, EventArgs e) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; host.doPluginOpen(); // if first keypress setup audio if (playback == null) { // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; host.Init(blockSize, sampleRate, channels); playback = new VstPlaybackNAudio(host); playback.Play(); } CheckBox check = (CheckBox) sender; if(check.Checked) { host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity); } else { host.SendMidiNote(host.SendContinousMidiNote, 0); } }
void EditorFrameKeyDown(object sender, KeyEventArgs e) { if ((PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0) { return; } if (hasNoKeyDown) { try { byte midiVelocity = 100; byte midiNote = KeyEventArgToMidiNote(e); System.Diagnostics.Debug.WriteLine("Key Down Event Detected: {0}, {1}, {2}", e.KeyCode, midiNote, midiVelocity); // only bother with the keys that trigger midi notes if (midiNote != 0) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; // if first keypress setup audio if (playback == null) { // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; host.Init(blockSize, sampleRate, channels); playback = new VstPlaybackNAudio(host); playback.Play(); } host.SendMidiNote(midiNote, midiVelocity); hasNoKeyDown = false; // Set to False to disable keyboard Auto Repeat } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.StackTrace); MessageBox.Show(ex.Message); } } else { hasNoKeyDown = false; // Set to False to disable keyboard Auto Repeat } }
void AnalyseBtnClick(object sender, EventArgs e) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; host.doPluginOpen(); // if first keypress setup audio if (playback == null) { // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; host.Init(blockSize, sampleRate, channels); playback = new VstPlaybackNAudio(host); playback.Play(); } AnalyseForm dlg = new AnalyseForm(); dlg.PluginContext = this.PluginContext; dlg.Playback = playback; //dlg.ShowDialog(this); // modal dlg.Show(); // modeless }
void ProcessAudioBtnClick(object sender, EventArgs e) { // plugin does not support processing audio if ((PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0) { MessageBox.Show(this, "This plugin does not process any audio.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; if (waveInputFilePath != "") { host.InputWave = waveInputFilePath; // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; host.Init(blockSize, sampleRate, channels); if (playback == null) { playback = new VstPlaybackNAudio(host); playback.Play(); } else { // toogle start or stop if (playback.PlaybackDevice.PlaybackState == PlaybackState.Playing) { playback.Stop(); } else if (playback.PlaybackDevice.PlaybackState == PlaybackState.Stopped) { playback.Play(); } } } else { MessageBox.Show(this, "Please choose an audio file to process.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
void PlayMidiC5100msBtnClick(object sender, EventArgs e) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; host.doPluginOpen(); // if first keypress setup audio if (Playback == null) { // with iblock=1...Nblocks and blocksize = Fs * tblock. Fs = 44100 and // tblock = 0.15 makes blocksize = 6615. int sampleRate = 44100; int blockSize = (int) (sampleRate * 0.15f); //6615; int channels = 2; host.Init(blockSize, sampleRate, channels); Playback = new VstPlaybackNAudio(host); Playback.Play(); } // time how long this took Stopwatch stopwatch = Stopwatch.StartNew(); // end midi note on host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity); // wait 100 ms System.Threading.Thread.Sleep(100); // send midi note off host.SendMidiNote(host.SendContinousMidiNote, 0); stopwatch.Stop(); Console.WriteLine("Midi Note Sent. Time used {0} ms", stopwatch.ElapsedMilliseconds); }