*** empty log message ***
[chuck-blob.git] / v2 / midiio_rtmidi.h
blob17bb057c2720efb6185bcc3e49ef79b91eb0977f
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: midiio_rtmidi.h
27 // desc: midi io header
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // Ananya Misra (amisra@cs.princeton.edu)
32 // date: Summer 2005
33 //-----------------------------------------------------------------------------
34 #ifndef __MIDI_IO_H__
35 #define __MIDI_IO_H__
37 #include "chuck_def.h"
38 #ifndef __DISABLE_MIDI__
39 #include "rtmidi.h"
40 #endif
41 #include "util_buffers.h"
46 //-----------------------------------------------------------------------------
47 // stuff
48 //-----------------------------------------------------------------------------
49 #define MIDI_NOTEON 0x90
50 #define MIDI_NOTEOFF 0x80
51 #define MIDI_POLYPRESS 0xa0
52 #define MIDI_CTRLCHANGE 0xb0
53 #define MIDI_PROGCHANGE 0xc0
54 #define MIDI_CHANPRESS 0xd0
55 #define MIDI_PITCHBEND 0xe0
56 #define MIDI_ALLNOTESOFF 0x7b
61 //-----------------------------------------------------------------------------
62 // definitions
63 //-----------------------------------------------------------------------------
64 union MidiMsg
66 t_CKBYTE data[4];
67 // t_CKUINT dw;
73 // forward reference
74 class RtMidiOut;
75 class RtMidiIn;
80 //-----------------------------------------------------------------------------
81 // name: class MidiOut
82 // desc: midi out
83 //-----------------------------------------------------------------------------
84 class MidiOut
86 public:
87 MidiOut();
88 ~MidiOut();
90 public:
91 t_CKBOOL open( t_CKUINT device_num = 0 );
92 t_CKBOOL close();
93 t_CKBOOL good() { return m_valid; }
94 t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; }
96 public:
97 void set_suppress( t_CKBOOL print_or_not )
98 { m_suppress_output = print_or_not; }
99 t_CKBOOL get_suppress()
100 { return m_suppress_output; }
102 public:
103 t_CKUINT send( t_CKBYTE status );
104 t_CKUINT send( t_CKBYTE status, t_CKBYTE data1 );
105 t_CKUINT send( t_CKBYTE status, t_CKBYTE data1, t_CKBYTE data2 );
106 t_CKUINT send( const MidiMsg * msg );
108 public:
109 t_CKUINT noteon( t_CKUINT channel, t_CKUINT note, t_CKUINT velocity );
110 t_CKUINT noteoff( t_CKUINT channel, t_CKUINT note, t_CKUINT velocity );
111 t_CKUINT polypress( t_CKUINT channel, t_CKUINT note, t_CKUINT pressure );
112 t_CKUINT ctrlchange( t_CKUINT channel, t_CKUINT ctrl_num, t_CKUINT ctrl_val );
113 t_CKUINT progchange( t_CKUINT channel, t_CKUINT patch );
114 t_CKUINT chanpress( t_CKUINT channel, t_CKUINT pressure );
115 t_CKUINT pitchbend( t_CKUINT channel, t_CKUINT bend_val );
116 t_CKUINT allnotesoff( t_CKUINT channel );
118 public:
119 RtMidiOut * mout;
120 std::vector<unsigned char> m_msg;
121 t_CKUINT m_device_num;
122 t_CKBOOL m_valid;
123 t_CKBOOL m_suppress_output;
129 //-----------------------------------------------------------------------------
130 // name: class MidiIn
131 // desc: midi
132 //-----------------------------------------------------------------------------
133 class MidiIn : public Chuck_Event
135 public:
136 MidiIn();
137 ~MidiIn();
139 public:
140 t_CKBOOL open( t_CKUINT device_num = 0 );
141 t_CKBOOL close();
142 t_CKBOOL good() { return m_valid; }
143 t_CKINT num() { return m_valid ? (t_CKINT)m_device_num : -1; }
145 public:
146 void set_suppress( t_CKBOOL print_or_not )
147 { m_suppress_output = print_or_not; }
148 t_CKBOOL get_suppress()
149 { return m_suppress_output; }
151 public:
152 t_CKBOOL empty();
153 t_CKUINT recv( MidiMsg * msg );
155 public:
156 CBufferAdvance * m_buffer;
157 t_CKUINT m_read_index;
158 RtMidiIn * min;
159 t_CKBOOL m_valid;
160 t_CKUINT m_device_num;
161 Chuck_Object * SELF;
162 t_CKBOOL m_suppress_output;
166 void probeMidiIn();
167 void probeMidiOut();
170 class MidiInManager
172 public:
173 static t_CKBOOL open( MidiIn * min, t_CKINT device_num );
174 static t_CKBOOL close( MidiIn * min );
176 static void cb_midi_input( double deltatime, std::vector<unsigned char> * msg,
177 void *userData );
178 protected:
179 MidiInManager();
180 ~MidiInManager();
182 static std::vector<RtMidiIn *> the_mins;
183 static std::vector<CBufferAdvance *> the_bufs;
187 class MidiOutManager
189 public:
190 static t_CKBOOL open( MidiOut * mout, t_CKINT device_num );
191 static t_CKBOOL close( MidiOut * mout );
193 protected:
194 MidiOutManager();
195 ~MidiOutManager();
197 static std::vector<RtMidiOut *> the_mouts;
201 //-----------------------------------------------------------------------------
202 // name: class MidiRW
203 // desc: reads and writes midi messages from file
204 //-----------------------------------------------------------------------------
205 class MidiRW
207 public:
208 MidiRW();
209 ~MidiRW();
211 public:
212 t_CKBOOL open( const char * filename );
213 t_CKBOOL close();
215 public:
216 t_CKBOOL read( MidiMsg * msg, t_CKTIME * time );
217 t_CKBOOL write( MidiMsg * msg, t_CKTIME * time );
219 protected:
220 FILE * file;
223 // closes all MidiRW file handles
224 t_CKBOOL midirw_detach( );
227 //-----------------------------------------------------------------------------
228 // name: class MidiMsgOut
229 // desc: reads midi messages from file
230 //-----------------------------------------------------------------------------
231 class MidiMsgOut
233 public:
234 MidiMsgOut();
235 ~MidiMsgOut();
237 public:
238 t_CKBOOL open( const char * filename );
239 t_CKBOOL close();
241 public:
242 t_CKBOOL write( MidiMsg * msg, t_CKTIME * time );
244 protected:
245 FILE * file;
249 //-----------------------------------------------------------------------------
250 // name: class MidiMsgIn
251 // desc: reads midi messages from file
252 //-----------------------------------------------------------------------------
253 class MidiMsgIn
255 public:
256 MidiMsgIn();
257 ~MidiMsgIn();
259 public:
260 t_CKBOOL open( const char * filename );
261 t_CKBOOL close();
263 public:
264 t_CKBOOL read( MidiMsg * msg, t_CKTIME * time );
266 protected:
267 FILE * file;
271 #endif