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
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)
33 //-----------------------------------------------------------------------------
37 #include "chuck_def.h"
38 #ifndef __DISABLE_MIDI__
41 #include "util_buffers.h"
46 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 // name: class MidiOut
83 //-----------------------------------------------------------------------------
91 t_CKBOOL
open( t_CKUINT device_num
= 0 );
93 t_CKBOOL
good() { return m_valid
; }
94 t_CKINT
num() { return m_valid
? (t_CKINT
)m_device_num
: -1; }
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
; }
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
);
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
);
120 std::vector
<unsigned char> m_msg
;
121 t_CKUINT m_device_num
;
123 t_CKBOOL m_suppress_output
;
129 //-----------------------------------------------------------------------------
130 // name: class MidiIn
132 //-----------------------------------------------------------------------------
133 class MidiIn
: public Chuck_Event
140 t_CKBOOL
open( t_CKUINT device_num
= 0 );
142 t_CKBOOL
good() { return m_valid
; }
143 t_CKINT
num() { return m_valid
? (t_CKINT
)m_device_num
: -1; }
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
; }
153 t_CKUINT
recv( MidiMsg
* msg
);
156 CBufferAdvance
* m_buffer
;
157 t_CKUINT m_read_index
;
160 t_CKUINT m_device_num
;
162 t_CKBOOL m_suppress_output
;
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
,
182 static std::vector
<RtMidiIn
*> the_mins
;
183 static std::vector
<CBufferAdvance
*> the_bufs
;
190 static t_CKBOOL
open( MidiOut
* mout
, t_CKINT device_num
);
191 static t_CKBOOL
close( MidiOut
* mout
);
197 static std::vector
<RtMidiOut
*> the_mouts
;
201 //-----------------------------------------------------------------------------
202 // name: class MidiRW
203 // desc: reads and writes midi messages from file
204 //-----------------------------------------------------------------------------
212 t_CKBOOL
open( const char * filename
);
216 t_CKBOOL
read( MidiMsg
* msg
, t_CKTIME
* time
);
217 t_CKBOOL
write( MidiMsg
* msg
, t_CKTIME
* time
);
223 // closes all MidiRW file handles
224 t_CKBOOL
midirw_detach( );
227 //-----------------------------------------------------------------------------
228 // name: class MidiMsgOut
229 // desc: reads midi messages from file
230 //-----------------------------------------------------------------------------
238 t_CKBOOL
open( const char * filename
);
242 t_CKBOOL
write( MidiMsg
* msg
, t_CKTIME
* time
);
249 //-----------------------------------------------------------------------------
250 // name: class MidiMsgIn
251 // desc: reads midi messages from file
252 //-----------------------------------------------------------------------------
260 t_CKBOOL
open( const char * filename
);
264 t_CKBOOL
read( MidiMsg
* msg
, t_CKTIME
* time
);