I am trying to create a theremin-like program, that plays continuous notes based on mouse cursor position. I am using Carl Franklin's MIDI Tools library to do this.
This is the code snippet I am using to play the notes.
byte pitch = 0;
while (exit == false)
{
byte newpitch = (byte)(32 + ((float)Cursor.Position.X / (float)SystemParameters.PrimaryScreenWidth) * 64);
if (newpitch != pitch)
{
instrument.StopNote(pitch,0);
instrument.PlayNote(newpitch, 53);
pitch = newpitch;
}
};
The problem is that the notes that are played out this way sound distinct; there is a clear transition from one note to another.
How do I play a continuous theremin like sound that shifts the pitch continuously?
This problem has little to do with MIDI, and more to do with the synthesizer generating the sound.
If you want to go from one note to the next smoothly with your current implementation, you need a synth patch that has lots of portamento. You may be able to get this to work on many patches by setting CC37 to 127 when you initialize.
Ideally, for complete smoothness, you need a synth patch that interprets the pitch bend for more than just up and down one step. Again, this has nothing to do with the values you send. Those will be 14-bit, no matter what. It is up to the synth to decide how far up/down those values go.
Depending on the synth, you can adjust its pitch bend range using the RPN for pitch bend sensitivity. You can read about it here: http://www.hoofjaw.com/forums/Topic946-32-1.aspx#bm1254
Or here: http://www.philrees.co.uk/nrpnq.htm