cleaned up midi1
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2934 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,19 +6,17 @@ UsePublicHeaders midi ;
|
||||
|
||||
SharedLibrary midi :
|
||||
Midi.cpp
|
||||
MidiGlue.cpp
|
||||
MidiPort.cpp
|
||||
MidiPortConsumer.cpp
|
||||
MidiStore.cpp
|
||||
MidiSynth.cpp
|
||||
MidiSynthFile.cpp
|
||||
MidiText.cpp
|
||||
MidiEvent.cpp
|
||||
Samples.cpp
|
||||
Synth.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs libmidi.so :
|
||||
be
|
||||
stdc++.r4
|
||||
midi2
|
||||
;
|
||||
|
||||
+325
-420
@@ -1,465 +1,370 @@
|
||||
/**
|
||||
* @file Midi.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
* Copyright (c) 2002 Michael Pfeiffer
|
||||
* Copyright (c) 2002 Jerome Leveque
|
||||
* Copyright (c) 2002 Paul Stadler
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* @author Jerome Leveque
|
||||
* @author Paul Stadler
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <List.h>
|
||||
#include <MidiProducer.h>
|
||||
|
||||
#include "Midi.h"
|
||||
#include "MidiGlue.h"
|
||||
#include "debug.h"
|
||||
#include "MidiEvent.h"
|
||||
|
||||
//-----------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define MSG_CODE_PROCESS_EVENT 1
|
||||
#define MSG_CODE_TERMINATE_THREAD 0
|
||||
status_t _run_thread(void* data)
|
||||
{
|
||||
BMidi* midi = (BMidi*) data;
|
||||
midi->Run();
|
||||
midi->isRunning = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initialization Stuff
|
||||
BMidi::BMidi()
|
||||
{
|
||||
fConnectionList = new BList();
|
||||
fIsRunning = false;
|
||||
|
||||
fInflowPort = create_port(1, "Inflow Port");
|
||||
|
||||
fInflowTask = spawn_thread(
|
||||
_inflow_task_, "BMidi Inflow Thread",
|
||||
B_REAL_TIME_PRIORITY, (void *)this);
|
||||
|
||||
fInflowAlive = resume_thread(fInflowTask) == B_OK;
|
||||
connections = new BList;
|
||||
threadId = -1;
|
||||
isRunning = false;
|
||||
|
||||
producer = new BMidiLocalProducer("MidiGlue(out)");
|
||||
consumer = new BMidiGlue(this, "MidiGlue(in)");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidi::~BMidi()
|
||||
{
|
||||
write_port(fInflowPort, MSG_CODE_TERMINATE_THREAD, NULL, 0);
|
||||
Stop();
|
||||
|
||||
status_t exit_value;
|
||||
wait_for_thread(fInflowTask, &exit_value);
|
||||
status_t result;
|
||||
wait_for_thread(threadId, &result);
|
||||
|
||||
delete_port(fInflowPort);
|
||||
delete fConnectionList;
|
||||
producer->Release();
|
||||
consumer->Release();
|
||||
|
||||
delete connections;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stubs for midi event hooks.
|
||||
void BMidi::NoteOff(uchar chan, uchar note, uchar vel, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::NoteOn(uchar chan, uchar note, uchar vel, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::KeyPressure(uchar chan, uchar note, uchar pres, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::ControlChange(uchar chan, uchar ctrl_num, uchar ctrl_val, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::ProgramChange(uchar chan, uchar prog_num, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::ChannelPressure(uchar chan, uchar pres, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::PitchBend(uchar chan, uchar lsb, uchar msb, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::SystemExclusive(void * data, size_t data_len, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::SystemCommon(uchar stat_byte, uchar data1, uchar data2, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::SystemRealTime(uchar stat_byte, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::TempoChange(int32 bpm, uint32 time)
|
||||
{
|
||||
}
|
||||
void BMidi::AllNotesOff(bool just_chan, uint32 time)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Public API Functions
|
||||
status_t BMidi::Start()
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
fRunTask = spawn_thread(_run_thread_,
|
||||
"BMidi Run Thread", B_REAL_TIME_PRIORITY, (void *)this);
|
||||
fIsRunning = true;
|
||||
status_t ret = resume_thread(fRunTask);
|
||||
if(ret != B_OK)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SystemExclusive(void* data, size_t length, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SystemCommon(uchar status, uchar data1, uchar data2, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SystemRealTime(uchar status, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::TempoChange(int32 beatsPerMinute, uint32 time)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::AllNotesOff(bool justChannel, uint32 time)
|
||||
{
|
||||
for (uchar channel = 1; channel <= 16; ++channel)
|
||||
{
|
||||
fIsRunning = false;
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
SprayControlChange(channel, B_ALL_NOTES_OFF, 0, time);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void BMidi::Stop()
|
||||
{
|
||||
status_t exit_value;
|
||||
status_t ret;
|
||||
fIsRunning = false;
|
||||
ret = wait_for_thread(fRunTask, &exit_value);
|
||||
}
|
||||
|
||||
bool BMidi::IsRunning() const
|
||||
{
|
||||
thread_info info;
|
||||
get_thread_info(fRunTask,&info);
|
||||
if(find_thread("BMidi Run Thread") == fRunTask)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void BMidi::Connect(BMidi *to_object)
|
||||
{
|
||||
fConnectionList->AddItem((void *)to_object);
|
||||
}
|
||||
|
||||
void BMidi::Disconnect(BMidi *from_object)
|
||||
{
|
||||
fConnectionList->RemoveItem((void *)from_object);
|
||||
}
|
||||
|
||||
bool BMidi::IsConnected(BMidi * to_object) const
|
||||
{
|
||||
return fConnectionList->HasItem((void *)to_object);
|
||||
}
|
||||
|
||||
BList * BMidi::Connections() const
|
||||
{
|
||||
return fConnectionList;
|
||||
}
|
||||
|
||||
void BMidi::SnoozeUntil(uint32 time) const
|
||||
{
|
||||
snooze_until((uint64)time*1000, B_SYSTEM_TIMEBASE);
|
||||
}
|
||||
|
||||
bool BMidi::KeepRunning()
|
||||
{
|
||||
return fIsRunning;
|
||||
}
|
||||
|
||||
void BMidi::Run()
|
||||
{
|
||||
while(KeepRunning())
|
||||
snooze(50000);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Spray Functions
|
||||
void BMidi::SprayMidiEvent(BMidiEvent *e) const
|
||||
{
|
||||
// TRACE(("Hello"))
|
||||
int32 num_connections = fConnectionList->CountItems();
|
||||
BMidi *m;
|
||||
for(int32 i = 0; i < num_connections; i++)
|
||||
{
|
||||
m = (BMidi *)fConnectionList->ItemAt(i);
|
||||
write_port(m->fInflowPort, MSG_CODE_PROCESS_EVENT, e, sizeof(BMidiEvent));
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayNoteOff(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_NOTE_OFF;
|
||||
event.noteOff.channel = channel;
|
||||
event.noteOff.note = note;
|
||||
event.noteOff.velocity = velocity;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayNoteOn(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_NOTE_ON;
|
||||
event.noteOn.channel = channel;
|
||||
event.noteOn.note = note;
|
||||
event.noteOn.velocity = velocity;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayKeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_KEY_PRESSURE;
|
||||
event.keyPressure.channel = channel;
|
||||
event.keyPressure.note = note;
|
||||
event.keyPressure.pressure = pressure;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue,
|
||||
uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_CONTROL_CHANGE;
|
||||
event.controlChange.channel = channel;
|
||||
event.controlChange.controlNumber = controlNumber;
|
||||
event.controlChange.controlValue = controlValue;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayProgramChange(
|
||||
uchar channel, uchar programNumber, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_PROGRAM_CHANGE;
|
||||
event.programChange.channel = channel;
|
||||
event.programChange.programNumber = programNumber;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayChannelPressure(
|
||||
uchar channel, uchar pressure, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_CHANNEL_PRESSURE;
|
||||
event.channelPressure.channel = channel;
|
||||
event.channelPressure.pressure = pressure;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayPitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_PITCH_BEND;
|
||||
event.pitchBend.channel = channel;
|
||||
event.pitchBend.lsb = lsb;
|
||||
event.pitchBend.msb = msb;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SpraySystemExclusive(
|
||||
void * data, size_t dataLength, uint32 time) const
|
||||
{
|
||||
// Should this data be duplicated!!?? I think Yes.
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_SYSTEM_EXCLUSIVE;
|
||||
event.systemExclusive.data = new uint8[dataLength];
|
||||
memcpy(event.systemExclusive.data, data, dataLength);
|
||||
event.systemExclusive.dataLength = dataLength;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SpraySystemCommon(
|
||||
uchar status, uchar data1, uchar data2, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_SYSTEM_COMMON;
|
||||
event.systemCommon.status = status;
|
||||
event.systemCommon.data1 = data1;
|
||||
event.systemCommon.data2 = data2;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SpraySystemRealTime(uchar status, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_SYSTEM_REAL_TIME;
|
||||
event.systemRealTime.status = status;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//----------------------
|
||||
|
||||
void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
|
||||
{
|
||||
BMidiEvent event;
|
||||
event.time = time;
|
||||
event.opcode = BMidiEvent::OP_TEMPO_CHANGE;
|
||||
event.tempoChange.beatsPerMinute = beatsPerMinute;
|
||||
SprayMidiEvent(&event);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// The Inflow Thread
|
||||
void BMidi::InflowTask()
|
||||
{
|
||||
BMidiEvent event;
|
||||
int32 code;
|
||||
size_t len;
|
||||
while(true)
|
||||
{
|
||||
len = read_port(fInflowPort, &code, &event, sizeof(BMidiEvent));
|
||||
|
||||
if (code == MSG_CODE_TERMINATE_THREAD) { return; }
|
||||
|
||||
if (len != sizeof(BMidiEvent)) { continue; } //ignore errors
|
||||
|
||||
switch (event.opcode)
|
||||
if (!justChannel)
|
||||
{
|
||||
case BMidiEvent::OP_NONE:
|
||||
case BMidiEvent::OP_TRACK_END:
|
||||
case BMidiEvent::OP_ALL_NOTES_OFF:
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_NOTE_OFF:
|
||||
NoteOff(
|
||||
event.noteOff.channel,
|
||||
event.noteOff.note,
|
||||
event.noteOff.velocity,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_NOTE_ON:
|
||||
NoteOn(
|
||||
event.noteOn.channel,
|
||||
event.noteOn.note,
|
||||
event.noteOn.velocity,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_KEY_PRESSURE:
|
||||
KeyPressure(
|
||||
event.keyPressure.channel,
|
||||
event.keyPressure.note,
|
||||
event.keyPressure.pressure,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_CONTROL_CHANGE:
|
||||
ControlChange(
|
||||
event.controlChange.channel,
|
||||
event.controlChange.controlNumber,
|
||||
event.controlChange.controlValue,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_PROGRAM_CHANGE:
|
||||
ProgramChange(
|
||||
event.programChange.channel,
|
||||
event.programChange.programNumber,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_CHANNEL_PRESSURE:
|
||||
ChannelPressure(
|
||||
event.channelPressure.channel,
|
||||
event.channelPressure.pressure,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_PITCH_BEND:
|
||||
PitchBend(
|
||||
event.pitchBend.channel,
|
||||
event.pitchBend.lsb,
|
||||
event.pitchBend.msb,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_SYSTEM_EXCLUSIVE:
|
||||
SystemExclusive(
|
||||
event.systemExclusive.data,
|
||||
event.systemExclusive.dataLength,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_SYSTEM_COMMON:
|
||||
SystemCommon(
|
||||
event.systemCommon.status,
|
||||
event.systemCommon.data1,
|
||||
event.systemCommon.data2,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_SYSTEM_REAL_TIME:
|
||||
SystemRealTime(
|
||||
event.systemRealTime.status,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
case BMidiEvent::OP_TEMPO_CHANGE:
|
||||
TempoChange(
|
||||
event.tempoChange.beatsPerMinute,
|
||||
event.time);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
for (uchar note = 0; note <= 0x7F; ++note)
|
||||
{
|
||||
SprayNoteOff(channel, note, 0, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//----------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BMidi::Start()
|
||||
{
|
||||
if (isRunning) { return B_OK; }
|
||||
|
||||
status_t err = spawn_thread(
|
||||
_run_thread, "MidiRunThread", B_URGENT_PRIORITY, this);
|
||||
|
||||
if (err < B_OK) { return err; }
|
||||
|
||||
threadId = err;
|
||||
isRunning = true;
|
||||
|
||||
err = resume_thread(threadId);
|
||||
if (err != B_OK)
|
||||
{
|
||||
threadId = -1;
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::Stop()
|
||||
{
|
||||
threadId = -1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool BMidi::IsRunning() const
|
||||
{
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::Connect(BMidi* toObject)
|
||||
{
|
||||
if (toObject != NULL)
|
||||
{
|
||||
if (producer->Connect(toObject->consumer) == B_OK)
|
||||
{
|
||||
connections->AddItem(toObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::Disconnect(BMidi* fromObject)
|
||||
{
|
||||
if (fromObject != NULL)
|
||||
{
|
||||
if (producer->Disconnect(fromObject->consumer) == B_OK)
|
||||
{
|
||||
connections->RemoveItem(fromObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool BMidi::IsConnected(BMidi* toObject) const
|
||||
{
|
||||
if (toObject != NULL)
|
||||
{
|
||||
return producer->IsConnected(toObject->consumer);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BList* BMidi::Connections() const
|
||||
{
|
||||
return connections;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SnoozeUntil(uint32 time) const
|
||||
{
|
||||
snooze_until(MAKE_BIGTIME(time), B_SYSTEM_TIMEBASE);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool BMidi::KeepRunning()
|
||||
{
|
||||
return (threadId != -1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::_ReservedMidi1() {}
|
||||
void BMidi::_ReservedMidi2() {}
|
||||
void BMidi::_ReservedMidi3() {}
|
||||
|
||||
//----------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t _run_thread_(void *data)
|
||||
void BMidi::Run()
|
||||
{
|
||||
((BMidi*)data)->Run();
|
||||
return 0;
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//----------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t _inflow_task_(void * data)
|
||||
void BMidi::SprayNoteOff(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||
{
|
||||
((BMidi*)data)->InflowTask();
|
||||
return 0;
|
||||
producer->SprayNoteOff(
|
||||
channel - 1, note, velocity, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//-----------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayNoteOn(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||
{
|
||||
producer->SprayNoteOn(
|
||||
channel - 1, note, velocity, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayKeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, uint32 time) const
|
||||
{
|
||||
producer->SprayKeyPressure(
|
||||
channel - 1, note, pressure, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue,
|
||||
uint32 time) const
|
||||
{
|
||||
producer->SprayControlChange(
|
||||
channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayProgramChange(
|
||||
uchar channel, uchar programNumber, uint32 time) const
|
||||
{
|
||||
producer->SprayProgramChange(
|
||||
channel - 1, programNumber, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayChannelPressure(
|
||||
uchar channel, uchar pressure, uint32 time) const
|
||||
{
|
||||
producer->SprayChannelPressure(
|
||||
channel - 1, pressure, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayPitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, uint32 time) const
|
||||
{
|
||||
producer->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SpraySystemExclusive(
|
||||
void* data, size_t length, uint32 time) const
|
||||
{
|
||||
producer->SpraySystemExclusive(data, length, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SpraySystemCommon(
|
||||
uchar status, uchar data1, uchar data2, uint32 time) const
|
||||
{
|
||||
producer->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SpraySystemRealTime(uchar status, uint32 time) const
|
||||
{
|
||||
producer->SpraySystemRealTime(status, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
|
||||
{
|
||||
producer->SprayTempoChange(beatsPerMinute, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* @file MidiEvent.cpp
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* @author Paul Stadler
|
||||
*/
|
||||
|
||||
#include "MidiEvent.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidiEvent::BMidiEvent()
|
||||
{
|
||||
opcode = OP_NONE;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidiEvent::~BMidiEvent()
|
||||
{
|
||||
if (opcode == OP_SYSTEM_EXCLUSIVE)
|
||||
delete systemExclusive.data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/**
|
||||
* @file MidiEvent.h
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* @author Paul Stadler
|
||||
*/
|
||||
|
||||
#ifndef _MIDI_EVENT_H
|
||||
#define _MIDI_EVENT_H
|
||||
|
||||
#include "MidiDefs.h"
|
||||
|
||||
/**
|
||||
* Describes a MIDI message and its attributes.
|
||||
*/
|
||||
class BMidiEvent
|
||||
{
|
||||
public:
|
||||
BMidiEvent();
|
||||
~BMidiEvent();
|
||||
|
||||
enum
|
||||
{
|
||||
OP_NONE,
|
||||
OP_NOTE_OFF,
|
||||
OP_NOTE_ON,
|
||||
OP_KEY_PRESSURE,
|
||||
OP_CONTROL_CHANGE,
|
||||
OP_PROGRAM_CHANGE,
|
||||
OP_CHANNEL_PRESSURE,
|
||||
OP_PITCH_BEND,
|
||||
OP_SYSTEM_EXCLUSIVE,
|
||||
OP_SYSTEM_COMMON,
|
||||
OP_SYSTEM_REAL_TIME,
|
||||
OP_TEMPO_CHANGE,
|
||||
OP_ALL_NOTES_OFF,
|
||||
OP_TRACK_END,
|
||||
}
|
||||
opcode;
|
||||
|
||||
uint32 time;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar note;
|
||||
uchar velocity;
|
||||
}
|
||||
noteOff;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar note;
|
||||
uchar velocity;
|
||||
}
|
||||
noteOn;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar note;
|
||||
uchar pressure;
|
||||
}
|
||||
keyPressure;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar controlNumber;
|
||||
uchar controlValue;
|
||||
}
|
||||
controlChange;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar programNumber;
|
||||
}
|
||||
programChange;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar pressure;
|
||||
}
|
||||
channelPressure;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar channel;
|
||||
uchar lsb;
|
||||
uchar msb;
|
||||
}
|
||||
pitchBend;
|
||||
|
||||
struct
|
||||
{
|
||||
uint8* data;
|
||||
size_t dataLength;
|
||||
}
|
||||
systemExclusive;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar status;
|
||||
uchar data1;
|
||||
uchar data2;
|
||||
}
|
||||
systemCommon;
|
||||
|
||||
struct
|
||||
{
|
||||
uchar status;
|
||||
}
|
||||
systemRealTime;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32 beatsPerMinute;
|
||||
}
|
||||
tempoChange;
|
||||
|
||||
struct
|
||||
{
|
||||
bool justChannel;
|
||||
}
|
||||
allNotesOff;
|
||||
};
|
||||
};
|
||||
|
||||
#endif _MIDI_EVENT_H
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Matthijs Hollemans
|
||||
* Copyright (c) 2002 Jerome Leveque
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "Midi.h"
|
||||
#include "MidiGlue.h"
|
||||
#include "MidiPort.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidiGlue::BMidiGlue(BMidi* midiObject_, const char* name)
|
||||
: BMidiLocalConsumer(name)
|
||||
{
|
||||
midiObject = midiObject_;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
midiObject->NoteOff(channel + 1, note, velocity, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
midiObject->NoteOn(channel + 1, note, velocity, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, bigtime_t time)
|
||||
{
|
||||
midiObject->KeyPressure(channel + 1, note, pressure, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
|
||||
{
|
||||
midiObject->ControlChange(
|
||||
channel + 1, controlNumber, controlValue, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::ProgramChange(
|
||||
uchar channel, uchar programNumber, bigtime_t time)
|
||||
{
|
||||
midiObject->ProgramChange(channel + 1, programNumber, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::ChannelPressure(
|
||||
uchar channel, uchar pressure, bigtime_t time)
|
||||
{
|
||||
midiObject->ChannelPressure(channel + 1, pressure, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::PitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, bigtime_t time)
|
||||
{
|
||||
midiObject->PitchBend(channel + 1, lsb, msb, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::SystemExclusive(
|
||||
void* data, size_t length, bigtime_t time)
|
||||
{
|
||||
midiObject->SystemExclusive(data, length, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, bigtime_t time)
|
||||
{
|
||||
midiObject->SystemCommon(status, data1, data2, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::SystemRealTime(uchar status, bigtime_t time)
|
||||
{
|
||||
midiObject->SystemRealTime(status, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiGlue::TempoChange(int32 beatsPerMinute, bigtime_t time)
|
||||
{
|
||||
midiObject->TempoChange(beatsPerMinute, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidiPortGlue::BMidiPortGlue(BMidiPort* midiObject_, const char* name)
|
||||
: BMidiLocalConsumer(name)
|
||||
{
|
||||
midiObject = midiObject_;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayNoteOff(channel + 1, note, velocity, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayNoteOn(channel + 1, note, velocity, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayKeyPressure(
|
||||
channel + 1, note, pressure, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayControlChange(
|
||||
channel + 1, controlNumber, controlValue, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::ProgramChange(
|
||||
uchar channel, uchar programNumber, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayProgramChange(
|
||||
channel + 1, programNumber, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::ChannelPressure(
|
||||
uchar channel, uchar pressure, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayChannelPressure(channel + 1, pressure, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::PitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayPitchBend(channel + 1, lsb, msb, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::SystemExclusive(
|
||||
void* data, size_t length, bigtime_t time)
|
||||
{
|
||||
midiObject->SpraySystemExclusive(data, length, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, bigtime_t time)
|
||||
{
|
||||
midiObject->SpraySystemCommon(status, data1, data2, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::SystemRealTime(uchar status, bigtime_t time)
|
||||
{
|
||||
midiObject->SpraySystemRealTime(status, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPortGlue::TempoChange(int32 beatsPerMinute, bigtime_t time)
|
||||
{
|
||||
midiObject->SprayTempoChange(beatsPerMinute, MAKE_TIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Matthijs Hollemans
|
||||
* Copyright (c) 2002 Jerome Leveque
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _MIDI_GLUE_H
|
||||
#define _MIDI_GLUE_H
|
||||
|
||||
#include <MidiConsumer.h>
|
||||
|
||||
#define MAKE_TIME(t) (t / (bigtime_t)1000)
|
||||
#define MAKE_BIGTIME(t) (t * (bigtime_t)1000)
|
||||
|
||||
class BMidiGlue: public BMidiLocalConsumer
|
||||
{
|
||||
public:
|
||||
|
||||
BMidiGlue(BMidi* midiObject, const char* name = NULL);
|
||||
|
||||
virtual void NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
|
||||
virtual void NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
|
||||
virtual void KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, bigtime_t time);
|
||||
|
||||
virtual void ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue,
|
||||
bigtime_t time);
|
||||
|
||||
virtual void ProgramChange(
|
||||
uchar channel, uchar programNumber, bigtime_t time);
|
||||
|
||||
virtual void ChannelPressure(
|
||||
uchar channel, uchar pressure, bigtime_t time);
|
||||
|
||||
virtual void PitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, bigtime_t time);
|
||||
|
||||
virtual void SystemExclusive(
|
||||
void* data, size_t length, bigtime_t time);
|
||||
|
||||
virtual void SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, bigtime_t time);
|
||||
|
||||
virtual void SystemRealTime(uchar status, bigtime_t time);
|
||||
|
||||
virtual void TempoChange(int32 beatsPerMinute, bigtime_t time);
|
||||
|
||||
private:
|
||||
|
||||
BMidi* midiObject;
|
||||
};
|
||||
|
||||
class BMidiPortGlue: public BMidiLocalConsumer
|
||||
{
|
||||
public:
|
||||
|
||||
BMidiPortGlue(BMidiPort* midiObject, const char* name = NULL);
|
||||
|
||||
virtual void NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
|
||||
virtual void NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
|
||||
virtual void KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, bigtime_t time);
|
||||
|
||||
virtual void ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue,
|
||||
bigtime_t time);
|
||||
|
||||
virtual void ProgramChange(
|
||||
uchar channel, uchar programNumber, bigtime_t time);
|
||||
|
||||
virtual void ChannelPressure(
|
||||
uchar channel, uchar pressure, bigtime_t time);
|
||||
|
||||
virtual void PitchBend(
|
||||
uchar channel, uchar lsb, uchar msb, bigtime_t time);
|
||||
|
||||
virtual void SystemExclusive(
|
||||
void* data, size_t length, bigtime_t time);
|
||||
|
||||
virtual void SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, bigtime_t time);
|
||||
|
||||
virtual void SystemRealTime(uchar status, bigtime_t time);
|
||||
|
||||
virtual void TempoChange(int32 beatsPerMinute, bigtime_t time);
|
||||
|
||||
private:
|
||||
|
||||
BMidiPort* midiObject;
|
||||
};
|
||||
|
||||
#endif // _MIDI_GLUE_H
|
||||
+177
-127
@@ -1,43 +1,54 @@
|
||||
/**
|
||||
* @file MidiPort.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
* Copyright (c) 2002 Jerome Leveque
|
||||
*
|
||||
* @author Jerome Leveque
|
||||
* @author Matthijs Hollemans
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <MidiProducer.h>
|
||||
#include <MidiRoster.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "MidiPort.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "MidiPortConsumer.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <MidiRoster.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <MidiProducer.h>
|
||||
#include "MidiGlue.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
BMidiPort::BMidiPort(const char* name)
|
||||
: BMidi(),
|
||||
remote_source(NULL),
|
||||
remote_sink(NULL),
|
||||
fName(NULL),
|
||||
fCStatus(B_ERROR),
|
||||
_fDevices(new BList)
|
||||
{
|
||||
local_source = new BMidiLocalProducer("MidiPortGlue(out)");
|
||||
if (local_source != NULL)
|
||||
local_source->Register();
|
||||
local_sink = new BMidiPortConsumer(this, "MidiPortGlue(in)");
|
||||
if (local_sink != NULL)
|
||||
local_sink->Register();
|
||||
portName = NULL;
|
||||
devices = new BList;
|
||||
status = B_ERROR;
|
||||
|
||||
localSource = new BMidiLocalProducer("MidiPortGlue(out)");
|
||||
localSink = new BMidiPortGlue(this, "MidiPortGlue(in)");
|
||||
|
||||
remoteSource = NULL;
|
||||
remoteSink = NULL;
|
||||
|
||||
ScanDevices();
|
||||
Open(name);
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
Open(name);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -45,86 +56,92 @@ BMidiPort::BMidiPort(const char* name)
|
||||
BMidiPort::~BMidiPort()
|
||||
{
|
||||
Close();
|
||||
delete fName;
|
||||
delete _fDevices;
|
||||
if (local_source)
|
||||
local_source->Release();
|
||||
if (local_sink)
|
||||
local_sink->Release();
|
||||
|
||||
EmptyDeviceList();
|
||||
delete devices;
|
||||
|
||||
localSource->Release();
|
||||
localSink->Release();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BMidiPort::InitCheck() const
|
||||
{
|
||||
return fCStatus;
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BMidiPort::Open(const char* name)
|
||||
{
|
||||
if (name == NULL)
|
||||
return fCStatus = B_ERROR;
|
||||
status = B_ERROR;
|
||||
|
||||
Close();
|
||||
|
||||
int32 id = 0;
|
||||
BMidiRoster *roster = BMidiRoster::MidiRoster();
|
||||
if (roster == NULL)
|
||||
return fCStatus = B_ERROR;
|
||||
BMidiEndpoint *endpt = NULL;
|
||||
while ((endpt = roster->NextEndpoint(&id)) != NULL)
|
||||
if (name != NULL)
|
||||
{
|
||||
if (strcmp(endpt->Name(), name) == 0)
|
||||
{//An endpoint have the same name as we want
|
||||
delete fName;
|
||||
fName = new char[strlen(name)];
|
||||
if (fName != NULL)
|
||||
strcpy(fName, name);
|
||||
//Can an Endpoint be Consumer AND Producer?
|
||||
if (endpt->IsProducer())
|
||||
Close();
|
||||
|
||||
for (int32 t = 0; t < devices->CountItems(); ++t)
|
||||
{
|
||||
BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(t);
|
||||
if (strcmp(name, endp->Name()) == 0)
|
||||
{
|
||||
remote_source = (BMidiProducer*)endpt;
|
||||
// endpt->Acquire(); //Because we always call Release()
|
||||
}
|
||||
if (endpt->IsConsumer())
|
||||
{
|
||||
remote_sink = (BMidiConsumer*)endpt;
|
||||
// endpt->Acquire();//Because we always call Release()
|
||||
if (local_source != NULL)
|
||||
local_source->Connect(remote_sink);
|
||||
if (endp->IsValid()) // still exists?
|
||||
{
|
||||
if (endp->IsProducer())
|
||||
{
|
||||
if (remoteSource == NULL)
|
||||
{
|
||||
remoteSource = (BMidiProducer*) endp;
|
||||
}
|
||||
}
|
||||
else if (endp->IsConsumer())
|
||||
{
|
||||
if (remoteSink == NULL)
|
||||
{
|
||||
remoteSink = (BMidiConsumer*) endp;
|
||||
localSource->Connect(remoteSink);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (remoteSource != NULL)
|
||||
{
|
||||
endpt->Release();
|
||||
portName = strdup(remoteSource->Name());
|
||||
status = B_OK;
|
||||
}
|
||||
else if (remoteSink != NULL)
|
||||
{
|
||||
portName = strdup(remoteSink->Name());
|
||||
status = B_OK;
|
||||
}
|
||||
}
|
||||
return fCStatus = B_OK;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::Close()
|
||||
{
|
||||
if (remote_source != NULL)
|
||||
if (remoteSource != NULL)
|
||||
{
|
||||
if (local_sink != NULL)
|
||||
{
|
||||
remote_source->Disconnect(local_sink);
|
||||
}
|
||||
remote_source->Release();
|
||||
remote_source = NULL;
|
||||
remoteSource->Disconnect(localSink);
|
||||
remoteSource = NULL;
|
||||
}
|
||||
if (remote_sink != NULL)
|
||||
|
||||
if (remoteSink != NULL)
|
||||
{
|
||||
if (local_source != NULL)
|
||||
{
|
||||
local_source->Disconnect(remote_sink);
|
||||
}
|
||||
remote_sink->Release();
|
||||
remote_sink = NULL;
|
||||
localSource->Disconnect(remoteSink);
|
||||
remoteSink = NULL;
|
||||
}
|
||||
|
||||
if (portName != NULL)
|
||||
{
|
||||
free(portName);
|
||||
portName = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +149,7 @@ void BMidiPort::Close()
|
||||
|
||||
const char* BMidiPort::PortName() const
|
||||
{
|
||||
return fName;
|
||||
return portName;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -140,7 +157,7 @@ return fName;
|
||||
void BMidiPort::NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
local_source->SprayNoteOff(channel, note, velocity, time);
|
||||
localSource->SprayNoteOff(channel - 1, note, velocity, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -148,7 +165,7 @@ void BMidiPort::NoteOff(
|
||||
void BMidiPort::NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
local_source->SprayNoteOn(channel, note, velocity, time);
|
||||
localSource->SprayNoteOn(channel - 1, note, velocity, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -156,7 +173,8 @@ void BMidiPort::NoteOn(
|
||||
void BMidiPort::KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, uint32 time)
|
||||
{
|
||||
local_source->SprayKeyPressure(channel, note, pressure, 0);
|
||||
localSource->SprayKeyPressure(
|
||||
channel - 1, note, pressure, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -164,7 +182,8 @@ void BMidiPort::KeyPressure(
|
||||
void BMidiPort::ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
|
||||
{
|
||||
local_source->SprayControlChange(channel, controlNumber, controlValue, 0);
|
||||
localSource->SprayControlChange(
|
||||
channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -172,28 +191,30 @@ void BMidiPort::ControlChange(
|
||||
void BMidiPort::ProgramChange(
|
||||
uchar channel, uchar programNumber, uint32 time)
|
||||
{
|
||||
local_source->SprayProgramChange(channel, programNumber, 0);
|
||||
localSource->SprayProgramChange(
|
||||
channel - 1, programNumber, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
||||
{
|
||||
local_source->SprayChannelPressure(channel, pressure, 0);
|
||||
localSource->SprayChannelPressure(
|
||||
channel - 1, pressure, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
|
||||
{
|
||||
local_source->SprayPitchBend(channel, lsb, msb, 0);
|
||||
localSource->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time)
|
||||
void BMidiPort::SystemExclusive(void* data, size_t length, uint32 time)
|
||||
{
|
||||
local_source->SpraySystemExclusive(data, dataLength, 0);
|
||||
localSource->SpraySystemExclusive(data, length, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -201,63 +222,67 @@ void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time)
|
||||
void BMidiPort::SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, uint32 time)
|
||||
{
|
||||
local_source->SpraySystemCommon(status, data1, data2, 0);
|
||||
localSource->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::SystemRealTime(uchar status, uint32 time)
|
||||
{
|
||||
local_source->SpraySystemRealTime(status, 0);
|
||||
localSource->SpraySystemRealTime(status, MAKE_BIGTIME(time));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BMidiPort::Start()
|
||||
{
|
||||
if ((local_sink != NULL) && (remote_source != NULL))
|
||||
if ((fCStatus = remote_source->Connect(local_sink)) != B_OK)
|
||||
return fCStatus;
|
||||
else
|
||||
{
|
||||
return BMidi::Start();
|
||||
}
|
||||
else
|
||||
return fCStatus = B_ERROR;
|
||||
status_t err = super::Start();
|
||||
|
||||
if ((err == B_OK) && (remoteSource != NULL))
|
||||
{
|
||||
return remoteSource->Connect(localSink);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::Stop()
|
||||
{
|
||||
if ((remote_source != NULL) && (local_sink != NULL))
|
||||
if (remoteSource != NULL)
|
||||
{
|
||||
remote_source->Disconnect(local_sink);
|
||||
remoteSource->Disconnect(localSink);
|
||||
}
|
||||
BMidi::Stop();
|
||||
|
||||
super::Stop();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int32 BMidiPort::CountDevices()
|
||||
{
|
||||
return _fDevices->CountItems();
|
||||
return devices->CountItems();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize)
|
||||
{
|
||||
BMidiEndpoint *endpt = (BMidiEndpoint*)_fDevices->ItemAt(n);
|
||||
if (endpt == NULL)
|
||||
BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(n);
|
||||
if (endp == NULL)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
size_t size = strlen(endpt->Name());
|
||||
if (size > bufSize)
|
||||
}
|
||||
|
||||
size_t size = strlen(endp->Name());
|
||||
if (size >= bufSize)
|
||||
{
|
||||
return B_NAME_TOO_LONG;
|
||||
if (strlen(strcpy(name, endpt->Name())) == size)
|
||||
return B_OK;
|
||||
else
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
strcpy(name, endp->Name());
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -270,33 +295,58 @@ void BMidiPort::_ReservedMidiPort3() { }
|
||||
|
||||
void BMidiPort::Run()
|
||||
{
|
||||
while(KeepRunning())
|
||||
while (KeepRunning())
|
||||
{
|
||||
snooze(50000);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::ScanDevices()
|
||||
{
|
||||
int32 id = 0;
|
||||
BMidiRoster *roster = BMidiRoster::MidiRoster();
|
||||
if (roster == NULL)
|
||||
return;
|
||||
BMidiEndpoint *endpt = NULL;
|
||||
while ((endpt = roster->NextEndpoint(&id)) != NULL)
|
||||
EmptyDeviceList();
|
||||
|
||||
int32 id = 0;
|
||||
BMidiEndpoint* endp;
|
||||
|
||||
while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL)
|
||||
{
|
||||
bool additem = true;
|
||||
for (int32 i = 0; i < _fDevices->CountItems(); i++)
|
||||
// Each hardware port has two endpoints associated with it, a consumer
|
||||
// and a producer. Both have the same name, so we add only one of them.
|
||||
|
||||
bool addItem = true;
|
||||
for (int32 t = 0; t < devices->CountItems(); ++t)
|
||||
{
|
||||
BMidiEndpoint *endpoint = (BMidiEndpoint*)_fDevices->ItemAt(i);
|
||||
if (strcmp(endpt->Name(), endpoint->Name()) == 0)
|
||||
additem = false;
|
||||
BMidiEndpoint* other = (BMidiEndpoint*) devices->ItemAt(t);
|
||||
if (strcmp(endp->Name(), other->Name()) == 0)
|
||||
{
|
||||
addItem = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (addItem)
|
||||
{
|
||||
devices->AddItem(endp);
|
||||
}
|
||||
else
|
||||
{
|
||||
endp->Release();
|
||||
}
|
||||
if (additem)
|
||||
_fDevices->AddItem(endpt);
|
||||
endpt->Release();
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiPort::EmptyDeviceList()
|
||||
{
|
||||
for (int32 t = 0; t < devices->CountItems(); ++t)
|
||||
{
|
||||
((BMidiEndpoint*) devices->ItemAt(t))->Release();
|
||||
}
|
||||
|
||||
devices->MakeEmpty();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/**
|
||||
* @file MidiPort.cpp
|
||||
*
|
||||
* @author Jerome Leveque
|
||||
*/
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
#include "MidiPortConsumer.h"
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
BMidiPortConsumer::BMidiPortConsumer(BMidiPort *toPort, const char *name = NULL)
|
||||
: BMidiLocalConsumer(name), port(toPort)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::NoteOff(uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
port->SprayNoteOff(channel, note, velocity, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::NoteOn(uchar channel, uchar note, uchar velocity, bigtime_t time)
|
||||
{
|
||||
port->SprayNoteOn(channel, note, velocity, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::KeyPressure(uchar channel, uchar note, uchar pressure, bigtime_t time)
|
||||
{
|
||||
port->SprayKeyPressure(channel, note, pressure, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::ControlChange(uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
|
||||
{
|
||||
port->SprayControlChange(channel, controlNumber, controlValue, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::ProgramChange(uchar channel, uchar programNumber, bigtime_t time)
|
||||
{
|
||||
port->SprayProgramChange(channel, programNumber, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::ChannelPressure(uchar channel, uchar pressure, bigtime_t time)
|
||||
{
|
||||
port->SprayChannelPressure(channel, pressure, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::PitchBend(uchar channel, uchar lsb, uchar msb, bigtime_t time)
|
||||
{
|
||||
port->SprayPitchBend(channel, lsb, msb, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::SystemExclusive(void *data, size_t dataLength, bigtime_t time)
|
||||
{
|
||||
port->SpraySystemExclusive(data, dataLength, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::SystemCommon(uchar statusByte, uchar data1, uchar data2, bigtime_t time)
|
||||
{
|
||||
port->SpraySystemCommon(statusByte, data1, data2, B_NOW);
|
||||
}
|
||||
|
||||
//-----------------
|
||||
|
||||
void BMidiPortConsumer::SystemRealTime(uchar statusByte, bigtime_t time)
|
||||
{
|
||||
port->SpraySystemRealTime(statusByte, B_NOW);
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
//----------------------------------------
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file MidiPort.h
|
||||
*
|
||||
* @author Jerome Leveque
|
||||
*/
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
#ifndef _MIDI_PORT_CONSUMER_H
|
||||
#define _MIDI_PORT_CONSUMER_H
|
||||
|
||||
#include <MidiConsumer.h>
|
||||
#include <MidiPort.h>
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
class BMidiPortConsumer : public BMidiLocalConsumer
|
||||
{
|
||||
public:
|
||||
BMidiPortConsumer(BMidiPort *toPort, const char *name = NULL);
|
||||
|
||||
void NoteOff(uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
void NoteOn(uchar channel, uchar note, uchar velocity, bigtime_t time);
|
||||
void KeyPressure(uchar channel, uchar note, uchar pressure, bigtime_t time);
|
||||
void ControlChange(uchar channel, uchar controlNumber,
|
||||
uchar controlValue, bigtime_t time);
|
||||
void ProgramChange(uchar channel, uchar programNumber, bigtime_t time);
|
||||
void ChannelPressure(uchar channel, uchar pressure, bigtime_t time);
|
||||
void PitchBend(uchar channel, uchar lsb, uchar msb, bigtime_t time);
|
||||
void SystemExclusive(void *data, size_t dataLength, bigtime_t time);
|
||||
void SystemCommon(uchar statusByte, uchar data1,
|
||||
uchar data2, bigtime_t time);
|
||||
void SystemRealTime(uchar statusByte, bigtime_t time);
|
||||
|
||||
private:
|
||||
BMidiPort *port;
|
||||
|
||||
};
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
#endif _MIDI_PORT_CONSUMER_H
|
||||
+861
-797
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,23 @@
|
||||
/**
|
||||
* @file MidiSynth.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
@@ -209,4 +225,3 @@ void BMidiSynth::Run()
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
/**
|
||||
* @file MidiSynthFile.h
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
@@ -184,4 +200,3 @@ void BMidiSynthFile::_ReservedMidiSynthFile2() { }
|
||||
void BMidiSynthFile::_ReservedMidiSynthFile3() { }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
+56
-54
@@ -1,15 +1,30 @@
|
||||
/**
|
||||
* @file MidiText.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
* Copyright (c) 2002 Jerome Leveque
|
||||
* Copyright (c) 2002 Paul Stadler
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* @author Jerome Leveque
|
||||
* @author Paul Stadler
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "MidiEvent.h"
|
||||
#include "MidiText.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -23,7 +38,7 @@ BMidiText::BMidiText()
|
||||
|
||||
BMidiText::~BMidiText()
|
||||
{
|
||||
// Do nothing
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -32,9 +47,9 @@ void BMidiText::NoteOff(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": NOTE OFF; channel = " << (int) channel
|
||||
<< ", note = " << (int) note
|
||||
<< ", velocity = " << (int) velocity << endl;
|
||||
printf(
|
||||
"B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
|
||||
channel, note, velocity);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -43,9 +58,9 @@ void BMidiText::NoteOn(
|
||||
uchar channel, uchar note, uchar velocity, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": NOTE ON; channel = " << (int) channel
|
||||
<< ", note = " << (int) note
|
||||
<< ", velocity = " << (int) velocity << endl;
|
||||
printf(
|
||||
"B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
|
||||
channel, note, velocity);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -54,9 +69,9 @@ void BMidiText::KeyPressure(
|
||||
uchar channel, uchar note, uchar pressure, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": KEY PRESSURE; channel = " << (int) channel
|
||||
<< ", note = " << (int) note
|
||||
<< ", pressure = " << (int) pressure << endl;
|
||||
printf(
|
||||
"KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
|
||||
channel, note, pressure);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -65,9 +80,9 @@ void BMidiText::ControlChange(
|
||||
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": CONTROL CHANGE; channel = " << (int) channel
|
||||
<< ", control = " << (int) controlNumber
|
||||
<< ", value = "<< (int) controlValue << endl;
|
||||
printf(
|
||||
"CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
|
||||
channel, controlNumber, controlValue);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -76,8 +91,9 @@ void BMidiText::ProgramChange(
|
||||
uchar channel, uchar programNumber, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": PROGRAM CHANGE; channel = " << (int) channel
|
||||
<< ", program = " << (int) programNumber << endl;
|
||||
printf(
|
||||
"PROGRAM CHANGE; channel = %d, program = %d\n",
|
||||
channel, programNumber);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -85,8 +101,9 @@ void BMidiText::ProgramChange(
|
||||
void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": CHANNEL PRESSURE; channel = " << (int) channel
|
||||
<< ", pressure = " << (int) pressure << endl;
|
||||
printf(
|
||||
"CHANNEL PRESSURE; channel = %d, pressure = %d\n",
|
||||
channel, pressure);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -94,23 +111,23 @@ void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
|
||||
void BMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": PITCH BEND; channel = " << (int) channel << hex
|
||||
<< ", lsb = " << (int) lsb
|
||||
<< ", msb = " << (int) msb << endl;
|
||||
printf(
|
||||
"PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
|
||||
channel, lsb, msb);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiText::SystemExclusive(void* data, size_t dataLength, uint32 time)
|
||||
void BMidiText::SystemExclusive(void* data, size_t length, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
|
||||
cout << ": SYSTEM EXCLUSIVE;";
|
||||
for (size_t i = 0; i < dataLength; i++)
|
||||
printf("SYSTEM EXCLUSIVE;\n");
|
||||
for (size_t t = 0; t < length; ++t)
|
||||
{
|
||||
cout << " " << hex << (int) ((uint8*) data)[i];
|
||||
printf("%02X ", ((uint8*) data)[t]);
|
||||
}
|
||||
cout << endl;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -119,9 +136,9 @@ void BMidiText::SystemCommon(
|
||||
uchar status, uchar data1, uchar data2, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": SYSTEM COMMON; status = " << hex << (int) status
|
||||
<< ", data1 = " << (int) data1
|
||||
<< ", data2 = " << (int) data2 << endl;
|
||||
printf(
|
||||
"SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
|
||||
status, data1, data2);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -129,23 +146,7 @@ void BMidiText::SystemCommon(
|
||||
void BMidiText::SystemRealTime(uchar status, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": SYSTEM REAL TIME; status = " << hex << (int) status << endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiText::TempoChange(int32 beatsPerMinute, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": TEMPO CHANGE; beatsperminute = " << beatsPerMinute << endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiText::AllNotesOff(bool justChannel, uint32 time)
|
||||
{
|
||||
WaitAndPrint(time);
|
||||
cout << ": ALL NOTES OFF;" << endl;
|
||||
printf("SYSTEM REAL TIME; status = %d\n", status);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -158,6 +159,8 @@ void BMidiText::ResetTimer(bool start)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BMidiText::_ReservedMidiText1() { }
|
||||
void BMidiText::_ReservedMidiText2() { }
|
||||
void BMidiText::_ReservedMidiText3() { }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -177,8 +180,7 @@ void BMidiText::WaitAndPrint(uint32 time)
|
||||
|
||||
SnoozeUntil(time);
|
||||
|
||||
cout << dec << (time - startTime);
|
||||
printf("%u: ", time - startTime);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
/**
|
||||
* @file Samples.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
@@ -128,4 +144,3 @@ void BSamples::_ReservedSamples2() { }
|
||||
void BSamples::_ReservedSamples3() { }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
+19
-27
@@ -1,7 +1,23 @@
|
||||
/**
|
||||
* @file Synth.cpp
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Matthijs Hollemans
|
||||
*
|
||||
* @author Matthijs Hollemans
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
@@ -239,27 +255,3 @@ void BSynth::_ReservedSynth3() { }
|
||||
void BSynth::_ReservedSynth4() { }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void BSynth::_init()
|
||||
{
|
||||
UNIMPLEMENTED
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BSynth::_do_load(synth_mode synth)
|
||||
{
|
||||
UNIMPLEMENTED
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
status_t BSynth::_load_insts(entry_ref* ref)
|
||||
{
|
||||
UNIMPLEMENTED
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user