title: Play a continuous theremin-like sound on MIDI
body: <p>I am trying to create a <a href="https://en.wikipedia.org/wiki/Theremin" rel="nofollow noreferrer">theremin</a>-like program, that plays continuous notes based on mouse cursor position. I am using Carl Franklin's <a href="http://www.franklins.net/dotnet/CarlsMIDITools.zip" rel="nofollow noreferrer">MIDI Tools</a> library to do this.</p>
  
  <p>This is the code snippet I am using to play the notes.</p>
  
  <pre><code>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;
      }
  };
  </code></pre>
  
  <p>The problem is that the notes that are played out this way sound distinct; there is a clear transition from one note to another.</p>
  
  <p>How do I play a continuous theremin like sound that shifts the pitch continuously?</p>