This project has moved. For the latest updates, please go here.

PatchChange: change midi instrument.

Jul 14, 2008 at 12:34 PM
Edited Jul 14, 2008 at 12:40 PM
I want to be able to change the midi instrument. When I read an existing midi file I find the follow information:

AbsoluteTime: 0
Channel: 1
CommandCode: PatchChange
Patch: 26

To set this information to a new midi file, I added the following code:

myMidiEvents.AddEvent(new PatchChangeEvent((long)0, 2, 26), 1);

This doesn't seem to work, because when I read this new midi file, I find this information:

AbsoluteTime: 0
Channel: 2
CommandCode: PatchChange
Patch: 0


It looks like my command is being ignored. Can please someone provide me some information how to change the midi instrument to 26 Electric Guitar(jazz).

Thanks in advance.
Coordinator
Jul 14, 2008 at 4:06 PM
looks like you found a bug. I've checked in a fix. Sorry for the inconvenience
Mark
Jul 14, 2008 at 7:36 PM


markheath wrote:
looks like you found a bug. I've checked in a fix. Sorry for the inconvenience
Mark


Thanks for the fast reply. Where can I get the new version, when I visit releases, the latest version is from 24 june?
Coordinator
Jul 14, 2008 at 9:46 PM
just go to the Source Code tab and click download on the latest code revision. This will get you the NAudio source code. Then load the NAudio.sln into Visual Studio and build it.

Mark
Jul 15, 2008 at 1:51 PM
Edited Jul 15, 2008 at 1:52 PM


markheath wrote:
just go to the Source Code tab and click download on the latest code revision. This will get you the NAudio source code. Then load the NAudio.sln into Visual Studio and build it.

Mark


Thanks, it worked. This is a great tool you made, keep up the good work, the community will be gratefull. :-)
Aug 29, 2008 at 7:55 PM
Say, I'm having the same problem, and updating to the latest version didn't seem to help... I think I might be doing something wrong! Incidentally I also can't get the pitch bend to work properly - it always seems to bend the pitch the exact same amount (sounds like down 2 notes or so) no matter what I put in for the third parameter for the PitchWheelChangeEvent constructor...

This is what I'm doing as a test to try to play a chord and bend its pitch - it does play a chord, but with a piano, not the specified instrument, and it does bend the pitch, but always by the same amount no matter what value I put in for the pitch bend amount!

Thanks for any advice you may be able to offer! :)

            var inst = new PatchChangeEvent(0, 1, 26);
            var noteOn = new NoteOnEvent(0, 1, 64, 127, 1000);
            var noteOn2 = new NoteOnEvent(0, 1, 67, 127, 1000);
            var noteOn3 = new NoteOnEvent(0, 1, 71, 127, 1000);
            var pitchBend = new PitchWheelChangeEvent(0, 1, int.MaxValue);
            midiOut.Send(inst.GetAsShortMessage());
            midiOut.Send(noteOn.GetAsShortMessage());
            midiOut.Send(noteOn2.GetAsShortMessage());
            midiOut.Send(noteOn3.GetAsShortMessage());
            midiOut.Send(inst.GetAsShortMessage());
            Thread.Sleep(500);
            midiOut.Send(pitchBend.GetAsShortMessage());
Coordinator
Sep 3, 2008 at 11:18 PM
hi there ekolis,
what MIDI instrument are you sending these messages to?
Sep 3, 2008 at 11:22 PM
Edited Sep 3, 2008 at 11:25 PM
$0Which instrument? I don't have an external MIDI instrument hooked up (Vista doesn't seem to support the old serial MIDI, and I don't have a new USB MIDI cable!) - I was just trying to play stuff on my sound card, which is the only MIDI device I have available:$0$0if (midiOut == null) midiOut = new MidiOut(0);midiOut.Reset();$0$0is what I used to initialize midiOut before the code I posted previously.$0$0$0$0$0edit: sorry this looks so awful, I'm trying to use Google Chrome and the rich text editor is just not working!!!$0