Making a virtual instrument

Hello

I have a few questions that might sound dumb but I searched forum a bit and and just got confused. I'm really new to C++ and Juce but I'm trying very hard to understand the fundamentals to achieve what I want.

I'd like to create a VST plug-in that is not an effect plug-in but an instrument plug-in (Image-Line puts that terminology, at any rate). In demo examples, they create either an *.exe app (great thing for stand-alone kind of instruments) or a *.dll app that can be used as an 'effect plug-in'. However I want to create a sampler with a keyboard and integrate my *.wav files to each notes and get them played on mousedown. In 'JuceDemo' at Synthesisers, MIDI i/o section, I see you already provided a keyboard playing samples but it only deals with one *.wav file (cello) and adjusts the pitch accordingly for the rest of the keys. So my questions are:

-how I can integrate my pre-recorded wav samples to each keys, e.g: if C1 clicked, play C1.wav, if C#1 clicked play C#1.wav and so on (a few lines code-example would be great :)

-on Visual Studio C++ how I set it for it to debug the output file as a *.dll that is not an effect plug-in but is a VST instrument

 

Any help would be much appreciated. 

(disclaimer: my english is far from perfect, sorry for that!)

- Regarding the first question:  look at the way the method setUsingSampledSound is implemented in the demo. In short, you create SynthesiserSound and more specifically in this case SamplerSound which is a subclass of it.

Have a look at the documentation: when creating these you specify the source you will be using (in this case an object handling your file). Then you specify the range of MIDI notes this sound will be used for  - in your case only one MIDI note for each one instead of the big "allNotes" aggregate in the demo.

I advise you to test it by adding one SamplerSound for one specific note (C1 for instance) using another sound file, and building it up from this.

 

Code example, nasty modification of the demo:

- I create a new reader for a sample file I have.

- I change the "allNotes" variable so it is no longer holding the value for 64.

- I create a new BigInteger variable with only 64 set.

- I add a sound to the synth which associates my sample with the previous variable for 64.

A a result, I can hear my own file when I send the MIDI note 64.

Note that this code change is really crude, this is only an example...


        ScopedPointer<AudioFormatReader> audioReader_file(wavFormat.createReaderFor(new FileInputStream(juce::File("c:/C5_flute.wav")),
                                                                                    true));

        BigInteger allNotes_except_64;
        allNotes_except_64.setRange (0, 128, true);
        allNotes_except_64.clearBit(64);

        synth.clearSounds();
        synth.addSound (new SamplerSound ("demo sound",
                                          *audioReader,
                                          allNotes_except_64,
                                          74,   // root midi note
                                          0.1,  // attack time
                                          0.1,  // release time
                                          10.0  // maximum sample length
                                          ));

        BigInteger note_64;
        note_64.setBit(64);
        synth.addSound (new SamplerSound ("demo sound 64",
                                          *audioReader_file,
                                          note_64,
                                          74,   // root midi note
                                          0.1,  // attack time
                                          0.1,  // release time
                                          10.0  // maximum sample length
                                          ));

- For the second part, the Introjucer takes care of all this - you only have to specify that your plugin is an instrument, the number of audio inputs (probably 0) and outputs, and that's it. It will also create the Visual studio files you need, e.g. .vcproj and .sln.

Awww that's confusing >.<

But that means there are lots of interesting stuff to learn!

I got very little of what you said but I won't give up, I think I need more training on C++ and then should buy a Getting Started with Juce copy, cause right now I feel lost in codes.

I will also be posting my questions here during the training. I know I sound stupid asking very basic questions but that's how I learn things. I hope you could tolerate them. ^^

Indeed if this was too complicated you may want to check this excellent (although old school looking) tutorial.

It covers all the basis for building a simple VST plugin. This is an effect plugin but I think it will be easier to grasp as a beginner.