MIDI

MIDI


wildcards Index Level Advanced Pick B-Trees
Syntax
Category Article
Type Article
Description acronym for Musical Instrument Digital Interface.

The MIDI specification was developed by a consortium of music industry companies led by roland to standardize the interface for electronic keyboards, synthesizers, controllers, etc.  MIDI data is sent and received as asynchronous serial data (just like the twisted pair rs-232 serial send and receive data used to communicate with terminals) transmitted at 38,400 baud.

The following program reads midi data and writes it into a file and as such is a definition of the MIDI specification.

This entry and more particularly the program is included because it is concise, performs a useful function and has a high degree of difficultly (programs meeting these criteria are hard to find).
Options
See Also
Example echo off
tcl 'esc-data'
tcl 'xcs-on'
tcl 'xonoff (f'
tcl 'set-baud 38400'
file midi.data
tcl 'clear-file midi.data'
id=1
first.data=1
tick=''
start=system(12)
loop
 loop in byte while byte=248 do tick=tick+1 repeat
 begin case
   case byte >= 128 ;* st byte
     midi.data=''
     if byte<240 then
       midi.data(st)=int(byte/16)
       midi.data(ch)=rem(byte,16)+1
     end else
       midi.data(st)=byte

     end
   case first.data
     midi.data(dt1)=byte
     first.data=0
     if status=13 or status=14 or status=241 or status=243 then gosub write.it
em
   case 1 ;* second data byte
     midi.data(dt2)=byte
     first.data=1
     if midi.data(st)<10 then
       if byte=0 then
         read midi.data from midi.data(ch):midi.data(note)
         midi.data(tickoff)=tick
         midi.data(secsoff)=system(12)-start
         write midi.data on id
         id=id+1
         delete midi.data,midi.data(ch):midi.data(note)
       end else
         midi.data(seconds)=system(12)-start
         midi.data(tick)=tick
         write midi.data on midi.data(ch):midi.data(note)
       end
     end else gosub write.item

 end case
repeat
write.item:
 midi.data(seconds)=system(12)-start
 midi.data(tick)=tick
 write midi.data on id
 id=id+1
return
Warnings
Compatibility
wildcards Index Level Advanced Pick B-Trees