MIDI-OX User Forum (http://www.midiox.com/cgi-bin/yabb/YaBB.pl)
MIDI-OX >> Scripting Questions >> How to set an instrument sound....
(Message started by: esopsis on Nov 25th, 2017, 4:14pm)

Title: How to set an instrument sound....
Post by esopsis on Nov 25th, 2017, 4:14pm
Yeah so I'm totally new to this MIDI stuff.  I am writing some code (which I'm not new to) and I somehow got things to work such that basically whenever I call OutputMidiMsg(-1, 144 58, 60) for example, it plays a note, which is nice, and then I can get it to stop playing by calling OutputMidiMsg(-1, 128, 58, 60), I think?  Which is great, although I'm not totally sure I get what those first two numbers do but whatever.  (The third and fourth are I believe the tone and how hard you hit the key so...)

Anyway, this is likely going to sound like a pretty dumb and basic question, but how do I choose what instrument to play?? When I do this it plays piano, but if I could just get it to play a different instrument, say, a trumpet, I would be set and that's all I would need to know how to do.  I've been looking all over but for some reason having trouble just figuring that out.  Basically got the first part to work just by using someone else's code which was how I found out about MIDI-OX the first place.  Thanks.


Title: Re: How to set an instrument sound....
Post by Breath on Nov 25th, 2017, 7:02pm
Hi
Some Midi basics... Midi has...
16 channels - in simple terms think players in a band. Well not really, better to think instruments eg trumpets, violins, piano where you can play more than one finger
Still not accurate as you can have zones on a keyboard with different instruments but playing on one channel.
So 16 channels, each having its own patch (preset)

Midi messages - I assume you can cope with hexadecimal as it makes Midi MUCH easier.
A byte in Hex (eg 9D) has two digits (9 and D in this case)

In Midi there are two type of bytes STATUS and DATA bytes.
Most common Midi messages consist of 3 bytes. eg 9A 64 7F.
Some have only 2 bytes like Patch Change eg CA 45

Byte 1 is the Status byte and uses the first nibble (byte - nibble, get it :) ) as the type of message and the second as the channel (0 to F or 0 to 15, but called 1 to 16 just to confuse)
9A = Note On channel 11
83 = Note Off  channel 4
etc
NOTE ALL STATUS BYTES are greater or equal to 80.
Bytes 2 and 3 are data bytes and are less than 80. You'll never see data bytes bigger than 7F (127).
Values bigger than 7F are only seen in the more complex System Exclusive Messages or by combining simple Midi messages - where  combinations of data bytes, all less than 7F, are used .

The Note On and Off messages have byte 2 = note number and byte 3 as the velocity or loudness.

NOTE that there is another way to turn off a note. Note On, but with velocity = 0
That is 93 64 00 = 83 64 xx where xx = any number below 7F
Roland tends to use Note Off and Yamaha uses Note On with 0 velocity

So if you computer or synth is setup with different instruments on different channels and your synth can play multi-timbrally then changing the channel of your note on and note of f messages will change the instrument.
OR you can send a patch change message to change the sound on the current channel and all future notes on that channel will play that new sound.

All the rest of the common Midi messages are straight forward.

http://www.somascape.org/midi/tech/spec.html
is a good reference for Midi messages

Welcome to the world of Midi .
Best of luck
Royce

Title: Re: How to set an instrument sound....
Post by esopsis on Nov 25th, 2017, 9:01pm
Ok yeah!  I think I can follow what's going on in that link you sent me!  I'll try it out later and see how it goes.  Thanks so much! I think maybe I will post back here when I get this music generating code working.



MIDI-OX User Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.