BBC MIDI Redirection ==================== J.G.Harston, 1989-2010 mdfs.net/Software/MIDI/Redirect -- jgh@mdfs.net 70 Camm Street, Walkley, Sheffield S6 3TR *MIDI (ON|OFF|) (&) ---------------------------------- *MIDI sets up an intercept on the SOUND command (OSWORD 7) to direct it via a 6850 MIDI port. *MIDI or *MIDI ON turns on the intercept, and *MIDI OFF turns it off. You can specify the MIDI channel to use, for instance to transmit on MIDI channel 4 use: *MIDI 4 By default, *MIDI transmits on MIDI channel 1. If there are no notes playing you can use *MIDI again to change the MIDI channel number, or use SOUND -257 (see below). SOUND commands -------------- Once the MIDI intercept is turned on, all SOUND commands are sent to the MIDI interface instead of the internal sound system. Up to fifteen simultaneous notes can be sent with SOUND 1,v,p,d to SOUND 15,v,p,d. There are a few limitations: * The duration of any note is ignored. The length of the note is defined by sending another note (or a silence) after it to turn it off. This means that this is only suitable for direct use with programs that use a timing mechanism to time the notes, rather than using the sound queue to time them. For example, programs that use a structure similar to: T%=TIME+delay% SOUND etc, etc, etc, REPEAT UNTIL TIME>T% * SOUND channel 0 (noise) is ignored and passed on to the BBC sound system. If you do not want this to happen, use *FX210,1 to turn off the internal sound or the experimental SOUND -257,-255,-1,0. * A volume of zero (eg SOUND 1,0,101,2) turns off the previous note, but does not start a new note. A volume of -1 to -15 is converted to a MIDI velocity of 8 to 120. An envelope number of 1 to 16 is converted to a MIDI velocity of 120. SOUND extensions ---------------- As well as passing normal SOUND commands to the MIDI interface, you can control the MIDI system directly with SOUND -257 and SOUND -258. SOUND -258,Command,Note,Velocity - Send raw MIDI command SOUND -257,Command,Note,Velocity - Send to current channel SOUND -257,-1,channel,0 - Set MIDI channel 1-16 SOUND -257,-1,0,0 - All notes off SOUND -257 adds the current MIDI channel to the command byte. SOUND -258 does not change the command byte, so the MIDI channel can be specified as part of the command. For example: SOUND -257,&90,60,127 :REM Send Note On to current channel SOUND -257,&91,60,127 :REM Send Note On to (current channel)+1 SOUND -258,&94,60,127 :REM Send Note On to channel 5 (ie 4+1) Note that the MIDI channel passed in the command byte is one less than the MIDI channel number. For instance, &94 sends to MIDI channel 5. SOUND -257,-1,0,0 sends a Note Off command for all possible notes on the current channel. SOUND -257,-1,channel,0 sets the MIDI channel for future transmissions. Summary of MIDI Messages ------------------------ The following can be sent with SOUND -257 to the current MIDI channel or SOUND -258 to the channel specified in the command byte. SOUND -257,&80,note,velocity Note Off SOUND -257,&90,note,velocity Note On SOUND -257,&A0,note,velocity Note Aftertouch SOUND -257,&B0,control,value Control Change SOUND -257,&C0,program,0 Program Change SOUND -257,&D0,velocity,0 Channel Aftertouch SOUND -257,&E0,pitchbend,0 Pitch Change Wheel The note and velocity parameters are combined so that the Change Pitch Wheel command can be sent with as a 14-bit number. Otherwise, the parameters are all 7-bit values and the higher bits are ignored. The following must be sent with SOUND -258, otherwise the command byte will be overwritten with the current MIDI channel. SOUND -258,&F0,0,0 System Exclusive SOUND -258,&F1,0,0 undefined SOUND -258,&F2,0,0 Song Position Pointer SOUND -258,&F3,0,0 Song Select SOUND -258,&F4,0,0 undefined SOUND -258,&F5,0,0 undefined SOUND -258,&F6,0,0 Tune Request SOUND -258,&F7,0,0 End of Exclusive SOUND -258,&F8,0,0 Timing Clock SOUND -258,&F9,0,0 undefined SOUND -258,&FA,0,0 Start SOUND -258,&FB,0,0 Continue SOUND -258,&FC,0,0 Stop SOUND -258,&FD,0,0 undefined SOUND -258,&FE,0,0 Active Sensing SOUND -258,&FF,0,0 Reset To send additional data bytes, for instance within a System Exclusive block or for the Song Select parameters, use a value less than &80 in place of the Command, for example: SOUND -258,&F3,0,0:SOUND -258,3,0,0:REM Select Song 3 The MIDI interface is controlled with a command byte less than 0, they can be sent with SOUND -257 or SOUND -258. SOUND -257,-1,0,0 All notes off SOUND -257,-1,channel,0 Set MIDI channel 1-16 Experimental: SOUND -257,-256,-1,0 Enable MOS noise channel SOUND -257,-255,-1,0 Disable MOS noise channel The All Notes Off sequence is sent 1- times, so SOUND -257,-2,0,0 loops through sending Note Off three times. Setting the MIDI channel with command -2 to -256 is reserved for mapping individual SOUND channels to individual MIDI channels. Technical Notes --------------- *MIDI redirects sound commands to a MIDI port using a 6850 ACIA. Almost all BBC MIDI interfaces use a 6850. See mdfs.net/MIDI for some circuit diagrams. Different MIDI interfaces appear in the I/O map in different places, and some interfaces have more than one port. By default *MIDI accesses a MIDI interface at &FCF0/1, but you can specify the address to use. For example: *MIDI &FC08 - M2000 port 1 *MIDI 6 &FCF2 - ETI/JGH port 2 on MIDI channel 6 Some MIDI I/O addresses are: M2000 port 1 &FC08 ETI/JGH port 1 &FCF0 M2000 port 2 &FC0A ETI/JGH port 2 &FCF2 M2000 port 3 &FC0C JGH port 3 &FCF4 EMR Any JGH port 4 &FCF6 The EMR interface is accessible at every address in &FCxx. You should use the default of &FCF0 to access it. The M2000, ETI and JGH MIDI interfaces use the BBC's 1MHz clock to form the ACIA clock signal. The EMR interface uses its own external clock. The *MIDI command sends some test data to work out how to initialise the ACIA to set the correct clock speed. The default MIDI port and clock speed can be set by modifying the *MIDI command. The first two bytes hold the address and the control byte to program the ACIA. These are normally &F0 and &00. You can change them with the following code: ch%=OPENUP"MIDI" BPUT#ch%,&F0:REM MIDI port at &FCF0 BPUT#ch%,&15:REM &00 to interrogate MIDI interface :REM &15 for 1MHz clock :REM &16 for 2MHz clock CLOSE#ch% The file MIDI/prn is a graphics text file showing a circuit diagram for a MIDI interface. Use *PRINT MIDI/prn or *TYPE MIDI/prn to display it. Acknowledgements ---------------- Robert Sprowson for suggesting code to work out the clock speed setting. Version History --------------- v1.00 20-Oct-1989 Initial version v1.01 20-Dec-1989 Added parameter v1.02 15-Jan-1991 Modifed Clock for EMR interface v1.10 20-Mar-1992 Tidied up code, added parameter v1.11 21-Mar-1992 Added default parameters v1.12 25-Jul-2010 Works out Clock setting v1.13 28-Jul-2010 Some optimisation and tidying v1.20 30-Jul-2010 AllOff loops from SOUND x,-N,x,x, ignores chan>16