Some correction, and class BMidiStore.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2047 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+108
-73
@@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
#ifndef _MIDI_H
|
#ifndef _MIDI_H
|
||||||
#define _MIDI_H
|
#define _MIDI_H
|
||||||
|
|
||||||
|
#ifndef _BE_BUILD_H
|
||||||
#include <BeBuild.h>
|
#include <BeBuild.h>
|
||||||
|
#endif
|
||||||
#include <MidiDefs.h>
|
#include <MidiDefs.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
@@ -12,115 +13,149 @@ class BList;
|
|||||||
class BMidi
|
class BMidi
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BMidi();
|
BMidi();
|
||||||
virtual ~BMidi();
|
virtual ~BMidi();
|
||||||
|
|
||||||
virtual void NoteOff(
|
virtual void NoteOff(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void NoteOn(
|
virtual void NoteOn(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void KeyPressure(
|
virtual void KeyPressure(uchar channel,
|
||||||
uchar channel, uchar note, uchar pressure, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar pressure,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ControlChange(
|
virtual void ControlChange(uchar channel,
|
||||||
uchar channel, uchar controlNumber, uchar controlValue,
|
uchar controlNumber,
|
||||||
uint32 time = B_NOW);
|
uchar controlValue,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ProgramChange(
|
virtual void ProgramChange(uchar channel,
|
||||||
uchar channel, uchar programNumber, uint32 time = B_NOW);
|
uchar programNumber,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ChannelPressure(
|
virtual void ChannelPressure(uchar channel,
|
||||||
uchar channel, uchar pressure, uint32 time = B_NOW);
|
uchar pressure,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void PitchBend(
|
virtual void PitchBend(uchar channel,
|
||||||
uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW);
|
uchar lsb,
|
||||||
|
uchar msb,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemExclusive(
|
virtual void SystemExclusive(void* data,
|
||||||
void* data, size_t dataLength, uint32 time = B_NOW);
|
size_t dataLength,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemCommon(
|
virtual void SystemCommon(uchar statusByte,
|
||||||
uchar status, uchar data1, uchar data2, uint32 time = B_NOW);
|
uchar data1,
|
||||||
|
uchar data2,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemRealTime(uchar status, uint32 time = B_NOW);
|
virtual void SystemRealTime(uchar statusByte, uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void TempoChange(int32 beatsPerMinute, uint32 time = B_NOW);
|
virtual void TempoChange(int32 bpm, uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void AllNotesOff(bool justChannel = true, uint32 time = B_NOW);
|
virtual void AllNotesOff(bool justChannel = true, uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual status_t Start();
|
virtual status_t Start();
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
bool IsRunning() const;
|
bool IsRunning() const;
|
||||||
|
|
||||||
void Connect(BMidi* toObject);
|
void Connect(BMidi* toObject);
|
||||||
void Disconnect(BMidi* fromObject);
|
void Disconnect(BMidi* fromObject);
|
||||||
bool IsConnected(BMidi* toObject) const;
|
bool IsConnected(BMidi* toObject) const;
|
||||||
BList* Connections() const;
|
BList* Connections() const;
|
||||||
|
|
||||||
void SnoozeUntil(uint32 time) const;
|
void SnoozeUntil(uint32 time) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void SprayNoteOff(uchar channel,
|
||||||
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayNoteOff(
|
void SprayNoteOn(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time) const;
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayNoteOn(
|
void SprayKeyPressure(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time) const;
|
uchar note,
|
||||||
|
uchar pressure,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayKeyPressure(
|
void SprayControlChange(uchar channel,
|
||||||
uchar channel, uchar note, uchar pressure, uint32 time) const;
|
uchar controlNumber,
|
||||||
|
uchar controlValue,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayControlChange(
|
void SprayProgramChange(uchar channel,
|
||||||
uchar channel, uchar controlNumber, uchar controlValue,
|
uchar programNumber,
|
||||||
uint32 time) const;
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayProgramChange(
|
void SprayChannelPressure(uchar channel,
|
||||||
uchar channel, uchar programNumber, uint32 time) const;
|
uchar pressure,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayChannelPressure(
|
void SprayPitchBend(uchar channel,
|
||||||
uchar channel, uchar pressure, uint32 time) const;
|
uchar lsb,
|
||||||
|
uchar msb,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SprayPitchBend(
|
void SpraySystemExclusive(void* data,
|
||||||
uchar channel, uchar lsb, uchar msb, uint32 time) const;
|
size_t dataLength,
|
||||||
|
uint32 time = B_NOW) const;
|
||||||
|
|
||||||
void SpraySystemExclusive(
|
void SpraySystemCommon(uchar statusByte,
|
||||||
void* data, size_t dataLength, uint32 time = B_NOW) const;
|
uchar data1,
|
||||||
|
uchar data2,
|
||||||
|
uint32 time) const;
|
||||||
|
|
||||||
void SpraySystemCommon(
|
void SpraySystemRealTime(uchar statusByte, uint32 time) const;
|
||||||
uchar status, uchar data1, uchar data2, uint32 time) const;
|
|
||||||
|
|
||||||
void SpraySystemRealTime(uchar status, uint32 time) const;
|
void SprayTempoChange(int32 bpm, uint32 time) const;
|
||||||
|
|
||||||
void SprayTempoChange(int32 beatsPerMinute, uint32 time) const;
|
bool KeepRunning();
|
||||||
|
|
||||||
bool KeepRunning();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
friend class BMidiStore;
|
friend class BMidiPort; /* for debugging */
|
||||||
|
friend class BMidiStore; /* for debugging */
|
||||||
|
|
||||||
virtual void _ReservedMidi1();
|
virtual void _ReservedMidi1();
|
||||||
virtual void _ReservedMidi2();
|
virtual void _ReservedMidi2();
|
||||||
virtual void _ReservedMidi3();
|
virtual void _ReservedMidi3();
|
||||||
|
|
||||||
static int32 RunThread(void* data);
|
friend status_t _run_thread_(void *arg);
|
||||||
static int32 InflowThread(void* data);
|
friend status_t _inflow_task_(void *arg);
|
||||||
|
|
||||||
virtual void Run();
|
void SprayMidiEvent(BMidiEvent* event) const;
|
||||||
void Inflow();
|
port_id ID() const;
|
||||||
|
|
||||||
void SprayMidiEvent(BMidiEvent* event) const;
|
virtual void Run();
|
||||||
|
|
||||||
BList* connections;
|
status_t StartInflow();
|
||||||
thread_id runThread;
|
void StopInflow();
|
||||||
thread_id inflowThread;
|
bool IsInflowing();
|
||||||
port_id inflowPort;
|
void InflowTask();
|
||||||
bool isRunning;
|
bool InflowIsAlive();
|
||||||
bool inflowAlive;
|
|
||||||
|
|
||||||
uint32 _reserved[5];
|
BList* fConnectionList;
|
||||||
|
volatile thread_id fRunTask;
|
||||||
|
volatile bool fIsRunning;
|
||||||
|
volatile thread_id fInflowTask;
|
||||||
|
volatile bool fInflowAlive;
|
||||||
|
port_id fInflowPort;
|
||||||
|
uint32 _reserved[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MIDI_H
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
+139
-66
@@ -1,105 +1,178 @@
|
|||||||
|
|
||||||
#ifndef _MIDI_STORE_H
|
#ifndef _MIDI_STORE_H
|
||||||
#define _MIDI_STORE_H
|
#define _MIDI_STORE_H
|
||||||
|
|
||||||
|
#ifndef _BE_BUILD_H
|
||||||
#include <BeBuild.h>
|
#include <BeBuild.h>
|
||||||
|
#endif
|
||||||
#include <Midi.h>
|
#include <Midi.h>
|
||||||
|
|
||||||
struct entry_ref;
|
struct entry_ref;
|
||||||
|
|
||||||
class BMidiEvent;
|
class BMidiEvent;
|
||||||
class BList;
|
|
||||||
class BFile;
|
class BFile;
|
||||||
|
|
||||||
class BMidiStore : public BMidi
|
/*------------------------------------------------------------*/
|
||||||
{
|
|
||||||
|
class BMidiStore : public BMidi {
|
||||||
public:
|
public:
|
||||||
BMidiStore();
|
BMidiStore();
|
||||||
virtual ~BMidiStore();
|
virtual ~BMidiStore();
|
||||||
|
|
||||||
virtual void NoteOff(
|
virtual void NoteOff(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void NoteOn(
|
virtual void NoteOn(uchar channel,
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar velocity,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void KeyPressure(
|
virtual void KeyPressure(uchar channel,
|
||||||
uchar channel, uchar note, uchar pressure, uint32 time = B_NOW);
|
uchar note,
|
||||||
|
uchar pressure,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ControlChange(
|
virtual void ControlChange(uchar channel,
|
||||||
uchar channel, uchar controlNumber, uchar controlValue,
|
uchar controlNumber,
|
||||||
uint32 time = B_NOW);
|
uchar controlValue,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ProgramChange(
|
virtual void ProgramChange(uchar channel,
|
||||||
uchar channel, uchar programNumber, uint32 time = B_NOW);
|
uchar programNumber,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void ChannelPressure(
|
virtual void ChannelPressure(uchar channel,
|
||||||
uchar channel, uchar pressure, uint32 time = B_NOW);
|
uchar pressure,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void PitchBend(
|
virtual void PitchBend(uchar channel,
|
||||||
uchar channel, uchar lsb, uchar msb, uint32 time = B_NOW);
|
uchar lsb,
|
||||||
|
uchar msb,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemExclusive(
|
virtual void SystemExclusive(void* data,
|
||||||
void* data, size_t dataLength, uint32 time = B_NOW);
|
size_t dataLength,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemCommon(
|
virtual void SystemCommon(uchar statusByte,
|
||||||
uchar status, uchar data1, uchar data2, uint32 time = B_NOW);
|
uchar data1,
|
||||||
|
uchar data2,
|
||||||
|
uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void SystemRealTime(uchar status, uint32 time = B_NOW);
|
virtual void SystemRealTime(uchar statusByte, uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void TempoChange(int32 beatsPerMinute, uint32 time = B_NOW);
|
virtual void TempoChange(int32 bpm, uint32 time = B_NOW);
|
||||||
|
|
||||||
virtual void AllNotesOff(bool justChannel = true, uint32 time = B_NOW);
|
status_t Import(const entry_ref *ref);
|
||||||
|
status_t Export(const entry_ref *ref, int32 format);
|
||||||
|
|
||||||
status_t Import(const entry_ref* ref);
|
void SortEvents(bool force=false);
|
||||||
status_t Export(const entry_ref* ref, int32 format);
|
uint32 CountEvents() const;
|
||||||
|
|
||||||
void SortEvents(bool force = false);
|
uint32 CurrentEvent() const;
|
||||||
uint32 CountEvents() const;
|
void SetCurrentEvent(uint32 eventNumber);
|
||||||
|
|
||||||
uint32 CurrentEvent() const;
|
uint32 DeltaOfEvent(uint32 eventNumber) const;
|
||||||
void SetCurrentEvent(uint32 eventNumber);
|
uint32 EventAtDelta(uint32 time) const;
|
||||||
|
|
||||||
uint32 DeltaOfEvent(uint32 eventNumber) const;
|
uint32 BeginTime() const;
|
||||||
uint32 EventAtDelta(uint32 time) const;
|
|
||||||
|
void SetTempo(int32 bpm);
|
||||||
uint32 BeginTime() const;
|
int32 Tempo() const;
|
||||||
|
|
||||||
void SetTempo(int32 beatsPerMinute);
|
|
||||||
int32 Tempo() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
virtual void _ReservedMidiStore1();
|
virtual void _ReservedMidiStore1();
|
||||||
virtual void _ReservedMidiStore2();
|
virtual void _ReservedMidiStore2();
|
||||||
|
virtual void _ReservedMidiStore3();
|
||||||
|
|
||||||
virtual void Run();
|
virtual void Run();
|
||||||
|
|
||||||
BMidiEvent* EventAt(uint32 index) const;
|
void AddEvent(uint32 time,
|
||||||
|
bool inMS,
|
||||||
|
uchar type,
|
||||||
|
uchar data1 = 0,
|
||||||
|
uchar data2 = 0,
|
||||||
|
uchar data3 = 0,
|
||||||
|
uchar data4 = 0);
|
||||||
|
|
||||||
static int CompareEvents(const void* event1, const void* event2);
|
void AddSystemExclusive(void* data, size_t dataLength);
|
||||||
|
|
||||||
|
status_t ReadHeader();
|
||||||
|
bool ReadMT(char*);
|
||||||
|
int32 Read32Bit();
|
||||||
|
int32 EGetC();
|
||||||
|
int32 To32Bit(int32, int32, int32, int32);
|
||||||
|
int32 Read16Bit();
|
||||||
|
int32 To16Bit(int32, int32);
|
||||||
|
bool ReadTrack();
|
||||||
|
int32 ReadVariNum();
|
||||||
|
void ChannelMessage(int32, int32, int32);
|
||||||
|
void MsgInit();
|
||||||
|
void MsgAdd(int32);
|
||||||
|
void BiggerMsg();
|
||||||
|
void MetaEvent(int32);
|
||||||
|
int32 MsgLength();
|
||||||
|
uchar* Msg();
|
||||||
|
void BadByte(int32);
|
||||||
|
|
||||||
|
int32 PutC(int32 c);
|
||||||
|
bool WriteTrack(int32 track);
|
||||||
|
void WriteTempoTrack();
|
||||||
|
bool WriteTrackChunk(int32 whichTrack);
|
||||||
|
void WriteHeaderChunk(int32 format);
|
||||||
|
bool WriteMidiEvent(uint32 deltaTime,
|
||||||
|
uint32 type,
|
||||||
|
uint32 channel,
|
||||||
|
uchar* data,
|
||||||
|
uint32 size);
|
||||||
|
bool WriteMetaEvent(uint32 deltaTime,
|
||||||
|
uint32 type,
|
||||||
|
uchar* data,
|
||||||
|
uint32 size);
|
||||||
|
bool WriteSystemExclusiveEvent(uint32 deltaTime,
|
||||||
|
uchar* data,
|
||||||
|
uint32 size);
|
||||||
|
void WriteTempo(uint32 deltaTime, int32 tempo);
|
||||||
|
void WriteVarLen(uint32 value);
|
||||||
|
void Write32Bit(uint32 data);
|
||||||
|
void Write16Bit(ushort data);
|
||||||
|
int32 EPutC(uchar c);
|
||||||
|
|
||||||
|
uint32 TicksToMilliseconds(uint32 ticks) const;
|
||||||
|
uint32 MillisecondsToTicks(uint32 ms) const;
|
||||||
|
|
||||||
void ReadFileHeader();
|
BList *events;
|
||||||
void ReadTrackHeader();
|
// uint32 fNumEvents;
|
||||||
void ReadTrack();
|
// uint32 fEventsSize;
|
||||||
int32 Read32Bit();
|
uint32 fCurrEvent;
|
||||||
int16 Read16Bit();
|
bool fNeedsSorting;
|
||||||
void ReadData(uint8* data, size_t size);
|
// bool fResetTimer;
|
||||||
|
uint32 fStartTime;
|
||||||
|
BFile* fFile;
|
||||||
|
short fDivision;
|
||||||
|
float fDivisionFactor;
|
||||||
|
int32 fTempo;
|
||||||
|
int32 fCurrTime;
|
||||||
|
int32 fCurrTrack;
|
||||||
|
int32 fNumTracks;
|
||||||
|
|
||||||
|
// int32 fToBeRead;
|
||||||
|
// int32 fMsgIndex;
|
||||||
|
// int32 fMsgSize;
|
||||||
|
// uchar* fMsgBuff;
|
||||||
|
|
||||||
|
int32 fNumBytesWritten;
|
||||||
|
|
||||||
BList* events;
|
uchar* fFileBuffer;
|
||||||
uint32 tempo;
|
int32 fFileBufferMax;
|
||||||
uint32 curEvent;
|
int32 fFileBufferSize;
|
||||||
uint32 startTime;
|
int32 fFileBufferIndex;
|
||||||
uint32 ticksPerBeat;
|
uint32 _reserved[4];
|
||||||
|
|
||||||
BFile* file;
|
|
||||||
int32 numTracks;
|
|
||||||
int32 trackSize;
|
|
||||||
int16 division;
|
|
||||||
|
|
||||||
uint16 _reserved1;
|
|
||||||
uint32 _reserved2[17];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MIDI_STORE_H
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
+169
-148
@@ -8,128 +8,170 @@
|
|||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
#include "debug.h"
|
|
||||||
#include "Midi.h"
|
#include "Midi.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "MidiEvent.h"
|
#include "MidiEvent.h"
|
||||||
|
|
||||||
#define MSG_CODE_PROCESS_EVENT 1
|
#define DEBUG
|
||||||
#define MSG_CODE_TERMINATE_THREAD 0
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
#define MSG_CODE_PROCESS_EVENT 1
|
||||||
|
#define MSG_CODE_TERMINATE_THREAD 0
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Initialization Stuff
|
||||||
BMidi::BMidi()
|
BMidi::BMidi()
|
||||||
{
|
{
|
||||||
connections = new BList();
|
fConnectionList = new BList();
|
||||||
isRunning = false;
|
fIsRunning = false;
|
||||||
|
|
||||||
inflowPort = create_port(1, "Inflow Port");
|
fInflowPort = create_port(1, "Inflow Port");
|
||||||
|
|
||||||
inflowThread = spawn_thread(
|
fInflowTask = spawn_thread(
|
||||||
InflowThread, "BMidi Inflow Thread",
|
_inflow_task_, "BMidi Inflow Thread",
|
||||||
B_REAL_TIME_PRIORITY, (void*) this);
|
B_REAL_TIME_PRIORITY, (void *)this);
|
||||||
|
|
||||||
inflowAlive = (resume_thread(inflowThread) == B_OK);
|
fInflowAlive = resume_thread(fInflowTask) == B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
BMidi::~BMidi()
|
BMidi::~BMidi()
|
||||||
{
|
{
|
||||||
write_port(inflowPort, MSG_CODE_TERMINATE_THREAD, NULL, 0);
|
write_port(fInflowPort, MSG_CODE_TERMINATE_THREAD, NULL, 0);
|
||||||
|
|
||||||
status_t exitValue;
|
status_t exit_value;
|
||||||
wait_for_thread(inflowThread, &exitValue);
|
wait_for_thread(fInflowTask, &exit_value);
|
||||||
|
|
||||||
delete_port(inflowPort);
|
delete_port(fInflowPort);
|
||||||
delete connections;
|
delete fConnectionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
// Stubs for midi event hooks.
|
||||||
void BMidi::NoteOff(uchar, uchar, uchar, uint32) { }
|
void BMidi::NoteOff(uchar chan, uchar note, uchar vel, uint32 time)
|
||||||
void BMidi::NoteOn(uchar, uchar, uchar, uint32) { }
|
{
|
||||||
void BMidi::KeyPressure(uchar, uchar, uchar, uint32) { }
|
}
|
||||||
void BMidi::ControlChange(uchar, uchar, uchar, uint32) { }
|
void BMidi::NoteOn(uchar chan, uchar note, uchar vel, uint32 time)
|
||||||
void BMidi::ProgramChange(uchar, uchar, uint32) { }
|
{
|
||||||
void BMidi::ChannelPressure(uchar, uchar, uint32) { }
|
}
|
||||||
void BMidi::PitchBend(uchar, uchar, uchar, uint32) { }
|
void BMidi::KeyPressure(uchar chan, uchar note, uchar pres, uint32 time)
|
||||||
void BMidi::SystemExclusive(void*, size_t, uint32) { }
|
{
|
||||||
void BMidi::SystemCommon(uchar, uchar, uchar, uint32) { }
|
}
|
||||||
void BMidi::SystemRealTime(uchar, uint32) { }
|
void BMidi::ControlChange(uchar chan, uchar ctrl_num, uchar ctrl_val, uint32 time)
|
||||||
void BMidi::TempoChange(int32, uint32) { }
|
{
|
||||||
void BMidi::AllNotesOff(bool, uint32) { }
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Public API Functions
|
||||||
status_t BMidi::Start()
|
status_t BMidi::Start()
|
||||||
{
|
{
|
||||||
runThread = spawn_thread(
|
fRunTask = spawn_thread(_run_thread_,
|
||||||
RunThread, "BMidi Run Thread",
|
"BMidi Run Thread", B_REAL_TIME_PRIORITY, (void *)this);
|
||||||
B_REAL_TIME_PRIORITY, (void*) this);
|
fIsRunning = true;
|
||||||
|
status_t ret = resume_thread(fRunTask);
|
||||||
status_t ret = resume_thread(runThread);
|
if(ret != B_OK)
|
||||||
|
{
|
||||||
if (ret == B_OK)
|
fIsRunning = false;
|
||||||
{
|
|
||||||
isRunning = true;
|
|
||||||
}
|
}
|
||||||
|
return B_OK;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BMidi::Stop()
|
void BMidi::Stop()
|
||||||
{
|
{
|
||||||
status_t exitValue;
|
status_t exit_value;
|
||||||
wait_for_thread(runThread, &exitValue);
|
status_t ret;
|
||||||
|
fIsRunning = false;
|
||||||
isRunning = false;
|
ret = wait_for_thread(fRunTask, &exit_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool BMidi::IsRunning() const
|
bool BMidi::IsRunning() const
|
||||||
{
|
{
|
||||||
return isRunning;
|
thread_info info;
|
||||||
|
get_thread_info(fRunTask,&info);
|
||||||
|
if(find_thread("BMidi Run Thread") == fRunTask)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void BMidi::Connect(BMidi *to_object)
|
||||||
|
|
||||||
void BMidi::Connect(BMidi* toObject)
|
|
||||||
{
|
{
|
||||||
connections->AddItem(toObject);
|
fConnectionList->AddItem((void *)to_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
void BMidi::Disconnect(BMidi *from_object)
|
||||||
|
|
||||||
void BMidi::Disconnect(BMidi* fromObject)
|
|
||||||
{
|
{
|
||||||
connections->RemoveItem(fromObject);
|
fConnectionList->RemoveItem((void *)from_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
bool BMidi::IsConnected(BMidi * to_object) const
|
||||||
|
|
||||||
bool BMidi::IsConnected(BMidi* toObject) const
|
|
||||||
{
|
{
|
||||||
return connections->HasItem(toObject);
|
return fConnectionList->HasItem((void *)to_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
BList * BMidi::Connections() const
|
||||||
|
|
||||||
BList* BMidi::Connections() const
|
|
||||||
{
|
{
|
||||||
return connections;
|
return fConnectionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BMidi::SnoozeUntil(uint32 time) const
|
void BMidi::SnoozeUntil(uint32 time) const
|
||||||
{
|
{
|
||||||
snooze_until((uint64) time * 1000, B_SYSTEM_TIMEBASE);
|
snooze_until((uint64)time*1000, B_SYSTEM_TIMEBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
bool BMidi::KeepRunning()
|
||||||
|
{
|
||||||
|
return fIsRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMidi::Run()
|
||||||
|
{
|
||||||
|
while(KeepRunning())
|
||||||
|
snooze(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Spray Functions
|
||||||
|
void BMidi::SprayMidiEvent(BMidiEvent *e) const
|
||||||
|
{
|
||||||
|
// TRACE(("Hello"))
|
||||||
|
int32 num_connections = fConnectionList->CountItems();
|
||||||
|
BMidi *m;
|
||||||
|
for(int32 i = 0; i < num_connections; i++)
|
||||||
|
{
|
||||||
|
m = (BMidi *)fConnectionList->ItemAt(i);
|
||||||
|
write_port(m->fInflowPort, MSG_CODE_PROCESS_EVENT, e, sizeof(BMidiEvent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayNoteOff(
|
void BMidi::SprayNoteOff(
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||||
@@ -143,7 +185,7 @@ void BMidi::SprayNoteOff(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayNoteOn(
|
void BMidi::SprayNoteOn(
|
||||||
uchar channel, uchar note, uchar velocity, uint32 time) const
|
uchar channel, uchar note, uchar velocity, uint32 time) const
|
||||||
@@ -157,7 +199,7 @@ void BMidi::SprayNoteOn(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayKeyPressure(
|
void BMidi::SprayKeyPressure(
|
||||||
uchar channel, uchar note, uchar pressure, uint32 time) const
|
uchar channel, uchar note, uchar pressure, uint32 time) const
|
||||||
@@ -171,7 +213,7 @@ void BMidi::SprayKeyPressure(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayControlChange(
|
void BMidi::SprayControlChange(
|
||||||
uchar channel, uchar controlNumber, uchar controlValue,
|
uchar channel, uchar controlNumber, uchar controlValue,
|
||||||
@@ -186,7 +228,7 @@ void BMidi::SprayControlChange(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayProgramChange(
|
void BMidi::SprayProgramChange(
|
||||||
uchar channel, uchar programNumber, uint32 time) const
|
uchar channel, uchar programNumber, uint32 time) const
|
||||||
@@ -199,7 +241,7 @@ void BMidi::SprayProgramChange(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayChannelPressure(
|
void BMidi::SprayChannelPressure(
|
||||||
uchar channel, uchar pressure, uint32 time) const
|
uchar channel, uchar pressure, uint32 time) const
|
||||||
@@ -212,7 +254,7 @@ void BMidi::SprayChannelPressure(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayPitchBend(
|
void BMidi::SprayPitchBend(
|
||||||
uchar channel, uchar lsb, uchar msb, uint32 time) const
|
uchar channel, uchar lsb, uchar msb, uint32 time) const
|
||||||
@@ -226,22 +268,22 @@ void BMidi::SprayPitchBend(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SpraySystemExclusive(
|
void BMidi::SpraySystemExclusive(
|
||||||
void* data, size_t dataLength, uint32 time) const
|
void * data, size_t dataLength, uint32 time) const
|
||||||
{
|
{
|
||||||
//TODO: Should this data be duplicated!!??
|
// Should this data be duplicated!!?? I think Yes.
|
||||||
|
|
||||||
BMidiEvent event;
|
BMidiEvent event;
|
||||||
event.time = time;
|
event.time = time;
|
||||||
event.opcode = BMidiEvent::OP_SYSTEM_EXCLUSIVE;
|
event.opcode = BMidiEvent::OP_SYSTEM_EXCLUSIVE;
|
||||||
event.systemExclusive.data = (uint8*) data;
|
event.systemExclusive.data = new uint8[dataLength];
|
||||||
|
memcpy(event.systemExclusive.data, data, dataLength);
|
||||||
event.systemExclusive.dataLength = dataLength;
|
event.systemExclusive.dataLength = dataLength;
|
||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SpraySystemCommon(
|
void BMidi::SpraySystemCommon(
|
||||||
uchar status, uchar data1, uchar data2, uint32 time) const
|
uchar status, uchar data1, uchar data2, uint32 time) const
|
||||||
@@ -255,7 +297,7 @@ void BMidi::SpraySystemCommon(
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SpraySystemRealTime(uchar status, uint32 time) const
|
void BMidi::SpraySystemRealTime(uchar status, uint32 time) const
|
||||||
{
|
{
|
||||||
@@ -266,7 +308,7 @@ void BMidi::SpraySystemRealTime(uchar status, uint32 time) const
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
|
void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
|
||||||
{
|
{
|
||||||
@@ -277,44 +319,20 @@ void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
|
|||||||
SprayMidiEvent(&event);
|
SprayMidiEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
// The Inflow Thread
|
||||||
bool BMidi::KeepRunning()
|
void BMidi::InflowTask()
|
||||||
{
|
|
||||||
return isRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BMidi::_ReservedMidi1() { }
|
|
||||||
void BMidi::_ReservedMidi2() { }
|
|
||||||
void BMidi::_ReservedMidi3() { }
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BMidi::Run()
|
|
||||||
{
|
|
||||||
while (KeepRunning())
|
|
||||||
{
|
|
||||||
snooze(50000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void BMidi::Inflow()
|
|
||||||
{
|
{
|
||||||
BMidiEvent event;
|
BMidiEvent event;
|
||||||
int32 code;
|
int32 code;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
while(true)
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
len = read_port(inflowPort, &code, &event, sizeof(event));
|
len = read_port(fInflowPort, &code, &event, sizeof(BMidiEvent));
|
||||||
|
|
||||||
if (code == MSG_CODE_TERMINATE_THREAD) { return; }
|
if (code == MSG_CODE_TERMINATE_THREAD) { return; }
|
||||||
|
|
||||||
if (len != sizeof(event)) { continue; } // ignore errors
|
if (len != sizeof(BMidiEvent)) { continue; } //ignore errors
|
||||||
|
|
||||||
switch (event.opcode)
|
switch (event.opcode)
|
||||||
{
|
{
|
||||||
@@ -332,7 +350,7 @@ void BMidi::Inflow()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BMidiEvent::OP_NOTE_ON:
|
case BMidiEvent::OP_NOTE_ON:
|
||||||
NoteOff(
|
NoteOn(
|
||||||
event.noteOn.channel,
|
event.noteOn.channel,
|
||||||
event.noteOn.note,
|
event.noteOn.note,
|
||||||
event.noteOn.velocity,
|
event.noteOn.velocity,
|
||||||
@@ -409,38 +427,41 @@ void BMidi::Inflow()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
//----------------------
|
||||||
|
|
||||||
void BMidi::SprayMidiEvent(BMidiEvent* event) const
|
void BMidi::_ReservedMidi1() {}
|
||||||
|
void BMidi::_ReservedMidi2() {}
|
||||||
|
void BMidi::_ReservedMidi3() {}
|
||||||
|
|
||||||
|
//----------------------
|
||||||
|
|
||||||
|
status_t _run_thread_(void *data)
|
||||||
{
|
{
|
||||||
TRACE(("[midi] BMidi::SprayMidiEvent, event time = %u, "
|
((BMidi*)data)->Run();
|
||||||
"current time = %u\n", event->time, B_NOW))
|
|
||||||
|
|
||||||
int32 count = connections->CountItems();
|
|
||||||
|
|
||||||
for (int32 i = 0; i < count; ++i)
|
|
||||||
{
|
|
||||||
write_port(
|
|
||||||
((BMidi*) connections->ItemAt(i))->inflowPort,
|
|
||||||
MSG_CODE_PROCESS_EVENT, event, sizeof(*event));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int32 BMidi::RunThread(void* data)
|
|
||||||
{
|
|
||||||
((BMidi*) data)->Run();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//----------------------
|
||||||
|
|
||||||
int32 BMidi::InflowThread(void* data)
|
status_t _inflow_task_(void * data)
|
||||||
{
|
{
|
||||||
((BMidi*) data)->Inflow();
|
((BMidi*)data)->InflowTask();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
//-----------------------------------------------
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ BMidiEvent::BMidiEvent()
|
|||||||
|
|
||||||
BMidiEvent::~BMidiEvent()
|
BMidiEvent::~BMidiEvent()
|
||||||
{
|
{
|
||||||
|
if (opcode == OP_SYSTEM_EXCLUSIVE)
|
||||||
|
delete systemExclusive.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -140,7 +140,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, 0);
|
local_source->SprayNoteOff(channel, note, velocity, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -148,7 +148,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, 0);
|
local_source->SprayNoteOn(channel, note, velocity, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
#include <MidiPortConsumer.h>
|
#include "MidiPortConsumer.h"
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
|
|||||||
+830
-303
File diff suppressed because it is too large
Load Diff
@@ -74,8 +74,8 @@ void Activity::Pulse(void)
|
|||||||
void Activity::NoteOn(uchar channel, uchar note,
|
void Activity::NoteOn(uchar channel, uchar note,
|
||||||
uchar velocity, uint32 time = B_NOW)
|
uchar velocity, uint32 time = B_NOW)
|
||||||
{//This function just update the variable
|
{//This function just update the variable
|
||||||
fActivity[channel - 1] = system_time();
|
fActivity[channel] = system_time();
|
||||||
BMidi::NoteOn(channel, note, velocity, time);
|
SprayNoteOn(channel, note, velocity, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user