Making a virtual instrument

(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.