top of page
Search
Writer's pictureTim Cave

Making a VSTi Host - Part 5

At this point it's a good idea to take stock and sort the code out!


To do this I've used a handy C# Bass Vsti demo buried in the forum of the Un4Seen site. The project is called BassNetVSTiDemo is you would rather code in C#.


The basic functions I'm going to use are as follows:



void InitBASS();

void CreateVSTChannelStream();

void FreeVSTChannelStream();

void CleanupAndShutdown();

I've hard coded in the plugin as my final project is about playing the one plugin on my PC.

To do it properly you need to work with file dialogs.


Each function is as follows:




void InitBASS()
{
    // NOTE: Use BASS_STREAM_DECODE flag for ASIO "output" and change ASIOPROC
   
    // init BASS using the default windows output device (not ASIO device)
    if (BASS_Init(-1, 44100, 0, 0, NULL))
    {
      //  MessageBox::Show("BASS Init");
    }
    else
    {
        // error initializing device
        MessageBox::Show("Stream error: " + BASS_ErrorGetCode());
    }
}

void CreateVSTChannelStream()
{
    m_plugIn1DLLFilename = "C:\\Program Files (x86)\\Vstplugins\\Arcade.dll";
    
    // create a stream channel from a file
    vststream = BASS_VST_ChannelCreate(44100, 2, m_plugIn1DLLFilename, 0);
    if (vststream != 0)
    {
        // play the stream channel
       BASS_ChannelPlay(vststream, false);
    }
    else
    {
        // error creating the stream
        MessageBox::Show("Stream error: " + BASS_ErrorGetCode());
    }

}

void FreeVSTChannelStream()
{      
    // detatch the VST's embedded editor UI
    if (vststream != 0)
    {
        BASS_VST_EmbedEditor(vststream, NULL);
    }

    // stop stream channel for VST
    if (vststream > 0) BASS_ChannelStop(vststream);

    // free the stream
    if (vststream > 0) BASS_StreamFree(vststream);
}

void CleanupAndShutdown()
{
    // free BASS
    BASS_Free();
}
void pluginEditor() {

    ArcadePlayerFinal::MyForm1 form;
    if (BASS_VST_GetInfo(vststream, &vstInfo) && vstInfo.hasEditor)
    {
        //  form.Width = vstInfo.editorWidth / 1.75 + 40;
         // form.Height = vstInfo.editorHeight / 1.75 + 40;
          //test with  piano
        form.Width = vstInfo.editorWidth + 40;
        form.Height = vstInfo.editorHeight + 40;
        form.AutoScale;

        IntPtr iHwnd = form.Handle;
        HWND hwnd = (HWND)iHwnd.ToInt32();
        BASS_VST_EmbedEditor(vststream, hwnd);

        form.ShowDialog();
    }
    else {
        MessageBox::Show("No editor");
    }
    form.Close();   
}

With a button added to your main form you can then call the functions as so:



   InitBASS();
   FreeVSTChannelStream();
   CreateVSTChannelStream();
   pluginEditor();

If all goes well then you should be able to hear your plugin through your default speakers.







23 views0 comments

Recent Posts

See All

Comments


bottom of page