void PlayMidiC5100msBtnClick(object sender, EventArgs e) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; host.doPluginOpen(); InitPlayback(); 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); }
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 EditorFrameKeyUp(object sender, KeyEventArgs e) { if ((PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0) { return; } hasNoKeyDown = true; // Set to True to enable next KeyDown event try { byte midiVelocity = 0; byte midiNote = KeyEventArgToMidiNote(e); System.Diagnostics.Debug.WriteLine("Key Up 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; host.SendMidiNote(midiNote, midiVelocity); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void MidiNoteCheckboxCheckedChanged(object sender, EventArgs e) { VstHost host = VstHost.Instance; host.PluginContext = this.PluginContext; host.doPluginOpen(); InitPlayback(); Playback.Play(); var 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 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); }
void SylenthAutoMeasureFilters() { VstHost host = VstHost.Instance; MeasureFrequencyInit(); // time how long this takes Stopwatch stopwatch = Stopwatch.StartNew(); // wait until the plugin has started playing some noise while (!host.LastProcessedBufferLeftPlaying) { // start playing audio Playback.Play(); // play midi host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity); if (stopwatch.ElapsedMilliseconds > 5000) { stopwatch.Stop(); Console.Out.WriteLine("AutoMeasureFreq: Playing Midi Failed!"); return; } System.Threading.Thread.Sleep(100); } // step through the filter steps for (float paramFilterAValue = 1.0f; paramFilterAValue >= 0.0f; paramFilterAValue -= 0.020f) { for (float paramFilterCtlValue = 1.0f; paramFilterCtlValue >= 0.0f; paramFilterCtlValue -= 0.020f) { stopwatch.Stop(); stopwatch.Start(); Console.Out.WriteLine("AutoMeasureFreq: Measuring {0} at value {1:0.00} and {2} at value {3:0.00} ...", "filterACutoff", paramFilterAValue, "filterCtlCutoff", paramFilterCtlValue); // set the parameters PluginContext.PluginCommandStub.SetParameter(WaveDisplayForm.SYLENTH_PARAM_FILTERA_CUTOFF, paramFilterAValue); ((HostCommandStub)PluginContext.HostCommandStub).SetParameterAutomated(WaveDisplayForm.SYLENTH_PARAM_FILTERA_CUTOFF, paramFilterAValue); PluginContext.PluginCommandStub.SetParameter(WaveDisplayForm.SYLENTH_PARAM_FILTERCTL_CUTOFF, paramFilterCtlValue); ((HostCommandStub)PluginContext.HostCommandStub).SetParameterAutomated(WaveDisplayForm.SYLENTH_PARAM_FILTERCTL_CUTOFF, paramFilterCtlValue); // wait System.Threading.Thread.Sleep(200); this.frequencyAnalyserUserControl1.SetAudioData(host.LastProcessedBufferLeft); // wait System.Threading.Thread.Sleep(200); // create a snapshot of the current freqency RetrieveFilterInfo(); stopwatch.Stop(); Console.Out.WriteLine("AutoMeasureFreq: Used {0} ms. Found max frequency {1:00.00} at {2:00.00} dB.", stopwatch.ElapsedMilliseconds, this.foundMaxFreq, this.foundMaxDB); // store as a png //string fileName = String.Format("frequency-measurement-{0}-{1}.png", StringUtils.MakeValidFileName(String.Format("{0:00.00} {1:00.00} {2:00.00}", this.foundMaxFreq, paramFilterAValue, paramFilterCtlValue)), StringUtils.GetCurrentTimestamp()); //this.frequencyAnalyserUserControl1.Bitmap.Save(fileName); // store in xml file float maxFreq = 0.0f; float.TryParse(this.foundMaxFreq, out maxFreq); if (maxFreq > 0) { FrequencySave(); } } } // stop midi host.SendMidiNote(host.SendContinousMidiNote, 0); // stop playing audio Playback.Stop(); }
void MeasureLFOBtnClick(object sender, EventArgs e) { MeasureLFOInit(); VstHost host = VstHost.Instance; List <string> lfoAlreadyProcessed = new List <string>(); // step through the LFO steps int count = 0; for (float paramValue = 1.0f; paramValue >= 0.0f; paramValue -= 0.020f) { // time how long this takes Stopwatch stopwatch = Stopwatch.StartNew(); // init the buffers host.ClearRecording(); host.ClearLastProcessedBuffers(); // start record host.Record = true; // set the parameter PluginContext.PluginCommandStub.SetParameter(SYLENTH_PARAM_LFO1_RATE, paramValue); // get param display value string paramDisplay = PluginContext.PluginCommandStub.GetParameterDisplay(SYLENTH_PARAM_LFO1_RATE); // check if already processed if (lfoAlreadyProcessed.Contains(paramDisplay)) { continue; } else { lfoAlreadyProcessed.Add(paramDisplay); } // wait until it has started playing while (!host.LastProcessedBufferLeftPlaying) { // start playing audio Playback.Play(); // play midi host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity); if (stopwatch.ElapsedMilliseconds > 5000) { stopwatch.Stop(); System.Console.Out.WriteLine("MeasureLFOBtnClick: Playing Midi Failed!"); return; } System.Threading.Thread.Sleep(100); } // play for approx 1000 ms // paramValue: 1 = 1/256 Triple (count = 0) // paramValue: 0 = 8/1 D (count = 10) System.Threading.Thread.Sleep((int)(20 * Math.Pow(count, 2))); // stop midi host.SendMidiNote(host.SendContinousMidiNote, 0); // wait until it has stopped playing while (host.LastProcessedBufferLeftPlaying) { if (stopwatch.ElapsedMilliseconds > 40000) { System.Console.Out.WriteLine("MeasureLFOBtnClick: Playing never stopped?!"); break; } } // stop playing audio Playback.Stop(); stopwatch.Stop(); System.Console.Out.WriteLine("MeasureLFOBtnClick: Playing stopped: {0} ms. {1}", stopwatch.ElapsedMilliseconds, paramDisplay); // stop recording host.Record = false; // crop CropAudio(); // store this in a wav ouput file. string wavFilePath = String.Format("audio-LFO-{0}-{1}.wav", StringUtils.MakeValidFileName(paramDisplay), StringUtils.GetCurrentTimestamp()); AudioUtilsNAudio.CreateWaveFile(host.RecordedLeft.ToArray(), wavFilePath, new WaveFormat(host.SampleRate, 1)); // store as a png System.Drawing.Bitmap png = CommonUtils.FFT.AudioAnalyzer.DrawWaveform(host.RecordedLeft.ToArray(), new System.Drawing.Size(1000, 600), 10000, 1, 0, host.SampleRate); string fileName = String.Format("audio-LFO-{0}-{1}.png", StringUtils.MakeValidFileName(paramDisplay), StringUtils.GetCurrentTimestamp()); png.Save(fileName); // clear ClearAudio(); // wait a specfied time System.Threading.Thread.Sleep(100); stopwatch.Stop(); count++; } }
void MeasureADSRParameter(int paramName, float paramValue, string envName, bool measureRelease = false) { System.Console.Out.WriteLine("MeasureADSREntry: Measuring {0} at value {1:0.00}...", envName, paramValue); VstHost host = VstHost.Instance; // time how long this takes Stopwatch stopwatch = Stopwatch.StartNew(); // init the buffers host.ClearRecording(); host.ClearLastProcessedBuffers(); // start record host.Record = true; // set the parameter PluginContext.PluginCommandStub.SetParameter(paramName, paramValue); ((HostCommandStub)PluginContext.HostCommandStub).SetParameterAutomated(paramName, paramValue); // wait until it has started playing while (!host.LastProcessedBufferLeftPlaying) { // start playing audio Playback.Play(); // play midi host.SendMidiNote(host.SendContinousMidiNote, host.SendContinousMidiNoteVelocity); if (stopwatch.ElapsedMilliseconds > 5000) { stopwatch.Stop(); System.Console.Out.WriteLine("MeasureADSREntry: Playing Midi Failed!"); return; } System.Threading.Thread.Sleep(100); } if (measureRelease) { // release is a special case where you only measure the tail after // a short midi signal // therefore we need to stop the midi message here host.SendMidiNote(host.SendContinousMidiNote, 0); } // wait until it has stopped playing stopwatch.Restart(); while (host.LastProcessedBufferLeftPlaying) { if (stopwatch.ElapsedMilliseconds > 40000) { stopwatch.Stop(); System.Console.Out.WriteLine("MeasureADSREntry: Playing never stopped?!"); break; } } // stop playing audio Playback.Stop(); stopwatch.Stop(); System.Console.Out.WriteLine("MeasureADSREntry: Playing stopped: {0} ms.", stopwatch.ElapsedMilliseconds); // stop recording host.Record = false; // wait a specfied time System.Threading.Thread.Sleep(100); // crop CropAudio(); // store the duration RetrieveDuration(); // store this in a wav ouput file. float param = PluginContext.PluginCommandStub.GetParameter(paramName); string wavFilePath = String.Format("{0}{1:0.00}s-{2}.wav", envName, param, StringUtils.GetCurrentTimestamp()); AudioUtilsNAudio.CreateWaveFile(host.RecordedLeft.ToArray(), wavFilePath, new WaveFormat(host.SampleRate, 1)); // store as a png System.Drawing.Bitmap png = CommonUtils.FFT.AudioAnalyzer.DrawWaveform(host.RecordedLeft.ToArray(), new System.Drawing.Size(1000, 600), 10000, 1, 0, host.SampleRate); string fileName = String.Format("{0}{1:0.00}s-{2}.png", envName, param, StringUtils.GetCurrentTimestamp()); png.Save(fileName); if (!measureRelease) { // turn of midi unless we are measuring a release envelope // then it should have been turned of immideately after a small signal is generated host.SendMidiNote(host.SendContinousMidiNote, 0); } // clear ClearAudio(); // wait a specfied time System.Threading.Thread.Sleep(100); stopwatch.Stop(); }