示例#1
0
 public void Dispose()
 {
     if (UtilityAudio.PlaybackDevice != null)
     {
         UtilityAudio.Dispose();
     }
 }
示例#2
0
        public new void Dispose()
        {
            UtilityAudio.DisposeVst();
            vst = null;
            base.Dispose();

            vstFormSingleton = null;
        }
示例#3
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            var saveFile = new SaveFileDialog();

            saveFile.Title  = "Select output file:";
            saveFile.Filter = "WAV Files (*.wav)|*.wav";
            saveFile.ShowDialog();

            UtilityAudio.SaveStream(saveFile.FileName);
        }
示例#4
0
 private void vst_PlayingStarted(object sender, EventArgs e)
 {
     if (UtilityAudio.PlaybackDevice != null)
     {
         UtilityAudio.StartStreamingToDisk();
         Console.Out.WriteLine("Started streaming to disk ...");
     }
     Console.Out.WriteLine("Vst Plugin Started playing ...");
     stoppedPlaying = false;
 }
示例#5
0
        void LoadToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (vstForm != null)
            {
                vstForm.Dispose();
                vstForm = null;

                showToolStripMenuItem.Enabled           = false;
                editParametersToolStripMenuItem.Enabled = false;
                loadToolStripMenuItem.Text = "Load...";
            }
            else
            {
                var ofd = new OpenFileDialog();
                ofd.Title  = "Select VST:";
                ofd.Filter = "VST Files (*.dll)|*.dll";
                if (LastDirectoryUsed.ContainsKey("VSTDir"))
                {
                    ofd.InitialDirectory = LastDirectoryUsed["VSTDir"];
                }
                else
                {
                    ofd.InitialDirectory = UtilityAudio.GetVstDirectory();
                }
                DialogResult res = ofd.ShowDialog();

                if (res != DialogResult.OK || !File.Exists(ofd.FileName))
                {
                    return;
                }

                try
                {
                    if (LastDirectoryUsed.ContainsKey("VSTDir"))
                    {
                        LastDirectoryUsed["VSTDir"] = Directory.GetParent(ofd.FileName).FullName;
                    }
                    else
                    {
                        LastDirectoryUsed.Add("VSTDir", Directory.GetParent(ofd.FileName).FullName);
                    }
                    vstForm = new VSTForm(ofd.FileName, "nix");
                    vstForm.Show();

                    showToolStripMenuItem.Enabled           = true;
                    editParametersToolStripMenuItem.Enabled = true;

                    loadToolStripMenuItem.Text = "Unload...";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#6
0
        public VstViewer(string VSTPath)
        {
            vstFormSingleton = this;
            UtilityAudio.OpenAudio(AudioLibrary.NAudio, RMVN_Studio.Properties.Settings.Default.ASIODriverName);
            InitializeComponent();
            vst       = UtilityAudio.LoadVST(VSTPath, this.Handle);
            this.Text = vst.PluginContext.PluginCommandStub.GetEffectName();
            var rect = new Rectangle();

            vst.PluginContext.PluginCommandStub.EditorGetRect(out rect);
            this.SetClientSizeCore(rect.Width, rect.Height);
            UtilityAudio.StartAudio();
        }
示例#7
0
 private void tsbRec_CheckedChanged(object sender, EventArgs e)
 {
     if (tsbRec.Checked)
     {
         tsbRec.BackColor = Color.Red;
         UtilityAudio.StartStreamingToDisk();
     }
     else
     {
         tsbRec.BackColor = Color.Transparent;
         UtilityAudio.StopStreamingToDisk();
     }
 }
示例#8
0
        void Timer1Tick(object sender, EventArgs e)
        {
            // Call these three functions 'getEditorSize', 'processIdle' and 'processReplacing' continually while the GUI is open.
            // If size don't change and you don't need to process audio call the functions anyway because plugins can rely on them being called frequently for their redrawing.
            // http://vstnet.codeplex.com/discussions/281497

            // In fact all I had to call was  Jacobi.Vst.Core.Host.IVstPluginCommandStub.EditorIdle()
            // which I do every 100 ms.  This works great ;)
            if (vst != null && doGUIRefresh && Visible)
            {
                vst.pluginContext.PluginCommandStub.EditorIdle();
            }

            // update play time
            tslNowTime.Text = UtilityAudio.GetMp3CurrentTime().ToString();
        }
示例#9
0
        private void tsbLoad_Click(object sender, EventArgs e)
        {
            var fileDialog = new OpenFileDialog();

            fileDialog.Title  = "Select MP3 file:";
            fileDialog.Filter = "MP3 Files (*.mp3)|*.mp3";
            fileDialog.ShowDialog();

            if (String.IsNullOrEmpty(fileDialog.FileName))
            {
                return;
            }

            UtilityAudio.LoadMp3(fileDialog.FileName);

            tslTotalTime.Text = " / " + UtilityAudio.GetMp3TotalTime().ToString();
        }
示例#10
0
        public VSTForm(string VSTPath, string asioDevice)
        {
            vstFormSingleton = this;
            UtilityAudio.OpenAudio(AudioLibrary.NAudio, asioDevice);

            InitializeComponent();

            vst       = UtilityAudio.LoadVst(VSTPath, this.Handle);
            this.Text = vst.pluginContext.PluginCommandStub.GetProgramName();
            var rect = new Rectangle();

            vst.pluginContext.PluginCommandStub.EditorGetRect(out rect);
            this.SetClientSizeCore(rect.Width, rect.Height + 125);
            vst.StreamCall += vst_StreamCall;


            UtilityAudio.StartAudio();
        }
示例#11
0
 void MainFormFormClosing(object sender, FormClosingEventArgs e)
 {
     if (midiIn != null)
     {
         midiIn.Dispose();
         midiIn = null;
     }
     if (midiOut != null)
     {
         midiOut.Dispose();
         midiOut = null;
     }
     if (vstForm != null)
     {
         vstForm.Dispose();
         vstForm = null;
     }
     UtilityAudio.Dispose();
 }
示例#12
0
 private void tsbStop_Click(object sender, EventArgs e)
 {
     try
     {
         if (UtilityAudio.IsMp3Played())
         {
             UtilityAudio.PauseMp3();
             tsbStop.Image = (System.Drawing.Image) new System.ComponentModel.ComponentResourceManager(typeof(VSTForm)).GetObject("tsbStop.Image");
         }
         else
         {
             UtilityAudio.StopMp3();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#13
0
 private void tsbMixer_Click(object sender, EventArgs e)
 {
     UtilityAudio.ShowMixer();
 }
示例#14
0
        void PresetRecording()
        {
            int programNumber           = 0;
            int testDataCount           = 0;
            List <Synth1Preset> presets =
                Synth1PresetHandler.GetPresetsFromFolderAndSubfolders(@"C:\Users\patri_000\Desktop\Synth1Presets");

            // Synth1 can max save 12800 programs
            while (programNumber < presets.Count)
            {
                if (!UtilityAudio.IsStreamingToDisk())
                {
                    VSTForm.vst.pluginContext.PluginCommandStub.SetProgram(0);
                    var programmName = presets[programNumber].Name;

                    // step over empty programs
                    if (programmName != "initial sound")
                    {
                        setSynthPreset(presets[programNumber]);
                        UtilityAudio.SaveStream(Path.Combine(recordDestinationPath, "Test" + testDataCount + ".wav"));

                        // start audio recording
                        UtilityAudio.StartStreamingToDisk();

                        const byte midiNote     = 60; // C4
                        byte       midiVelocity = 100;

                        progressLog1.LogMessage(Color.Blue, "TestSample No. " + testDataCount + " recording from presets started...");

                        UtilityAudio.StartReadNonRealtime();

                        // only bother with the keys that trigger midi notes
                        if (VSTForm.vst != null && midiNote != 0)
                        {
                            // start synth processing
                            VSTForm.vst.MIDI_NoteOn(midiNote, midiVelocity);
                        }

                        // sleep for duration how long the note is hold
                        Thread.Sleep(7);

                        midiVelocity = 0;

                        if (VSTForm.vst != null && midiNote != 0)
                        {
                            // stop synth processing
                            VSTForm.vst.MIDI_NoteOn(midiNote, midiVelocity);
                        }

                        var testDataXml =
                            new XDocument(
                                new XElement("Synth1Testdata",
                                             new XElement("TestdataCount", testDataCount),
                                             new XElement("PresetName", programmName)
                                             )
                                );

                        for (int i = 0; i < 99; i++)
                        {
                            var parameter = new XElement("Parameter",
                                                         new XAttribute("index", i), new XAttribute("vstValue", VSTForm.vst.pluginContext.PluginCommandStub.GetParameter(i)), new XAttribute("presetValue", Synth1PresetHandler.ConvertVstParaToParaV113(i, VSTForm.vst.pluginContext.PluginCommandStub.GetParameter(i))));

                            testDataXml.Element("Synth1Testdata")?.Add(parameter);
                        }

                        testDataXml.Save(Path.Combine(recordDestinationPath, "Test" + testDataCount + ".xml"));

                        testDataCount++;
                    }

                    programNumber++;
                }

                Thread.Sleep(5);
            }
        }
示例#15
0
 private void tsbPlay_Click(object sender, EventArgs e)
 {
     UtilityAudio.PlayMp3();
     tsbStop.Image = (System.Drawing.Image) new System.ComponentModel.ComponentResourceManager(typeof(VSTForm)).GetObject("tsbPause.Image");
 }
示例#16
0
        /// <summary>
        /// Reads bytes from this wave stream
        /// </summary>
        /// <param name="buffer">buffer to read into</param>
        /// <param name="offset">offset into buffer</param>
        /// <param name="count">number of bytes required</param>
        /// <returns>Number of bytes read.</returns>
        /// <exception cref="ArgumentException">Thrown if an invalid number of bytes requested</exception>
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (autoStop)
            {
                if (position + count > length)
                {
                    count = (int)(length - position);
                }

                // was a bug here, should be fixed now
                System.Diagnostics.Debug.Assert(count >= 0, "length and position mismatch");
            }


            if (count % bytesPerSample != 0)
            {
                throw new ArgumentException("Must read an whole number of samples", "count");
            }

            // blank the buffer
            Array.Clear(buffer, offset, count);
            int bytesRead = 0;

            // sum the channels in
            byte[] readBuffer = new byte[count];
            foreach (WaveStream inputStream in inputStreams)
            {
                if (inputStream.HasData(count))
                {
                    int readFromThisStream = inputStream.Read(readBuffer, 0, count);
                    //System.Diagnostics.Debug.Assert(readFromThisStream == count, "A mixer input stream did not provide the requested amount of data");
                    //OWN
                    //TODO: better check for empty wave
                    if (UtilityAudio.IsStreamingToDisk())
                    {
                        _recordLengthCounter++;
                        if (_recordLengthCounter > RecordLength)
                        {
                            UtilityAudio.StopStreamingToDisk();
                        }
                    }

                    bytesRead = Math.Max(bytesRead, readFromThisStream);
                    if (readFromThisStream > 0)
                    {
                        Sum32BitAudio(buffer, offset, readBuffer, readFromThisStream);
                    }
                }
                else
                {
                    bytesRead             = Math.Max(bytesRead, count);
                    inputStream.Position += count;
                }
            }
            position += count;
            // If streamToDisk has been enabled the mixed audio will be streamed directly to a wave file, so we need to send the data to the wave file writer
            if (streamToDisk)
            {
                WriteMixStreamOut(buffer, offset, count);
            }
            return(count);
        }
示例#17
0
        public bool ProcessRealTime(String waveInputFilePath, String waveOutputFilePath, String pluginPath, String fxpFilePath = null, float volume = 1.0f)
        {
            var wavFileReader = new WaveFileReader(waveInputFilePath);

            // reuse if batch processing
            bool doUpdateVstPlugin  = false;
            bool doUpdateSampleRate = false;
            bool doUpdateNoChannels = false;

            if (_pluginPath != null)
            {
                if (_pluginPath.Equals(pluginPath))
                {
                    // plugin has not changed
                }
                else
                {
                    // plugin has changed!
                    doUpdateVstPlugin = true;
                }
            }
            else
            {
                _pluginPath       = pluginPath;
                doUpdateVstPlugin = true;
            }

            if (_sampleRate != 0)
            {
                if (_sampleRate == wavFileReader.WaveFormat.SampleRate)
                {
                    // same sample rate
                }
                else
                {
                    // sample rate has changed!
                    doUpdateSampleRate = true;
                }
            }
            else
            {
                _sampleRate        = wavFileReader.WaveFormat.SampleRate;
                doUpdateSampleRate = true;
            }

            if (_channels != 0)
            {
                if (_channels == wavFileReader.WaveFormat.Channels)
                {
                    // same number of channels
                }
                else
                {
                    // number of channels has changed!
                    doUpdateNoChannels = true;
                }
            }
            else
            {
                _channels          = wavFileReader.WaveFormat.Channels;
                doUpdateNoChannels = true;
            }

            if (doUpdateNoChannels || doUpdateSampleRate)
            {
                Console.Out.WriteLine("Opening Audio driver using samplerate {0} and {1} channels.", _sampleRate, _channels);
                UtilityAudio.OpenAudio(AudioLibrary.NAudio, _sampleRate, _channels);
            }

            if (doUpdateVstPlugin || doUpdateNoChannels || doUpdateSampleRate)
            {
                Console.Out.WriteLine("Loading Vstplugin using samplerate {0} and {1} channels.", _sampleRate, _channels);
                vst = UtilityAudio.LoadVST(_pluginPath, _sampleRate, _channels);
                UtilityAudio.VstStream.ProcessCalled  += vst_ProcessCalled;
                UtilityAudio.VstStream.PlayingStarted += vst_PlayingStarted;
                UtilityAudio.VstStream.PlayingStopped += vst_PlayingStopped;

                // plugin does not support processing audio
                if ((vst.PluginContext.PluginInfo.Flags & VstPluginFlags.CanReplacing) == 0)
                {
                    Console.Out.WriteLine("This plugin does not process any audio.");
                    return(false);
                }

                // check if the plugin supports real time proccesing
                if (vst.PluginContext.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)) == VstCanDoResult.Yes)
                {
                    Console.Out.WriteLine("This plugin does not support realtime processing.");
                    return(false);
                }
            }

            if (File.Exists(fxpFilePath))
            {
                Console.Out.WriteLine("Loading preset file {0}.", fxpFilePath);
                vst.LoadFXP(fxpFilePath);
            }
            else
            {
                Console.Out.WriteLine("Could not find preset file (fxp|fxb) ({0})", fxpFilePath);
            }

            if (UtilityAudio.PlaybackDevice.PlaybackState != PlaybackState.Playing)
            {
                Console.Out.WriteLine("Starting audio playback engine.");
                UtilityAudio.StartAudio();
            }

            Console.Out.WriteLine("Setting input wave {0}.", waveInputFilePath);
            UtilityAudio.VstStream.SetInputWave(waveInputFilePath, volume);

            Console.Out.WriteLine("Setting output wave {0}.", waveOutputFilePath);
            UtilityAudio.SaveStream(waveOutputFilePath);

            UtilityAudio.VstStream.DoProcess = true;

            // just wait while the stream is playing
            // the events will trigger and set the stoppedPlaying flag
            while (!stoppedPlaying)
            {
                Thread.Sleep(50);
            }

            // reset if calling this method multiple times
            stoppedPlaying = false;
            return(true);
        }