Forums > MaxMSP

Encode text to SYSEX to send over midi

February 25, 2006 | 9:05 pm

I want to create a sysex message from a Name to send over midi to an external receiver.

e.g.
MAX/MASP
myname –> midiChannel -> midiOut

JAVA application
–> midiIn –> display:"myname"

any ideas?

thank you

Markus


February 27, 2006 | 11:15 pm

You might want to work on the text formatting, but this solves the midi and sysex issue.

mzed

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 348 152 63 196617 dump , clear;
#P newex 362 118 65 196617 sel 240 247;
#P user textedit 416 205 516 255 32768 3 9 d o g s a n d c a t s;
#P newex 416 151 27 196617 itoa;
#P comment 135 119 128 196617 < -- type your text in here;
#P newex 32 189 27 196617 atoi;
#P newex 416 180 40 196617 text;
#P newex 362 90 154 196617 sysexin "IAC Driver IAC Bus 1";
#P button 32 73 15 0;
#P newex 32 163 56 196617 route text;
#P user textedit 32 101 132 151 32768 3 9 dogs and cats;
#P newex 32 243 61 196617 append 247;
#P newex 32 217 66 196617 prepend 240;
#P newex 32 269 152 196617 midiout "IAC Driver IAC Bus 1";
#P comment 60 72 100 196617 < -- bang to send;
#P connect 7 0 13 0;
#P connect 3 0 1 0;
#P connect 8 0 12 0;
#P connect 14 0 8 0;
#P connect 13 1 14 0;
#P connect 11 0 8 0;
#P connect 13 2 11 0;
#P connect 9 0 2 0;
#P connect 6 0 4 0;
#P connect 5 0 9 0;
#P connect 4 0 5 0;
#P connect 2 0 3 0;
#P window clipboard copycount 15;


February 28, 2006 | 12:11 am

thanks


February 28, 2006 | 7:29 am


February 28, 2006 | 2:25 pm

"Normally, midi transmits 7bits data. Although your technique works thru
an IAC bus, I’m not sure it will work with 8bits char with hardware
MIDI device (I cannot test myself now!). So the integer should be split
into 2 7 bits words (or whatever other technique).
"

Not sure that’s true. The sysex header byte is 0xf0 (240 decimal), note on is 0×80, etc.. last time I checked, that’s 8 full bits. Now, the data might be encoded as 7 bits, but for sysex, 8 bit data is OK.


February 28, 2006 | 2:54 pm

> "Normally, midi transmits 7bits data. Although your technique works thru
> an IAC bus, I’m not sure it will work with 8bits char with hardware
> MIDI device (I cannot test myself now!). So the integer should be split
> into 2 7 bits words (or whatever other technique)."
>
> Not sure that’s true. The sysex header byte is 0xf0 (240 decimal), note on
> is 0×80, etc..
> last time I checked, that’s 8 full bits. Now, the data might be encoded as
> 7 bits, but for
> sysex, 8 bit data is OK.

You’re forgetting that the MSB in each MIDI byte is reserved for designating
whether it’s a status or data byte.

Cheers.

*V*I*R*G*O*


February 28, 2006 | 3:23 pm


February 28, 2006 | 3:35 pm

On around Feb 28, 2006, at 15:25, Mark Hill said something like:
> Not sure that’s true. The sysex header byte is 0xf0 (240 decimal),
> note on is 0×80, etc.. last time I checked, that’s 8 full bits. Now,
> the data might be encoded as 7 bits, but for sysex, 8 bit data is OK.

MIDI Status bytes have the MSB set
MIDI Data bytes have the MSB clear

Either way, the actual *content* of a MIDI byte is encoded in bits 0-6.
Bit 7 (MSB) is the status bit. MIDI **data** are restricted to 7 bits
per byte.

That is the MIDI standard the way it’s been forever.

If you want to send arbitrary streams of serial 8-bit bytes, you can
do, but it ain’t MIDI. If IAC let’s you do this… you’re maybe in
luck, but it’s breaking the MIDI spec.

>
————– http://www.bek.no/~pcastine/Litter/ ————–
Peter Castine | ^
| Litter Power & Litter Bundle for Jitter
pcastine@gmx.net |
pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
4-15@kagi.com | for Max/MSP
| Extremely cool
| http://www.dspaudio.com
| http://www.dspaudio.com/software/software.html


February 28, 2006 | 3:41 pm

MIDI always transmit 8 bits bytes. The first bit indicates if this is
a status byte (1) or a data byte (0). Status bytes indicate the start
of a new midi message, or in the case of a SYSEX it could also
indicate the end of a sysex message (0xFF or 247). If you send sysex
messages where the data bytes between the first and last bytes are in
the range 128-255 you might risk them being misinterpreted at the
receiving for being something else, e.g. the start of a note-on
message (144-159) or a pitch-bend message (224-239).

For this reason you should reformat your character values so that one
char is sent as two bytes, to make sure that the first bit of each of
the bytes is 0. Peter Elsea provides externals for dealing with
"nibbles" as part of Lobjects.

http://en.wikipedia.org/wiki/Nibble

You can do with standard Max obejcts as well. The patch below
provides abstractions for converting ascii to and from nibble as well
as messages to and from sysex. I did not bother to add Checksum at
the end of the sysex messages, or an manufactorer ID to the sysex
that could have been used to tell it apart from sysex messages meant
for other gear.

Best,
Trond

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 376 67 40 196617 orange;
#P message 334 67 40 196617 banana;
#P message 299 67 33 196617 apple;
#N vpatcher 44 74 344 489;
#P window setfont "Sans Serif" 9.;
#P newex 62 297 64 196617 fromsymbol;
#P outlet 62 334 15 0;
#P newex 62 269 27 196617 itoa;
#P newex 62 238 46 196617 zl group;
#P newex 62 61 67 196617 t b l;
#P newex 119 204 58 196617 +;
#P newex 119 171 29 196617 < < 4;
#P newex 119 140 58 196617 unpack 0 0;
#P newex 119 102 55 196617 zl group 2;
#P inlet 62 35 15 0;
#P connect 0 0 5 0;
#P connect 4 0 6 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 9 0;
#P connect 9 0 8 0;
#P connect 5 1 1 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 2 1 4 1;
#P pop;
#P newobj 94 284 72 196617 p sysex2ascii;
#N vpatcher 44 74 644 474;
#P outlet 144 295 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 144 256 67 196617 zl group 256;
#P newex 144 191 29 196617 gate;
#P window linecount 1;
#P newex 123 154 31 196617 t b 0;
#P window linecount 0;
#P newex 96 154 21 196617 t 1;
#P newex 96 113 65 196617 sel 240 247;
#P inlet 96 69 15 0;
#P comment 302 85 100 196617 In real life you would use sysexin instead;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 2 1 4 0;
#P connect 4 1 5 0;
#P connect 3 0 5 0;
#P connect 4 0 6 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 2 2 5 1;
#P pop;
#P newobj 94 217 83 196617 p stream2sysex;
#P newex 94 136 25 196617 iter;
#N vpatcher 44 74 644 474;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 50 223 61 196617 append 247;
#P newex 50 199 66 196617 prepend 240;
#N vpatcher 44 74 644 474;
#P window setfont "Sans Serif" 9.;
#P newex 82 128 62 196617 prepend set;
#P outlet 67 190 15 0;
#P newex 67 161 101 196617 pack 0 0;
#P newex 67 78 40 196617 t b i i;
#P window linecount 1;
#P newex 158 112 33 196617 & 15;
#P window linecount 0;
#P newex 82 108 29 196617 >> 4;
#P inlet 67 55 15 0;
#P connect 0 0 3 0;
#P connect 6 0 4 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 3 1 1 0;
#P connect 1 0 6 0;
#P connect 3 2 2 0;
#P connect 2 0 4 1;
#P pop;
#P newobj 67 139 75 196617 p char2nibbles;
#P newex 50 169 67 196617 zl group 250;
#P newex 50 85 27 196617 t b l;
#P newex 67 114 25 196617 iter;
#P newex 50 50 27 196617 atoi;
#P inlet 50 30 15 0;
#P outlet 50 273 15 0;
#P connect 1 0 2 0;
#P connect 2 0 4 0;
#P connect 6 0 5 0;
#P connect 4 0 5 0;
#P connect 5 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 0 0;
#P connect 4 1 3 0;
#P connect 3 0 6 0;
#P pop;
#P newobj 94 114 72 196617 p ascii2sysex;
#P window linecount 0;
#P message 94 371 147 196617;
#P window linecount 1;
#P newex 94 337 62 196617 prepend set;
#P newex 94 83 56 196617 route text;
#P user textedit 94 60 272 79 32896 3 9 dette er en annen test;
#P connect 4 0 5 0;
#P connect 6 0 7 0;
#P fasten 9 0 4 0 339 106 99 106;
#P fasten 10 0 4 0 381 106 99 106;
#P fasten 8 0 4 0 304 106 99 106;
#P connect 1 0 4 0;
#P connect 5 0 6 0;
#P connect 7 0 2 0;
#P connect 2 0 3 0;
#P connect 0 0 1 0;
#P window clipboard copycount 11;


February 28, 2006 | 4:43 pm

On 28 Feb 2006, at 14:25, Mark Hill wrote:

> Now, the data might be encoded as 7 bits, but for sysex, 8 bit data
> is OK.

As other folks have suggested (or will suggest): MIDI data bytes are
7-bit. Sysex messages start with 0xF0 and end with 0xF7, but all the
intermediate bytes have to have the top bit clear. (We could argue
about whether realtime messages with the top bit set are allowed
within Sysex; I don’t know of any kit, hardware or software, that
does that.)

Back in the days when hardware synthesisers roamed the land,
manufacturers used to implement a scheme to "stream" 8-bit data into
7-bit bytes. (Well, the Japanese did; the Americans often favoured
nybble-encodings.)

Those with long memories might want to check the command options in
the configuration files used by Max’s "lib" object.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com


February 28, 2006 | 9:31 pm

>
> On 28 Feb 2006, at 14:25, Mark Hill wrote:
>
> > Now, the data might be encoded as 7 bits, but for sysex, 8 bit data
> > is OK.
>

OK, sorry for my mistake with sysex. I was rembering something that I had in fact done with meta events.

You can send a text string over MIDI by starting a meta event (0xFF) of type 1 (0×01) then a string of ascii characters.

Max support for meta events isn’t strong, but you can parse this data out of the output of [midiin] with a little programming. I have this somewhere… but it’s a long time ago. I’ll see if I can dig it out.

I prefer OSC now. :-)

mzed

see:

http://www.sonicspot.com/guide/midifiles.html



f.e
March 1, 2006 | 7:34 am

To send meta events, you may use Peter Swinnen’s psw.midifile.parser
source to make it real-time, maybe…

f.e


Viewing 12 posts - 1 through 12 (of 12 total)