BMidiPort is complete, just need some testing, compile and work with Midi_Player_Replacement (All other BMidi class from libmidi).

BMidiPortConsumer act like a filter for sending data from new MidiKit to old MidiKit.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1955 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
jerl1
2002-11-16 00:24:16 +00:00
parent 6c45733119
commit d30512e906
2 changed files with 391 additions and 207 deletions
+317 -207
View File
@@ -1,207 +1,317 @@
/** /**
* @file MidiPort.cpp * @file MidiPort.cpp
* *
* @author Matthijs Hollemans * @author Jerome Leveque
*/ */
#include "debug.h" //----------------------------------------
#include "MidiPort.h"
#include "MidiPortConsumer.cpp"
//------------------------------------------------------------------------------
//----------------------------------------
BMidiPort::BMidiPort(const char* name)
{ #include <MidiPort.h>
UNIMPLEMENTED #include <MidiRoster.h>
} #include <string.h>
//------------------------------------------------------------------------------ #include <MidiProducer.h>
BMidiPort::~BMidiPort() //#define DEBUG
{
UNIMPLEMENTED //----------------------------------------
} //Public function
//------------------------------------------------------------------------------ BMidiPort::BMidiPort(const char *name = NULL)
: BMidi(),
status_t BMidiPort::InitCheck() const remote_source(NULL),
{ remote_sink(NULL),
UNIMPLEMENTED fCStatus(B_ERROR),
return B_NO_INIT; _fDevices(new BList)
} {
local_source = new BMidiLocalProducer("MidiPortGlue(out)");
//------------------------------------------------------------------------------ if (local_source != NULL)
local_source->Register();
status_t BMidiPort::Open(const char* name) local_sink = new BMidiPortConsumer(this, "MidiPortGlue(in)");
{ if (local_sink != NULL)
UNIMPLEMENTED local_sink->Register();
return B_ERROR;
} ScanDevices();
Open(name);
//------------------------------------------------------------------------------ }
void BMidiPort::Close() //-----------------
{
UNIMPLEMENTED BMidiPort::~BMidiPort()
} {
Close();
//------------------------------------------------------------------------------ delete fName;
if (local_source)
const char* BMidiPort::PortName() const local_source->Release();
{ if (local_sink)
UNIMPLEMENTED local_sink->Release();
return NULL; }
}
//----------------------------------------
//------------------------------------------------------------------------------
status_t BMidiPort::InitCheck() const
void BMidiPort::NoteOff( {
uchar channel, uchar note, uchar velocity, uint32 time) return fCStatus;
{ }
UNIMPLEMENTED
} //-----------------
//------------------------------------------------------------------------------ status_t BMidiPort::Open(const char *name)
{
void BMidiPort::NoteOn( if (name == NULL)
uchar channel, uchar note, uchar velocity, uint32 time) return fCStatus = B_ERROR;
{
UNIMPLEMENTED if (remote_source != NULL)
} {
if (local_sink != NULL)
//------------------------------------------------------------------------------ {
remote_source->Disconnect(local_sink);
void BMidiPort::KeyPressure( }
uchar channel, uchar note, uchar pressure, uint32 time) remote_source->Release();
{ remote_source = NULL;
UNIMPLEMENTED }
} if (remote_sink != NULL)
{
//------------------------------------------------------------------------------ if (local_source != NULL)
{
void BMidiPort::ControlChange( local_source->Disconnect(remote_sink);
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) }
{ remote_sink->Release();
UNIMPLEMENTED remote_sink = NULL;
} }
//------------------------------------------------------------------------------ int32 id = 0;
BMidiRoster *roster = BMidiRoster::MidiRoster();
void BMidiPort::ProgramChange( if (roster == NULL)
uchar channel, uchar programNumber, uint32 time) return fCStatus = B_ERROR;
{ BMidiEndpoint *endpt = NULL;
UNIMPLEMENTED while ((endpt = roster->NextEndpoint(&id)) != NULL)
} {
if (strcmp(endpt->Name(), name) == 0)
//------------------------------------------------------------------------------ {//An endpoint have the same name as we want
fName = new char[strlen(name)];
void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time) if (fName != NULL)
{ strcpy(fName, name);
UNIMPLEMENTED if (endpt->IsProducer())
} {
remote_source = (BMidiProducer*)endpt;
//------------------------------------------------------------------------------ endpt->Acquire(); //Because we always call Release()
}
void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) if (endpt->IsConsumer())
{ {
UNIMPLEMENTED remote_sink = (BMidiConsumer*)endpt;
} endpt->Acquire();//Because we always call Release()
if (local_source != NULL)
//------------------------------------------------------------------------------ local_source->Connect(remote_sink);
}
void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time) }
{ endpt->Release();
UNIMPLEMENTED }
} return fCStatus = B_OK;
}
//------------------------------------------------------------------------------
//-----------------
void BMidiPort::SystemCommon(
uchar status, uchar data1, uchar data2, uint32 time) void BMidiPort::Close()
{ {
UNIMPLEMENTED if ((local_sink != NULL) && (remote_source != NULL))
} {
remote_source->Disconnect(local_sink);
//------------------------------------------------------------------------------ remote_source->Release();
remote_source = NULL;
void BMidiPort::SystemRealTime(uchar status, uint32 time) }
{ if ((local_source != NULL) && (remote_sink != NULL))
UNIMPLEMENTED {
} local_source->Disconnect(remote_sink);
remote_sink->Release();
//------------------------------------------------------------------------------ remote_sink = NULL;
}
status_t BMidiPort::Start() }
{
UNIMPLEMENTED //-----------------
return B_ERROR;
} int32 BMidiPort::CountDevices()
{
//------------------------------------------------------------------------------ return _fDevices->CountItems();
}
void BMidiPort::Stop()
{ //-----------------
UNIMPLEMENTED
} status_t BMidiPort::GetDeviceName(int32 n, char *name, size_t bufSize)
{
//------------------------------------------------------------------------------ BMidiEndpoint *endpt = (BMidiEndpoint*)_fDevices->ItemAt(n);
if (endpt == NULL)
int32 BMidiPort::CountDevices() return B_BAD_VALUE;
{ size_t size = strlen(endpt->Name());
UNIMPLEMENTED if (size > bufSize)
return 0; return B_NAME_TOO_LONG;
} if (strlen(strcpy(name, endpt->Name())) == size)
return B_OK;
//------------------------------------------------------------------------------ else
return B_ERROR;
status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize) }
{
UNIMPLEMENTED //-----------------
return B_ERROR;
} const char *BMidiPort::PortName() const
{
//------------------------------------------------------------------------------ return fName;
}
void BMidiPort::_ReservedMidiPort1() { }
void BMidiPort::_ReservedMidiPort2() { } //----------------------------------------
void BMidiPort::_ReservedMidiPort3() { }
void BMidiPort::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time = B_NOW)
//------------------------------------------------------------------------------ {
local_source->SprayNoteOff(channel, note, velocity, 0);
void BMidiPort::Run() }
{
UNIMPLEMENTED //-----------------
}
void BMidiPort::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time = B_NOW)
//------------------------------------------------------------------------------ {
local_source->SprayNoteOn(channel, note, velocity, 0);
void BMidiPort::Dispatch( }
const unsigned char* buffer, size_t size, bigtime_t when)
{ //-----------------
UNIMPLEMENTED
} void BMidiPort::KeyPressure(uchar channel, uchar note, uchar pressure, uint32 time = B_NOW)
{
//------------------------------------------------------------------------------ local_source->SprayKeyPressure(channel, note, pressure, 0);
}
ssize_t BMidiPort::Read(void* buffer, size_t numBytes) const
{ //-----------------
UNIMPLEMENTED
return 0; void BMidiPort::ControlChange(uchar channel, uchar controlNumber, uchar controlValue, uint32 time = B_NOW)
} {
local_source->SprayControlChange(channel, controlNumber, controlValue, 0);
//------------------------------------------------------------------------------ }
ssize_t BMidiPort::Write(void* buffer, size_t numBytes, uint32 time) const //-----------------
{
UNIMPLEMENTED void BMidiPort::ProgramChange(uchar channel, uchar programNumber, uint32 time = B_NOW)
return 0; {
} local_source->SprayProgramChange(channel, programNumber, 0);
}
//------------------------------------------------------------------------------
//-----------------
void BMidiPort::ScanDevices()
{ void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time = B_NOW)
UNIMPLEMENTED {
} local_source->SprayChannelPressure(channel, pressure, 0);
}
//------------------------------------------------------------------------------
//-----------------
void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW)
{
local_source->SprayPitchBend(channel, lsb, msb, 0);
}
//-----------------
void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time = B_NOW)
{
local_source->SpraySystemExclusive(data, dataLength, 0);
}
//-----------------
void BMidiPort::SystemCommon(uchar statusByte, uchar data1, uchar data2, uint32 time = B_NOW)
{
local_source->SpraySystemCommon(statusByte, data1, data2, 0);
}
//-----------------
void BMidiPort::SystemRealTime(uchar statusByte, uint32 time = B_NOW)
{
local_source->SpraySystemRealTime(statusByte, 0);
}
//----------------------------------------
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;
}
//-----------------
void BMidiPort::Stop()
{
if ((remote_source != NULL) && (local_sink != NULL))
{
remote_source->Disconnect(local_sink);
}
BMidi::Stop();
}
//----------------------------------------
//Private Function
void BMidiPort::_ReservedMidiPort1() {}
void BMidiPort::_ReservedMidiPort2() {}
void BMidiPort::_ReservedMidiPort3() {}
//----------------------------------------
//Not Used function
void BMidiPort::Dispatch(const unsigned char *buffer, size_t size, bigtime_t when) {}
ssize_t BMidiPort::Read(void *buffer, size_t numBytes) const { return 0; }
ssize_t BMidiPort::Write(void *buffer, size_t numBytes, uint32 time) const { return 0; }
//-----------------
//Used function
void BMidiPort::Run()
{
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)
{
bool additem = true;
for (int32 i = 0; i < _fDevices->CountItems(); i++)
{
BMidiEndpoint *endpoint = (BMidiEndpoint*)_fDevices->ItemAt(i);
if (strcmp(endpt->Name(), endpoint->Name()) == 0)
additem = false;
}
if (additem)
_fDevices->AddItem(endpt);
endpt->Release();
}
}
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
+74
View File
@@ -0,0 +1,74 @@
/**
* @file MidiPort.cpp
*
* @author Jerome Leveque
*/
//----------------------------------------
#include <MidiConsumer.h>
#include <MidiPort.h>
//----------------------------------------
class BMidiPortConsumer : public BMidiLocalConsumer
{
public:
BMidiPortConsumer(BMidiPort *toPort, const char *name = NULL)
: BMidiLocalConsumer(name), port(toPort) {}
void NoteOff(uchar channel, uchar note, uchar velocity, bigtime_t time)
{
port->SprayNoteOff(channel, note, velocity, B_NOW);
}
void NoteOn(uchar channel, uchar note, uchar velocity, bigtime_t time)
{
port->SprayNoteOn(channel, note, velocity, B_NOW);
}
void KeyPressure(uchar channel, uchar note, uchar pressure, bigtime_t time)
{
port->SprayKeyPressure(channel, note, pressure, B_NOW);
}
void ControlChange(uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
{
port->SprayControlChange(channel, controlNumber, controlValue, B_NOW);
}
void ProgramChange(uchar channel, uchar programNumber, bigtime_t time)
{
port->SprayProgramChange(channel, programNumber, B_NOW);
}
void ChannelPressure(uchar channel, uchar pressure, bigtime_t time)
{
port->SprayChannelPressure(channel, pressure, B_NOW);
}
void PitchBend(uchar channel, uchar lsb, uchar msb, bigtime_t time)
{
port->SprayPitchBend(channel, lsb, msb, B_NOW);
}
void SystemExclusive(void *data, size_t dataLength, bigtime_t time)
{
port->SpraySystemExclusive(data, dataLength, B_NOW);
}
void SystemCommon(uchar statusByte, uchar data1, uchar data2, bigtime_t time)
{
port->SpraySystemCommon(statusByte, data1, data2, B_NOW);
}
void SystemRealTime(uchar statusByte, bigtime_t time)
{
port->SpraySystemRealTime(statusByte, B_NOW);
}
private:
BMidiPort *port;
};