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"
39 #include "util_buffers.h"
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 #define MIDI_NOTEON 0x90
48 #define MIDI_NOTEOFF 0x80
49 #define MIDI_POLYPRESS 0xa0
50 #define MIDI_CTRLCHANGE 0xb0
51 #define MIDI_PROGCHANGE 0xc0
52 #define MIDI_CHANPRESS 0xd0
53 #define MIDI_PITCHBEND 0xe0
54 #define MIDI_ALLNOTESOFF 0x7b
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
72 // name: class MidiOut
74 //-----------------------------------------------------------------------------
82 t_CKBOOL
open( t_CKUINT device_num
= 0 );
84 t_CKBOOL
good() { return m_valid
; }
85 t_CKINT
num() { return m_valid
? (t_CKINT
)m_device_num
: -1; }
88 void set_suppress( t_CKBOOL print_or_not
)
89 { m_suppress_output
= print_or_not
; }
90 t_CKBOOL
get_suppress()
91 { return m_suppress_output
; }
94 t_CKUINT
send( t_CKBYTE status
);
95 t_CKUINT
send( t_CKBYTE status
, t_CKBYTE data1
);
96 t_CKUINT
send( t_CKBYTE status
, t_CKBYTE data1
, t_CKBYTE data2
);
97 t_CKUINT
send( const MidiMsg
* msg
);
100 t_CKUINT
noteon( t_CKUINT channel
, t_CKUINT note
, t_CKUINT velocity
);
101 t_CKUINT
noteoff( t_CKUINT channel
, t_CKUINT note
, t_CKUINT velocity
);
102 t_CKUINT
polypress( t_CKUINT channel
, t_CKUINT note
, t_CKUINT pressure
);
103 t_CKUINT
ctrlchange( t_CKUINT channel
, t_CKUINT ctrl_num
, t_CKUINT ctrl_val
);
104 t_CKUINT
progchange( t_CKUINT channel
, t_CKUINT patch
);
105 t_CKUINT
chanpress( t_CKUINT channel
, t_CKUINT pressure
);
106 t_CKUINT
pitchbend( t_CKUINT channel
, t_CKUINT bend_val
);
107 t_CKUINT
allnotesoff( t_CKUINT channel
);
111 std::vector
<unsigned char> m_msg
;
112 t_CKUINT m_device_num
;
114 t_CKBOOL m_suppress_output
;
120 //-----------------------------------------------------------------------------
121 // name: class MidiIn
123 //-----------------------------------------------------------------------------
124 class MidiIn
: public Chuck_Event
131 t_CKBOOL
open( t_CKUINT device_num
= 0 );
133 t_CKBOOL
good() { return m_valid
; }
134 t_CKINT
num() { return m_valid
? (t_CKINT
)m_device_num
: -1; }
137 void set_suppress( t_CKBOOL print_or_not
)
138 { m_suppress_output
= print_or_not
; }
139 t_CKBOOL
get_suppress()
140 { return m_suppress_output
; }
144 t_CKUINT
recv( MidiMsg
* msg
);
147 CBufferAdvance
* m_buffer
;
148 t_CKUINT m_read_index
;
151 t_CKUINT m_device_num
;
153 t_CKBOOL m_suppress_output
;
164 static t_CKBOOL
open( MidiIn
* min
, t_CKINT device_num
);
165 static t_CKBOOL
close( MidiIn
* min
);
167 static void cb_midi_input( double deltatime
, std::vector
<unsigned char> * msg
,
173 static std::vector
<RtMidiIn
*> the_mins
;
174 static std::vector
<CBufferAdvance
*> the_bufs
;
181 static t_CKBOOL
open( MidiOut
* mout
, t_CKINT device_num
);
182 static t_CKBOOL
close( MidiOut
* mout
);
188 static std::vector
<RtMidiOut
*> the_mouts
;
192 //-----------------------------------------------------------------------------
193 // name: class MidiRW
194 // desc: reads and writes midi messages from file
195 //-----------------------------------------------------------------------------
203 t_CKBOOL
open( const char * filename
);
207 t_CKBOOL
read( MidiMsg
* msg
, t_CKTIME
* time
);
208 t_CKBOOL
write( MidiMsg
* msg
, t_CKTIME
* time
);
214 // closes all MidiRW file handles
215 t_CKBOOL
midirw_detach( );
218 //-----------------------------------------------------------------------------
219 // name: class MidiMsgOut
220 // desc: reads midi messages from file
221 //-----------------------------------------------------------------------------
229 t_CKBOOL
open( const char * filename
);
233 t_CKBOOL
write( MidiMsg
* msg
, t_CKTIME
* time
);
240 //-----------------------------------------------------------------------------
241 // name: class MidiMsgIn
242 // desc: reads midi messages from file
243 //-----------------------------------------------------------------------------
251 t_CKBOOL
open( const char * filename
);
255 t_CKBOOL
read( MidiMsg
* msg
, t_CKTIME
* time
);