42 event->timestamp = cslMIDI->
time;
52 ((
unsigned) ((Pm_MessageStatus(event->message) & 0xF0) >> 4) );
53 cslMIDI->
channel = Pm_MessageStatus(event->message) & 0x0F;
54 cslMIDI->
data1 = Pm_MessageData1(event->message);
55 cslMIDI->
data2 = Pm_MessageData2(event->message);
56 cslMIDI->
time =
event->timestamp;
66 return (((
unsigned)message << 4) + channel );
109 if(err != pmNoError )
115 char dev_nam[128], * nl;
117 printf(
"\nPortMidi devices:\n");
118 for (i = 0; i < Pm_CountDevices(); i++) {
119 const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
120 if ((nl = index(info->name,
'\n')) == NULL)
121 strcpy(dev_nam, info->name);
123 strncpy(dev_nam, info->name, (nl - info->name));
124 printf(
"\tDeviceID %d: %s, %s", i, info->interf, dev_nam);
125 if (info->input) printf(
" (input)");
126 if (info->output) printf(
" (output)");
133 printf(
"PortMidi device count = %d\n", Pm_CountDevices());
139 return (
int) Pm_CountDevices();
143 return (
int) Pm_GetDefaultInputDeviceID();
147 return (
int) Pm_GetDefaultOutputDeviceID();
151 return Pm_GetDeviceInfo((PmDeviceID) deviceID );
158 logMsg(
kLogError,
"An error occured while using PortMIDI, Error# %d, %s",err, Pm_GetErrorText(err));
170 mDeviceID = Pm_GetDefaultInputDeviceID();
185 if( ! info->input ) {
196 if(err != pmNoError )
214 if(err != pmNoError ) {
223 #ifdef DEBUG_MIDIIO_READ
224 unsigned cmd, voice, pitch = 0, vel;
229 cmd = Pm_Messagevoid(msg) & 0xF0;
230 voice = Pm_Messagevoid(msg) & 0x0F;
231 pitch = Pm_MessageData1(msg);
232 vel = Pm_MessageData2(msg);
233 printf(
"\tGot message: time %.3f, cmd: %x midich: %d data1: %d data2: %d\n", (
float)
mBuffer[0].timestamp / 1000.0f, cmd, voice, pitch, vel);
237 logMsg(
"in MIDIIn::read(). MIDI message not read");
246 unsigned cmd, voice, pitch = 0, vel;
249 cmd = (Pm_MessageStatus(msg) & 0xF0) >> 4;
250 voice = Pm_MessageStatus(msg) & 0x0F;
251 pitch = Pm_MessageData1(msg);
252 vel = Pm_MessageData2(msg);
304 printf(
"Unknown input: void=%d chan=%d value1=%d value2=%d", cmd, voice, pitch, vel);
308 #ifdef DEBUG_MIDIIO_READ_INTERPRET
314 unsigned cmd, voice, pitch = 0, vel;
317 cmd = Pm_MessageStatus(msg) & 0xF0;
318 voice = Pm_MessageStatus(msg) & 0x0F;
319 pitch = Pm_MessageData1(msg);
320 vel = Pm_MessageData2(msg);
321 printf(
"\tGot message: time %.3f, cmd: %x midich: %d data1: %d data2: %d\n", (
float)
mBuffer[0].timestamp / 1000.0f, cmd, voice, pitch, vel);
325 printf(
"MIDIIn message received\n");
328 printf(
"\t message: kNone");
331 printf(
"\t message: kNoteOff");
334 printf(
"\t message: kNoteOn");
337 printf(
"\t message: kPolyTouch");
340 printf(
"\t message: kControlChange");
343 printf(
"\t message: kProgramChange");
346 printf(
"\t message: kAftertouch");
349 printf(
"\t message: kPitchWheel");
352 printf(
"\t message: kSysEX");
355 printf(
"\t message: unknown");
406 err = Pm_SetFilter(
mMIDIStream, PM_FILT_ACTIVE | PM_FILT_CLOCK);
407 if(err != pmNoError )
416 if(err != pmNoError )
426 if(err != pmNoError )
432 logMsg(
"active sensing filter state not changed, mFilterFlag = %d",
mFilterFlag);
441 if(err != pmNoError )
451 if(err != pmNoError )
467 if(err != pmNoError )
477 if(err != pmNoError )
494 mDeviceID = Pm_GetDefaultOutputDeviceID();
510 if( ! info->output ) {
521 if(err != pmNoError )
538 long eventLength = 1;
541 if(err != pmNoError )
547 for(i = 0; i < length; i++ ) {
561 if(err != pmNoError )
568 if(err != pmNoError )
580 if(err != pmNoError )
589 (
int)ceil(amplitude * 127.0f) );
592 if(err != pmNoError )
604 if(err != pmNoError )
613 (
int)ceil(amplitude * 127.0f) );
616 if(err != pmNoError )
628 if(err != pmNoError )
640 if(err != pmNoError )
652 if(err != pmNoError )
664 if(err != pmNoError )
676 if(err != pmNoError )
void logMsg(const char *format,...)
These are the public logging messages.
MIDIIO class: superclass of in and out; has a message buffer and current messages It's a model so you...
void write_PitchWheel(unsigned channel, unsigned amount)
[0, 16384]
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
bool is_PitchWheel_received()
unsigned get_PolyAftertouch()
void open()
method for opening the default stream.
bool is_Aftertouch_received()
long mBufferSize
fundamental members
bool is_NoteOff_received()
CSL_MIDIMessageType
CSL_MIDIMessageType.
void filter_active_sensing(bool flag)
bool mIsOpen
instance status indicators
void set_buffer_size(unsigned bufferSize)
unsigned get_PitchWheel()
float keyToFreq(unsigned midiKey)
MIDI Conversions.
void filter_sysex(bool flag)
int mDeviceID
device ID which will/is opened.
MIDIIO()
< It's a model & sends itself "changed"
float get_velocity_float()
has range of [0.0 1.0] mapped to [0 127]
const PmDeviceInfo * get_device_info(int deviceID)
int get_default_input_id()
void filter_clock_msg(bool flag)
bool is_PolyTouch_received()
void copy_CSL_MIDIMessage(CSL_MIDIMessage *source, CSL_MIDIMessage *dest)
copy_CSL_MIDIMessage – copies CSL_MIDIMessage
bool is_ProgramChange_received()
void write_short(CSL_MIDIMessage msg)
unsigned get_ControlChange_function()
PmStream * mMIDIStream
opened stream
void set_buffer_size(unsigned bufferSize)
unsigned get_ControlChange_value()
int get_default_output_id()
void write_PolyTouch(unsigned channel, unsigned pitch, unsigned amount)
unsigned freqToKey(float frequency)
freqToKey – converts from frequency in Hz to MIDI key #
void write_NoteOn(unsigned channel, unsigned pitch, unsigned velocity)
convenience method for each MIDI messages writes directly and doesn't use member mMsg for temporal st...
bool poll()
poll returns a bool (really quickly)
PmEvent mBuffer[1]
buffer which gets filled by read()
bool is_ControlChange_received()
void write_NoteOff(unsigned channel, unsigned pitch, unsigned velocity)
MIDINote#, [0, 127].
unsigned get_Aftertouch()
void write_ControlChange(unsigned channel, unsigned function, unsigned value)
unsigned get_ProgramNumber()
bool is_open()
can't open the abstract class
CSL_MIDIMessageType message
void write_Aftertouch(unsigned channel, unsigned amount)
[0, 127]
void handle_error(PmError err)
static unsigned mNumInstantiated
void dump_CSL_MIDIMessage()
bool is_NoteOn_received()
void CSL_MIDIMessageToPmEvent(CSL_MIDIMessage *cslMIDI, PmEvent *event)
CSL_MIDIMessageToPmEvent – converts CSL_MIDIMessage to PmEvent.
static bool mIsPortTimeStarted
status indicators
void read_interpret()
read method and sets internal flag for which message was received
void write_SysEX(long when, unsigned char *msg)
virtual void close()
closing MIDI stream
void dump_device_info()
printing device info for all devices.
void dump_count_devices()
printing total number of devices available
void set_message(CSL_MIDIMessage msg, long when)
static bool mIsInitialized
< static flags to keep track of driver state
void read()
generic read method. gets MIDI message and store it in mBuffer
unsigned Message_ChannelToStatus(CSL_MIDIMessageType message, unsigned channel)
Message_ChannelToStatus – converts from message and channel to status byte.
void write_ProgramChange(unsigned channel, unsigned programNum)
void PmEventToCSL_MIDIMessage(PmEvent *event, CSL_MIDIMessage *cslMIDI)
PmEventToCSL_MIDIMessage – converts PmEvent to CSL_MIDIMessage.
void set_latency(long latency)