cleaned up midi1

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2934 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
mahlzeit
2003-03-17 22:30:19 +00:00
parent a06c9b684a
commit 49fa1748f5
15 changed files with 1834 additions and 1740 deletions
+1 -3
View File
@@ -6,19 +6,17 @@ UsePublicHeaders midi ;
SharedLibrary midi : SharedLibrary midi :
Midi.cpp Midi.cpp
MidiGlue.cpp
MidiPort.cpp MidiPort.cpp
MidiPortConsumer.cpp
MidiStore.cpp MidiStore.cpp
MidiSynth.cpp MidiSynth.cpp
MidiSynthFile.cpp MidiSynthFile.cpp
MidiText.cpp MidiText.cpp
MidiEvent.cpp
Samples.cpp Samples.cpp
Synth.cpp Synth.cpp
; ;
LinkSharedOSLibs libmidi.so : LinkSharedOSLibs libmidi.so :
be be
stdc++.r4
midi2 midi2
; ;
+297 -392
View File
@@ -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
* *
* @author Matthijs Hollemans * Permission is hereby granted, free of charge, to any person obtaining a
* @author Jerome Leveque * copy of this software and associated documentation files (the "Software"),
* @author Paul Stadler * 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 <List.h> #include <List.h>
#include <MidiProducer.h>
#include "Midi.h" #include "Midi.h"
#include "MidiGlue.h"
#include "debug.h" #include "debug.h"
#include "MidiEvent.h"
//----------------------------------------------- //------------------------------------------------------------------------------
#define MSG_CODE_PROCESS_EVENT 1 status_t _run_thread(void* data)
#define MSG_CODE_TERMINATE_THREAD 0 {
BMidi* midi = (BMidi*) data;
midi->Run();
midi->isRunning = false;
return 0;
}
//----------------------------------------------- //------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Initialization Stuff
BMidi::BMidi() BMidi::BMidi()
{ {
fConnectionList = new BList(); connections = new BList;
fIsRunning = false; threadId = -1;
isRunning = false;
fInflowPort = create_port(1, "Inflow Port"); producer = new BMidiLocalProducer("MidiGlue(out)");
consumer = new BMidiGlue(this, "MidiGlue(in)");
fInflowTask = spawn_thread(
_inflow_task_, "BMidi Inflow Thread",
B_REAL_TIME_PRIORITY, (void *)this);
fInflowAlive = resume_thread(fInflowTask) == B_OK;
} }
//------------------------------------------------------------------------------
BMidi::~BMidi() BMidi::~BMidi()
{ {
write_port(fInflowPort, MSG_CODE_TERMINATE_THREAD, NULL, 0); Stop();
status_t exit_value; status_t result;
wait_for_thread(fInflowTask, &exit_value); wait_for_thread(threadId, &result);
delete_port(fInflowPort); producer->Release();
delete fConnectionList; consumer->Release();
delete connections;
} }
//----------------------------------------------------------------------------- //------------------------------------------------------------------------------
// Stubs for midi event hooks.
void BMidi::NoteOff(uchar chan, uchar note, uchar vel, uint32 time) void BMidi::NoteOff(uchar channel, uchar note, uchar velocity, 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)
{ {
// do nothing
} }
//----------------------------------------------------------------------------- //------------------------------------------------------------------------------
// Public API Functions
void BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time)
{
// 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)
{
SprayControlChange(channel, B_ALL_NOTES_OFF, 0, time);
if (!justChannel)
{
for (uchar note = 0; note <= 0x7F; ++note)
{
SprayNoteOff(channel, note, 0, time);
}
}
}
}
//------------------------------------------------------------------------------
status_t BMidi::Start() status_t BMidi::Start()
{ {
fRunTask = spawn_thread(_run_thread_, if (isRunning) { return B_OK; }
"BMidi Run Thread", B_REAL_TIME_PRIORITY, (void *)this);
fIsRunning = true; status_t err = spawn_thread(
status_t ret = resume_thread(fRunTask); _run_thread, "MidiRunThread", B_URGENT_PRIORITY, this);
if(ret != B_OK)
if (err < B_OK) { return err; }
threadId = err;
isRunning = true;
err = resume_thread(threadId);
if (err != B_OK)
{ {
fIsRunning = false; threadId = -1;
isRunning = false;
} }
return B_OK;
return err;
} }
//----------------------------------------------------------------------------- //------------------------------------------------------------------------------
void BMidi::Stop() void BMidi::Stop()
{ {
status_t exit_value; threadId = -1;
status_t ret;
fIsRunning = false;
ret = wait_for_thread(fRunTask, &exit_value);
} }
//------------------------------------------------------------------------------
bool BMidi::IsRunning() const bool BMidi::IsRunning() const
{ {
thread_info info; return isRunning;
get_thread_info(fRunTask,&info);
if(find_thread("BMidi Run Thread") == fRunTask)
return true;
return false;
} }
void BMidi::Connect(BMidi *to_object) //------------------------------------------------------------------------------
void BMidi::Connect(BMidi* toObject)
{ {
fConnectionList->AddItem((void *)to_object); if (toObject != NULL)
{
if (producer->Connect(toObject->consumer) == B_OK)
{
connections->AddItem(toObject);
}
}
} }
void BMidi::Disconnect(BMidi *from_object) //------------------------------------------------------------------------------
void BMidi::Disconnect(BMidi* fromObject)
{ {
fConnectionList->RemoveItem((void *)from_object); if (fromObject != NULL)
{
if (producer->Disconnect(fromObject->consumer) == B_OK)
{
connections->RemoveItem(fromObject);
}
}
} }
bool BMidi::IsConnected(BMidi * to_object) const //------------------------------------------------------------------------------
bool BMidi::IsConnected(BMidi* toObject) const
{ {
return fConnectionList->HasItem((void *)to_object); if (toObject != NULL)
{
return producer->IsConnected(toObject->consumer);
}
return false;
} }
BList * BMidi::Connections() const //------------------------------------------------------------------------------
BList* BMidi::Connections() const
{ {
return fConnectionList; return connections;
} }
//------------------------------------------------------------------------------
void BMidi::SnoozeUntil(uint32 time) const void BMidi::SnoozeUntil(uint32 time) const
{ {
snooze_until((uint64)time*1000, B_SYSTEM_TIMEBASE); snooze_until(MAKE_BIGTIME(time), B_SYSTEM_TIMEBASE);
} }
//------------------------------------------------------------------------------
bool BMidi::KeepRunning() bool BMidi::KeepRunning()
{ {
return fIsRunning; return (threadId != -1);
} }
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)
{
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;
}
}
}
//----------------------
//----------------------
//----------------------
//----------------------
//----------------------
//----------------------
//----------------------
//----------------------
void BMidi::_ReservedMidi1() {} void BMidi::_ReservedMidi1() {}
void BMidi::_ReservedMidi2() {} void BMidi::_ReservedMidi2() {}
void BMidi::_ReservedMidi3() {} void BMidi::_ReservedMidi3() {}
//---------------------- //------------------------------------------------------------------------------
status_t _run_thread_(void *data) void BMidi::Run()
{ {
((BMidi*)data)->Run(); // do nothing
return 0;
} }
//---------------------- //------------------------------------------------------------------------------
status_t _inflow_task_(void * data) void BMidi::SprayNoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) const
{ {
((BMidi*)data)->InflowTask(); producer->SprayNoteOff(
return 0; 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));
}
//------------------------------------------------------------------------------
-26
View File
@@ -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;
}
//------------------------------------------------------------------------------
-135
View File
@@ -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
+220
View File
@@ -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));
}
//------------------------------------------------------------------------------
+118
View File
@@ -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
+171 -121
View File
@@ -1,43 +1,54 @@
/** /*
* @file MidiPort.cpp * Copyright (c) 2002-2003 Matthijs Hollemans
* Copyright (c) 2002 Jerome Leveque
* *
* @author Jerome Leveque * Permission is hereby granted, free of charge, to any person obtaining a
* @author Matthijs Hollemans * 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 "debug.h"
#include "MidiPort.h" #include "MidiPort.h"
#include "MidiGlue.h"
//------------------------------------------------------------------------------
#include "MidiPortConsumer.h"
//------------------------------------------------------------------------------
#include <MidiRoster.h>
#include <string.h>
#include <MidiProducer.h>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BMidiPort::BMidiPort(const char* name) 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)"); portName = NULL;
if (local_source != NULL) devices = new BList;
local_source->Register(); status = B_ERROR;
local_sink = new BMidiPortConsumer(this, "MidiPortGlue(in)");
if (local_sink != NULL) localSource = new BMidiLocalProducer("MidiPortGlue(out)");
local_sink->Register(); localSink = new BMidiPortGlue(this, "MidiPortGlue(in)");
remoteSource = NULL;
remoteSink = NULL;
ScanDevices(); ScanDevices();
if (name != NULL)
{
Open(name); Open(name);
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -45,86 +56,92 @@ BMidiPort::BMidiPort(const char* name)
BMidiPort::~BMidiPort() BMidiPort::~BMidiPort()
{ {
Close(); Close();
delete fName;
delete _fDevices; EmptyDeviceList();
if (local_source) delete devices;
local_source->Release();
if (local_sink) localSource->Release();
local_sink->Release(); localSink->Release();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BMidiPort::InitCheck() const status_t BMidiPort::InitCheck() const
{ {
return fCStatus; return status;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BMidiPort::Open(const char* name) status_t BMidiPort::Open(const char* name)
{ {
if (name == NULL) status = B_ERROR;
return fCStatus = B_ERROR;
if (name != NULL)
{
Close(); Close();
int32 id = 0; for (int32 t = 0; t < devices->CountItems(); ++t)
BMidiRoster *roster = BMidiRoster::MidiRoster();
if (roster == NULL)
return fCStatus = B_ERROR;
BMidiEndpoint *endpt = NULL;
while ((endpt = roster->NextEndpoint(&id)) != NULL)
{ {
if (strcmp(endpt->Name(), name) == 0) BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(t);
{//An endpoint have the same name as we want if (strcmp(name, endp->Name()) == 0)
delete fName;
fName = new char[strlen(name)];
if (fName != NULL)
strcpy(fName, name);
//Can an Endpoint be Consumer AND Producer?
if (endpt->IsProducer())
{ {
remote_source = (BMidiProducer*)endpt; if (endp->IsValid()) // still exists?
// endpt->Acquire(); //Because we always call Release()
}
if (endpt->IsConsumer())
{ {
remote_sink = (BMidiConsumer*)endpt; if (endp->IsProducer())
// endpt->Acquire();//Because we always call Release()
if (local_source != NULL)
local_source->Connect(remote_sink);
}
}
else
{ {
endpt->Release(); if (remoteSource == NULL)
{
remoteSource = (BMidiProducer*) endp;
} }
} }
return fCStatus = B_OK; else if (endp->IsConsumer())
{
if (remoteSink == NULL)
{
remoteSink = (BMidiConsumer*) endp;
localSource->Connect(remoteSink);
}
}
}
}
}
if (remoteSource != NULL)
{
portName = strdup(remoteSource->Name());
status = B_OK;
}
else if (remoteSink != NULL)
{
portName = strdup(remoteSink->Name());
status = B_OK;
}
}
return status;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BMidiPort::Close() void BMidiPort::Close()
{ {
if (remote_source != NULL) if (remoteSource != NULL)
{ {
if (local_sink != NULL) remoteSource->Disconnect(localSink);
{ remoteSource = NULL;
remote_source->Disconnect(local_sink);
} }
remote_source->Release();
remote_source = NULL; if (remoteSink != NULL)
}
if (remote_sink != NULL)
{ {
if (local_source != NULL) localSource->Disconnect(remoteSink);
{ remoteSink = NULL;
local_source->Disconnect(remote_sink);
} }
remote_sink->Release();
remote_sink = NULL; if (portName != NULL)
{
free(portName);
portName = NULL;
} }
} }
@@ -132,7 +149,7 @@ void BMidiPort::Close()
const char* BMidiPort::PortName() const const char* BMidiPort::PortName() const
{ {
return fName; return portName;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -140,7 +157,7 @@ return fName;
void BMidiPort::NoteOff( void BMidiPort::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) 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( void BMidiPort::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) 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( void BMidiPort::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) 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( void BMidiPort::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) 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( void BMidiPort::ProgramChange(
uchar channel, uchar programNumber, uint32 time) 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) 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) 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( void BMidiPort::SystemCommon(
uchar status, uchar data1, uchar data2, uint32 time) 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) void BMidiPort::SystemRealTime(uchar status, uint32 time)
{ {
local_source->SpraySystemRealTime(status, 0); localSource->SpraySystemRealTime(status, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BMidiPort::Start() status_t BMidiPort::Start()
{ {
if ((local_sink != NULL) && (remote_source != NULL)) status_t err = super::Start();
if ((fCStatus = remote_source->Connect(local_sink)) != B_OK)
return fCStatus; if ((err == B_OK) && (remoteSource != NULL))
else
{ {
return BMidi::Start(); return remoteSource->Connect(localSink);
} }
else
return fCStatus = B_ERROR; return err;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BMidiPort::Stop() 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() int32 BMidiPort::CountDevices()
{ {
return _fDevices->CountItems(); return devices->CountItems();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize) status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize)
{ {
BMidiEndpoint *endpt = (BMidiEndpoint*)_fDevices->ItemAt(n); BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(n);
if (endpt == NULL) if (endp == NULL)
{
return B_BAD_VALUE; 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; return B_NAME_TOO_LONG;
if (strlen(strcpy(name, endpt->Name())) == size) }
strcpy(name, endp->Name());
return B_OK; return B_OK;
else
return B_ERROR;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -270,33 +295,58 @@ void BMidiPort::_ReservedMidiPort3() { }
void BMidiPort::Run() void BMidiPort::Run()
{ {
while(KeepRunning()) while (KeepRunning())
{
snooze(50000); snooze(50000);
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BMidiPort::ScanDevices() void BMidiPort::ScanDevices()
{ {
int32 id = 0; EmptyDeviceList();
BMidiRoster *roster = BMidiRoster::MidiRoster();
if (roster == NULL) int32 id = 0;
return; BMidiEndpoint* endp;
BMidiEndpoint *endpt = NULL;
while ((endpt = roster->NextEndpoint(&id)) != NULL) while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL)
{ {
bool additem = true; // Each hardware port has two endpoints associated with it, a consumer
for (int32 i = 0; i < _fDevices->CountItems(); i++) // 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); BMidiEndpoint* other = (BMidiEndpoint*) devices->ItemAt(t);
if (strcmp(endpt->Name(), endpoint->Name()) == 0) if (strcmp(endp->Name(), other->Name()) == 0)
additem = false; {
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();
}
//------------------------------------------------------------------------------
-97
View File
@@ -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);
}
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
-42
View File
@@ -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
File diff suppressed because it is too large Load Diff
+19 -4
View File
@@ -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" #include "debug.h"
@@ -209,4 +225,3 @@ void BMidiSynth::Run()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+19 -4
View File
@@ -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" #include "debug.h"
@@ -184,4 +200,3 @@ void BMidiSynthFile::_ReservedMidiSynthFile2() { }
void BMidiSynthFile::_ReservedMidiSynthFile3() { } void BMidiSynthFile::_ReservedMidiSynthFile3() { }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
+56 -54
View File
@@ -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 * Permission is hereby granted, free of charge, to any person obtaining a
* @author Jerome Leveque * copy of this software and associated documentation files (the "Software"),
* @author Paul Stadler * 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 "debug.h"
#include "MidiEvent.h"
#include "MidiText.h" #include "MidiText.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -23,7 +38,7 @@ BMidiText::BMidiText()
BMidiText::~BMidiText() BMidiText::~BMidiText()
{ {
// Do nothing // do nothing
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -32,9 +47,9 @@ void BMidiText::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": NOTE OFF; channel = " << (int) channel printf(
<< ", note = " << (int) note "B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
<< ", velocity = " << (int) velocity << endl; channel, note, velocity);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -43,9 +58,9 @@ void BMidiText::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": NOTE ON; channel = " << (int) channel printf(
<< ", note = " << (int) note "B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
<< ", velocity = " << (int) velocity << endl; channel, note, velocity);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -54,9 +69,9 @@ void BMidiText::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) uchar channel, uchar note, uchar pressure, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": KEY PRESSURE; channel = " << (int) channel printf(
<< ", note = " << (int) note "KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
<< ", pressure = " << (int) pressure << endl; channel, note, pressure);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -65,9 +80,9 @@ void BMidiText::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": CONTROL CHANGE; channel = " << (int) channel printf(
<< ", control = " << (int) controlNumber "CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
<< ", value = "<< (int) controlValue << endl; channel, controlNumber, controlValue);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -76,8 +91,9 @@ void BMidiText::ProgramChange(
uchar channel, uchar programNumber, uint32 time) uchar channel, uchar programNumber, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": PROGRAM CHANGE; channel = " << (int) channel printf(
<< ", program = " << (int) programNumber << endl; "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) void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": CHANNEL PRESSURE; channel = " << (int) channel printf(
<< ", pressure = " << (int) pressure << endl; "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) void BMidiText::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": PITCH BEND; channel = " << (int) channel << hex printf(
<< ", lsb = " << (int) lsb "PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
<< ", msb = " << (int) msb << endl; 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); WaitAndPrint(time);
cout << ": SYSTEM EXCLUSIVE;"; printf("SYSTEM EXCLUSIVE;\n");
for (size_t i = 0; i < dataLength; i++) 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) uchar status, uchar data1, uchar data2, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": SYSTEM COMMON; status = " << hex << (int) status printf(
<< ", data1 = " << (int) data1 "SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
<< ", data2 = " << (int) data2 << endl; status, data1, data2);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -129,23 +146,7 @@ void BMidiText::SystemCommon(
void BMidiText::SystemRealTime(uchar status, uint32 time) void BMidiText::SystemRealTime(uchar status, uint32 time)
{ {
WaitAndPrint(time); WaitAndPrint(time);
cout << ": SYSTEM REAL TIME; status = " << hex << (int) status << endl; printf("SYSTEM REAL TIME; status = %d\n", status);
}
//------------------------------------------------------------------------------
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;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -158,6 +159,8 @@ void BMidiText::ResetTimer(bool start)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BMidiText::_ReservedMidiText1() { } void BMidiText::_ReservedMidiText1() { }
void BMidiText::_ReservedMidiText2() { }
void BMidiText::_ReservedMidiText3() { }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -177,8 +180,7 @@ void BMidiText::WaitAndPrint(uint32 time)
SnoozeUntil(time); SnoozeUntil(time);
cout << dec << (time - startTime); printf("%u: ", time - startTime);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+19 -4
View File
@@ -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" #include "debug.h"
@@ -128,4 +144,3 @@ void BSamples::_ReservedSamples2() { }
void BSamples::_ReservedSamples3() { } void BSamples::_ReservedSamples3() { }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+19 -27
View File
@@ -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" #include "debug.h"
@@ -239,27 +255,3 @@ void BSynth::_ReservedSynth3() { }
void BSynth::_ReservedSynth4() { } 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;
}
//------------------------------------------------------------------------------