Hello Max Wizards,
I'm struggling with what seems like a fairly simple problem.
I am wanting to de-tokenize (?) a stream of 7-bit integers coming to me via a Sysex stream from a MIDI device. The stream contains delimiters (tokens) which denote which command/opcode to execute, however each opcode has a discreet discrete number of variables. Here's an example input stream:
08 12 09 00 72 101 108 108 111 08 14 09 30 08 12 32 32 32 32 32 10 65 65 127 97
Opcode 08 has a single parameter that follows
Opcode 09 has a single parameter that follows
Opcode 10 has four parameters that follow
ALL other data should be sent as is, but the ABOVE data should be filtered.
Ideally, I'd like something that does:
Read stream of data; Get an 08, read in the next digit and send it out OUT 1
Get an 09, read in the next digit and send it out OUT 2
Get a 10, read in the next FOUR digits, and send them out OUT 3
Get any other digits, send them out OUT 4.
I have all this built with a state machine, but I'm doing kludgy things like watching for a token, and using that to close a gate, but then having a delay in place to prevent the following digit from going through (i.e. it gets "eaten" by the gate). It works, but it feels wrong.
I have the data in a coll, but finding the logic to, say, find where a "10" token exists, and delete the next 4 digits is not apparent to me.
I also tried using zl objects, but, again trying to use 'sub' to locate the tokens was proving quite difficult.
Any suggestions? I'm a little rusty with Max, but have been using it since 1993 on and off!