Made correction asked to me

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1957 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
jerl1
2002-11-16 16:38:59 +00:00
parent 42010ad93f
commit f9493271b8
6 changed files with 446 additions and 394 deletions
+9 -7
View File
@@ -67,11 +67,12 @@ private:
virtual void Run(); virtual void Run();
friend class BMidiPortConsumer; friend class BMidiPortConsumer;
void Dispatch( //Can I do that?
const unsigned char* buffer, size_t size, bigtime_t when); // void Dispatch(
// const unsigned char* buffer, size_t size, bigtime_t when);
ssize_t Read(void* buffer, size_t numBytes) const; // ssize_t Read(void* buffer, size_t numBytes) const;
ssize_t Write(void* buffer, size_t numBytes, uint32 time) const; // ssize_t Write(void* buffer, size_t numBytes, uint32 time) const;
void ScanDevices(); void ScanDevices();
@@ -84,9 +85,10 @@ private:
char* fName; char* fName;
status_t fCStatus; status_t fCStatus;
BList* _fDevices; BList* _fDevices;
uint8 _m_prev_cmd; // uint8 _m_prev_cmd;
bool _m_enhanced; // bool _m_enhanced;
uint8 _m_reserved[2]; // uint8 _m_reserved[2];
uint8 _reserved[4];
}; };
#endif // _MIDI_PORT_H #endif // _MIDI_PORT_H
+125 -140
View File
@@ -2,29 +2,30 @@
* @file MidiPort.cpp * @file MidiPort.cpp
* *
* @author Jerome Leveque * @author Jerome Leveque
* @author Matthijs Hollemans
*/ */
//---------------------------------------- #include "debug.h"
#include "MidiPort.h"
#include "MidiPortConsumer.cpp" //------------------------------------------------------------------------------
//---------------------------------------- #include "MidiPortConsumer.h"
//------------------------------------------------------------------------------
#include <MidiPort.h>
#include <MidiRoster.h> #include <MidiRoster.h>
#include <string.h> #include <string.h>
#include <MidiProducer.h> #include <MidiProducer.h>
//#define DEBUG //------------------------------------------------------------------------------
//---------------------------------------- BMidiPort::BMidiPort(const char* name)
//Public function
BMidiPort::BMidiPort(const char *name = NULL)
: BMidi(), : BMidi(),
remote_source(NULL), remote_source(NULL),
remote_sink(NULL), remote_sink(NULL),
fName(NULL),
fCStatus(B_ERROR), fCStatus(B_ERROR),
_fDevices(new BList) _fDevices(new BList)
{ {
@@ -39,32 +40,74 @@ BMidiPort::BMidiPort(const char *name = NULL)
Open(name); Open(name);
} }
//----------------- //------------------------------------------------------------------------------
BMidiPort::~BMidiPort() BMidiPort::~BMidiPort()
{ {
Close(); Close();
delete fName; delete fName;
delete _fDevices;
if (local_source) if (local_source)
local_source->Release(); local_source->Release();
if (local_sink) if (local_sink)
local_sink->Release(); local_sink->Release();
} }
//---------------------------------------- //------------------------------------------------------------------------------
status_t BMidiPort::InitCheck() const status_t BMidiPort::InitCheck() const
{ {
return fCStatus; return fCStatus;
} }
//----------------- //------------------------------------------------------------------------------
status_t BMidiPort::Open(const char *name) status_t BMidiPort::Open(const char* name)
{ {
if (name == NULL) if (name == NULL)
return fCStatus = B_ERROR; return fCStatus = 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 (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())
{
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);
}
}
else
{
endpt->Release();
}
}
return fCStatus = B_OK;
}
//------------------------------------------------------------------------------
void BMidiPort::Close()
{
if (remote_source != NULL) if (remote_source != NULL)
{ {
if (local_sink != NULL) if (local_sink != NULL)
@@ -83,156 +126,92 @@ status_t BMidiPort::Open(const char *name)
remote_sink->Release(); remote_sink->Release();
remote_sink = NULL; remote_sink = NULL;
} }
int32 id = 0;
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)
{//An endpoint have the same name as we want
fName = new char[strlen(name)];
if (fName != NULL)
strcpy(fName, name);
if (endpt->IsProducer())
{
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);
}
}
endpt->Release();
}
return fCStatus = B_OK;
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::Close() const char* BMidiPort::PortName() const
{
if ((local_sink != NULL) && (remote_source != NULL))
{
remote_source->Disconnect(local_sink);
remote_source->Release();
remote_source = NULL;
}
if ((local_source != NULL) && (remote_sink != NULL))
{
local_source->Disconnect(remote_sink);
remote_sink->Release();
remote_sink = NULL;
}
}
//-----------------
int32 BMidiPort::CountDevices()
{
return _fDevices->CountItems();
}
//-----------------
status_t BMidiPort::GetDeviceName(int32 n, char *name, size_t bufSize)
{
BMidiEndpoint *endpt = (BMidiEndpoint*)_fDevices->ItemAt(n);
if (endpt == NULL)
return B_BAD_VALUE;
size_t size = strlen(endpt->Name());
if (size > bufSize)
return B_NAME_TOO_LONG;
if (strlen(strcpy(name, endpt->Name())) == size)
return B_OK;
else
return B_ERROR;
}
//-----------------
const char *BMidiPort::PortName() const
{ {
return fName; return fName;
} }
//---------------------------------------- //------------------------------------------------------------------------------
void BMidiPort::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time = B_NOW) void BMidiPort::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time)
{ {
local_source->SprayNoteOff(channel, note, velocity, 0); local_source->SprayNoteOff(channel, note, velocity, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time = B_NOW) void BMidiPort::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time)
{ {
local_source->SprayNoteOn(channel, note, velocity, 0); local_source->SprayNoteOn(channel, note, velocity, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::KeyPressure(uchar channel, uchar note, uchar pressure, uint32 time = B_NOW) void BMidiPort::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time)
{ {
local_source->SprayKeyPressure(channel, note, pressure, 0); local_source->SprayKeyPressure(channel, note, pressure, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::ControlChange(uchar channel, uchar controlNumber, uchar controlValue, uint32 time = B_NOW) void BMidiPort::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
local_source->SprayControlChange(channel, controlNumber, controlValue, 0); local_source->SprayControlChange(channel, controlNumber, controlValue, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::ProgramChange(uchar channel, uchar programNumber, uint32 time = B_NOW) void BMidiPort::ProgramChange(
uchar channel, uchar programNumber, uint32 time)
{ {
local_source->SprayProgramChange(channel, programNumber, 0); local_source->SprayProgramChange(channel, programNumber, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time = B_NOW) void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
local_source->SprayChannelPressure(channel, pressure, 0); local_source->SprayChannelPressure(channel, pressure, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW) void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
{ {
local_source->SprayPitchBend(channel, lsb, msb, 0); local_source->SprayPitchBend(channel, lsb, msb, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time = B_NOW) void BMidiPort::SystemExclusive(void* data, size_t dataLength, uint32 time)
{ {
local_source->SpraySystemExclusive(data, dataLength, 0); local_source->SpraySystemExclusive(data, dataLength, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::SystemCommon(uchar statusByte, uchar data1, uchar data2, uint32 time = B_NOW) void BMidiPort::SystemCommon(
uchar status, uchar data1, uchar data2, uint32 time)
{ {
local_source->SpraySystemCommon(statusByte, data1, data2, 0); local_source->SpraySystemCommon(statusByte, data1, data2, 0);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::SystemRealTime(uchar statusByte, uint32 time = B_NOW) void BMidiPort::SystemRealTime(uchar status, uint32 time)
{ {
local_source->SpraySystemRealTime(statusByte, 0); local_source->SpraySystemRealTime(statusByte, 0);
} }
//---------------------------------------- //------------------------------------------------------------------------------
status_t BMidiPort::Start() status_t BMidiPort::Start()
{ {
@@ -247,7 +226,7 @@ status_t BMidiPort::Start()
return fCStatus = B_ERROR; return fCStatus = B_ERROR;
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::Stop() void BMidiPort::Stop()
{ {
@@ -258,22 +237,36 @@ void BMidiPort::Stop()
BMidi::Stop(); BMidi::Stop();
} }
//---------------------------------------- //------------------------------------------------------------------------------
//Private Function
void BMidiPort::_ReservedMidiPort1() {} int32 BMidiPort::CountDevices()
void BMidiPort::_ReservedMidiPort2() {} {
void BMidiPort::_ReservedMidiPort3() {} return _fDevices->CountItems();
}
//---------------------------------------- //------------------------------------------------------------------------------
//Not Used function
void BMidiPort::Dispatch(const unsigned char *buffer, size_t size, bigtime_t when) {} status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize)
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; } BMidiEndpoint *endpt = (BMidiEndpoint*)_fDevices->ItemAt(n);
if (endpt == NULL)
return B_BAD_VALUE;
size_t size = strlen(endpt->Name());
if (size > bufSize)
return B_NAME_TOO_LONG;
if (strlen(strcpy(name, endpt->Name())) == size)
return B_OK;
else
return B_ERROR;
}
//----------------- //------------------------------------------------------------------------------
//Used function
void BMidiPort::_ReservedMidiPort1() { }
void BMidiPort::_ReservedMidiPort2() { }
void BMidiPort::_ReservedMidiPort3() { }
//------------------------------------------------------------------------------
void BMidiPort::Run() void BMidiPort::Run()
{ {
@@ -281,7 +274,7 @@ void BMidiPort::Run()
snooze(50000); snooze(50000);
} }
//----------------- //------------------------------------------------------------------------------
void BMidiPort::ScanDevices() void BMidiPort::ScanDevices()
{ {
@@ -305,13 +298,5 @@ int32 id = 0;
} }
} }
//---------------------------------------- //------------------------------------------------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
//----------------------------------------
+72 -49
View File
@@ -6,69 +6,92 @@
//---------------------------------------- //----------------------------------------
#include <MidiConsumer.h> #include <MidiPortConsumer.h>
#include <MidiPort.h>
//---------------------------------------- //----------------------------------------
class BMidiPortConsumer : public BMidiLocalConsumer BMidiPortConsumer::BMidiPortConsumer(BMidiPort *toPort, const char *name = NULL)
: BMidiLocalConsumer(name), port(toPort)
{ {
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) void BMidiPortConsumer::NoteOff(uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
port->SprayNoteOn(channel, note, velocity, B_NOW); port->SprayNoteOff(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) void BMidiPortConsumer::NoteOn(uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
port->SprayControlChange(channel, controlNumber, controlValue, B_NOW); port->SprayNoteOn(channel, note, velocity, 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) void BMidiPortConsumer::KeyPressure(uchar channel, uchar note, uchar pressure, bigtime_t time)
{ {
port->SprayChannelPressure(channel, pressure, B_NOW); port->SprayKeyPressure(channel, note, 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) void BMidiPortConsumer::ControlChange(uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
{ {
port->SpraySystemExclusive(data, dataLength, B_NOW); port->SprayControlChange(channel, controlNumber, controlValue, 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) void BMidiPortConsumer::ProgramChange(uchar channel, uchar programNumber, bigtime_t time)
{ {
port->SpraySystemRealTime(statusByte, B_NOW); port->SprayProgramChange(channel, programNumber, B_NOW);
} }
private: //-----------------
BMidiPort *port;
}; 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
@@ -0,0 +1,42 @@
/**
* @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
@@ -3,7 +3,7 @@ Author: Jerome LEVEQUE
Email: [email protected] Email: [email protected]
*/ */
#include "MidiPlayerView.h" #include "MidiPlayerView.h"
#include "Scope.h" //#include "Scope.h"
#include "Activity.h" #include "Activity.h"
#include <StringView.h> #include <StringView.h>
@@ -154,12 +154,12 @@ Activity *view = NULL;
RemoveAll(fViewBox); RemoveAll(fViewBox);
break; break;
//-------------- //--------------
case VIEW_CHANGE_TO_SCOPE : /* case VIEW_CHANGE_TO_SCOPE :
RemoveAll(fViewBox); RemoveAll(fViewBox);
fViewBox->AddChild(new Scope(BRect(10, 25, 340, 340))); fViewBox->AddChild(new Scope(BRect(10, 25, 340, 340)));
break; break;
//-------------- //--------------
case VIEW_CHANGE_TO_ACTIVITY : */ case VIEW_CHANGE_TO_ACTIVITY :
RemoveAll(fViewBox); RemoveAll(fViewBox);
msg->FindPointer("View", (void**)&view); msg->FindPointer("View", (void**)&view);
fViewBox->AddChild(view); fViewBox->AddChild(view);
@@ -229,7 +229,7 @@ BMessage *msg = NULL;
BMenuItem *item = NULL; BMenuItem *item = NULL;
int32 temp = 0; int32 temp = 0;
Menu = new BPopUpMenu("Sample Rate"); /* Menu = new BPopUpMenu("Sample Rate");
temp = be_synth->SamplingRate(); temp = be_synth->SamplingRate();
msg = new BMessage(CHANGE_SAMPLE_RATE_SYNTH); msg = new BMessage(CHANGE_SAMPLE_RATE_SYNTH);
Menu->AddItem(item = new BMenuItem("11025 Hz", msg)); Menu->AddItem(item = new BMenuItem("11025 Hz", msg));
@@ -303,7 +303,7 @@ BSlider *slider = new BSlider(BRect(5, 100, 275, 130), NULL, "Volume",
slider->SetValue(temp); slider->SetValue(temp);
slider->SetLimitLabels("Min", "Max"); slider->SetLimitLabels("Min", "Max");
aView->AddChild(slider); aView->AddChild(slider);
} */}
//---------------------------------------------------------- //----------------------------------------------------------
//---------------------------------------------------------- //----------------------------------------------------------
@@ -17,7 +17,7 @@ Email: [email protected]
#include <File.h> #include <File.h>
#include <MidiStore.h> #include <MidiStore.h>
#include <MidiPort.h> #include <MidiPort.h>
#include <MidiSynth.h> //#include <MidiSynth.h>
#include <MidiSynthFile.h> #include <MidiSynthFile.h>
//---------------------------------------------------------- //----------------------------------------------------------
@@ -210,7 +210,7 @@ entry_ref ref;
PostMessage(msg, fStandartView); PostMessage(msg, fStandartView);
break; break;
//-------------- //--------------
case OUTPUT_CHANGE_TO_BEOS_SYNTH : /* case OUTPUT_CHANGE_TO_BEOS_SYNTH :
if (fOutputType == BEOS_SYNTH) if (fOutputType == BEOS_SYNTH)
break; break;
fOutputType = BEOS_SYNTH; fOutputType = BEOS_SYNTH;
@@ -244,7 +244,7 @@ entry_ref ref;
PostMessage(msg, fStandartView); PostMessage(msg, fStandartView);
break; break;
//-------------- //--------------
case OUTPUT_CHANGE_TO_MIDIPORT : */ case OUTPUT_CHANGE_TO_MIDIPORT :
if (fOutputType == MIDIPORT) if (fOutputType == MIDIPORT)
break; break;
fOutputType = MIDIPORT; fOutputType = MIDIPORT;
@@ -280,14 +280,14 @@ entry_ref ref;
PostMessage(msg, fStandartView); PostMessage(msg, fStandartView);
break; break;
//-------------- //--------------
case VIEW_CHANGE_TO_SCOPE : /* case VIEW_CHANGE_TO_SCOPE :
if (fDisplayType == SCOPE) if (fDisplayType == SCOPE)
break; break;
fDisplayType = SCOPE; fDisplayType = SCOPE;
PostMessage(msg, fStandartView); PostMessage(msg, fStandartView);
break; break;
//-------------- //--------------
case VIEW_CHANGE_TO_ACTIVITY : */ case VIEW_CHANGE_TO_ACTIVITY :
if (fDisplayType == ACTIVITY) if (fDisplayType == ACTIVITY)
break; break;
fDisplayType = ACTIVITY; fDisplayType = ACTIVITY;
@@ -422,7 +422,7 @@ entry_ref ref;
//-------------- //--------------
//Message from the BeOS Synth //Message from the BeOS Synth
//-------------- //--------------
case CHANGE_BEOS_SYNTH_FILE: /* case CHANGE_BEOS_SYNTH_FILE:
if (fOutputFilePanel) if (fOutputFilePanel)
{ {
msg->FindRef("refs", &fOutputFile); msg->FindRef("refs", &fOutputFile);
@@ -545,7 +545,7 @@ entry_ref ref;
//-------------- //--------------
//For the drag and drop function //For the drag and drop function
//-------------- //--------------
case B_SIMPLE_DATA : //A file had been dropped into application */ case B_SIMPLE_DATA : //A file had been dropped into application
if (msg->FindRef("refs", &ref) == B_OK) if (msg->FindRef("refs", &ref) == B_OK)
{ {
message = BMessage(INPUT_CHANGE_TO_FILE); message = BMessage(INPUT_CHANGE_TO_FILE);