00001 /* 00002 midiinterop.h: 00003 00004 Copyright (C) 2002 Michael Gogins 00005 00006 This file is part of Csound. 00007 00008 The Csound Library is free software; you can redistribute it 00009 and/or modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 Csound is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with Csound; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00021 02111-1307 USA 00022 */ 00023 00024 #ifndef MIDIINTEROP_H 00025 #define MIDIINTEROP_H 00026 00027 #include "csoundCore.h" 00028 00029 /* 00030 00031 MIDI INTEROPERABILITY OPCODES 00032 00033 midinoteoff xkey, xvelocity 00034 midinoteonkey xkey, xvelocity 00035 midinoteoncps xcps, xvelocity 00036 midinoteonoct xoct, xvelocity 00037 midinoteonpch xpch, xvelocity 00038 midipolyaftertouch xpolyaftertouch, xcontrollervalue [, olow, hhigh] 00039 midicontrolchange, xcontroller, xcontrollervalue [, olow, hhigh] 00040 midiprogramchange xprogram 00041 midichannelaftertouch xchannelaftertouch [, olow, hhigh] 00042 midipitchbend xpitchbend [, olow, hhigh] 00043 mididefault xdefault, xvalue 00044 00045 Description 00046 00047 These opcodes are designed to simplify writing instruments that can be 00048 used interchangeably for either score or MIDI input, and to make it 00049 easier to adapt instruments originally written for score input to work 00050 with MIDI input. 00051 00052 In general, it should be possible to write instrument definitions that 00053 work identically with both scores and MIDI, including both MIDI files 00054 and real-time MIDI input, without using any conditional statements, 00055 and that take full advantage of MIDI voice messages. 00056 00057 Note that correlating Csound instruments with MIDI channel numbers is 00058 done using the massign opcode for real-time performance. For 00059 file-driven performance, instrument numbers default to MIDI channel 00060 number + 1, but the defaults are overridden by any MIDI program change 00061 messages in the file. 00062 00063 Initialization 00064 00065 xkey - returns MIDI key during MIDI activation, remains unchanged otherwise 00066 kcps - returns MIDI key translated to cycles per second during MIDI 00067 activation, remains unchanged otherwise 00068 xoct - returns MIDI key translated to linear octaves during MIDI 00069 activation, remains unchanged otherwise 00070 xpch - returns MIDI key translated to octave.pch during MIDI 00071 activation, remains unchanged otherwise 00072 xvelocity - returns MIDI velocity during MIDI activation, remains 00073 unchanged otherwise 00074 xpolyaftertouch - returns MIDI polyphonic aftertouch during MIDI 00075 activation, remains unchanged otherwise 00076 xcontroller - specifies a MIDI controller number 00077 xcontrollervalue - returns the value of the MIDI controller during 00078 MIDI activation, remains unchanged otherwise 00079 xprogram - returns the MIDI program change value during MIDI 00080 activation, remains unchanged otherwise 00081 xchannelaftertouch - returns the MIDI channel aftertouch during MIDI 00082 activation, remains unchanged otherwise 00083 xpitchbend - returns the MIDI pitch bend during MIDI activation, 00084 remains unchanged otherwise 00085 xdefault - specifies a default value that will be used during MIDI activation 00086 xvalue - overwritten by xdefault during MIDI activation, remains 00087 unchanged otherwise 00088 olow - optional low value after rescaling, defaults to 0. 00089 hhigh - optional high value after rescaling, defaults to 127. 00090 00091 Performance 00092 00093 for the first 10 opcodes, if the instrument was activated by MIDI 00094 input, the opcode overwrites the value of the "x" input variable(s) 00095 with the corresponding value from MIDI input. If the instrument was 00096 NOT activated by MIDI input, the value of the "x" input variable(s) 00097 remains unchanged. 00098 00099 This enables score pfields to receive MIDI input data during MIDI 00100 activation, and score values otherwise. 00101 00102 For the mididefault opcode, if the instrument was activated by MIDI 00103 input, the opcode will overwrite the value of xvalue with the value of 00104 xdefault. If the instrument was NOT activated by MIDI input, xvalue 00105 will remain unchanged. 00106 00107 This enables score pfields to receive a default value during MIDI 00108 activation, and score values otherwise. 00109 00110 To adapt an ordinary Csound instrument designed for score activation 00111 for score/MIDI interoperability: 00112 00113 1. Change all linen, linseg, and expseg opcodes to linenr, 00114 linsegr, and expsegr, respectively. This will not materially 00115 change score-driven performance. 00116 00117 2. Add the following lines at the beginning of the instrument 00118 definition: 00119 mididefault 60, p3 ; Ensures that a MIDI-activated instrument 00120 will have a positive p3 field. 00121 midinoteoncps p4, p5 ; Puts MIDI key translated to cycles per 00122 second into p4, and MIDI velocity into p5 00123 00124 Obviously, midinoteoncps could be changed to midinoteonoct or 00125 any of the other options, and the choice of pfields is arbitrary. 00126 00127 Author: Michael Gogins 00128 gogins@pipeline.com 00129 00130 */ 00131 00132 typedef struct MIDINOTEON_ 00133 { 00134 OPDS h; 00135 MYFLT *xkey; 00136 MYFLT *xvelocity; 00137 } 00138 MIDINOTEON; 00139 00140 typedef struct MIDIPOLYAFTERTOUCH_ 00141 { 00142 OPDS h; 00143 MYFLT *xpolyaftertouch; 00144 MYFLT *xcontroller; 00145 MYFLT *olow; 00146 MYFLT *hhigh; 00147 } 00148 MIDIPOLYAFTERTOUCH; 00149 00150 typedef struct MIDICONTROLCHANGE_ 00151 { 00152 OPDS h; 00153 MYFLT *xcontroller; 00154 MYFLT *xcontrollervalue; 00155 MYFLT *olow; 00156 MYFLT *hhigh; 00157 } 00158 MIDICONTROLCHANGE; 00159 00160 typedef struct MIDIPROGRAMCHANGE_ 00161 { 00162 OPDS h; 00163 MYFLT *xprogram; 00164 } 00165 MIDIPROGRAMCHANGE; 00166 00167 typedef struct MIDICHANNELAFTERTOUCH_ 00168 { 00169 OPDS h; 00170 MYFLT *xchannelaftertouch; 00171 MYFLT *olow; 00172 MYFLT *hhigh; 00173 } 00174 MIDICHANNELAFTERTOUCH; 00175 00176 typedef struct MIDIPITCHBEND_ 00177 { 00178 OPDS h; 00179 MYFLT *xpitchbend; 00180 MYFLT *olow; 00181 MYFLT *hhigh; 00182 } 00183 MIDIPITCHBEND; 00184 00185 typedef struct MIDIDEFAULT_ 00186 { 00187 OPDS h; 00188 MYFLT *xdefault; 00189 MYFLT *xvalue; 00190 } 00191 MIDIDEFAULT; 00192 00193 #endif