code style update to match ours (kind of)

license header update
minor clean up


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17876 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2006-06-19 13:24:04 +00:00
parent 3639baa4b0
commit 4810cdcdbc
18 changed files with 785 additions and 992 deletions
+5 -5
View File
@@ -109,12 +109,12 @@ private:
virtual void Run(); virtual void Run();
BMidiLocalProducer* producer; BMidiLocalProducer* fProducer;
BMidiLocalConsumer* consumer; BMidiLocalConsumer* fConsumer;
BList* connections; BList* fConnections;
volatile thread_id threadId; volatile thread_id fThreadId;
volatile bool isRunning; volatile bool fIsRunning;
uint32 _reserved2[5]; uint32 _reserved2[5];
}; };
+7 -7
View File
@@ -75,14 +75,14 @@ private:
void ScanDevices(); void ScanDevices();
void EmptyDeviceList(); void EmptyDeviceList();
BMidiLocalProducer* localSource; BMidiLocalProducer* fLocalSource;
BMidiLocalConsumer* localSink; BMidiLocalConsumer* fLocalSink;
BMidiProducer* remoteSource; BMidiProducer* fRemoteSource;
BMidiConsumer* remoteSink; BMidiConsumer* fRemoteSink;
char* portName; char* fPortName;
status_t status; status_t fStatus;
BList* devices; BList* fDevices;
uint32 _reserved[1]; uint32 _reserved[1];
}; };
+18 -18
View File
@@ -85,12 +85,12 @@ private:
uint32 TicksToMilliseconds(uint32 ticks) const; uint32 TicksToMilliseconds(uint32 ticks) const;
uint32 MillisecondsToTicks(uint32 ms) const; uint32 MillisecondsToTicks(uint32 ms) const;
BList* events; BList* fEvents;
int32 currentEvent; int32 fCurrentEvent;
uint32 startTime; uint32 fStartTime;
int32 beatsPerMinute; int32 fBeatsPerMinute;
int16 ticksPerBeat; int16 fTicksPerBeat;
bool needsSorting; bool fNeedsSorting;
void ReadFourCC(char* fourcc); void ReadFourCC(char* fourcc);
uint32 Read32Bit(); uint32 Read32Bit();
@@ -112,21 +112,21 @@ private:
void WriteTrack(); void WriteTrack();
void WriteMetaEvent(BMidiEvent* event); void WriteMetaEvent(BMidiEvent* event);
BFile* file; BFile* fFile;
uint32 byteCount; uint32 fByteCount;
uint32 totalTicks; uint32 fTotalTicks;
uint16 numTracks; uint16 fNumTracks;
uint16 currTrack; uint16 fCurrTrack;
uint16 format; uint16 fFormat;
uint16 _reserved1[1]; uint16 _reserved1[1];
bool* instruments; bool* fInstruments;
synth_file_hook hookFunc; synth_file_hook fHookFunc;
int32 hookArg; int32 fHookArg;
bool looping; bool fLooping;
bool paused; bool fPaused;
bool finished; bool fFinished;
uint32 _reserved2[12]; uint32 _reserved2[12];
}; };
+3 -3
View File
@@ -80,9 +80,9 @@ private:
virtual void Run(); virtual void Run();
bigtime_t creationTime; bigtime_t fCreationTime;
int16 transpose; int16 fTranspose;
bool inputEnabled; bool fInputEnabled;
}; };
#endif // _MIDI_SYNTH_H #endif // _MIDI_SYNTH_H
+1 -1
View File
@@ -57,7 +57,7 @@ private:
virtual void _ReservedMidiSynthFile2(); virtual void _ReservedMidiSynthFile2();
virtual void _ReservedMidiSynthFile3(); virtual void _ReservedMidiSynthFile3();
BMidiStore* store; BMidiStore* fStore;
int32 _reserved[3]; int32 _reserved[3];
}; };
+2 -2
View File
@@ -53,9 +53,9 @@ private:
virtual void Run(); virtual void Run();
void WaitAndPrint(uint32 time); void _WaitAndPrint(uint32 time);
uint32 startTime; uint32 fStartTime;
uint32 _reserved[4]; uint32 _reserved[4];
}; };
+4 -4
View File
@@ -95,11 +95,11 @@ private:
virtual void _ReservedSynth3(); virtual void _ReservedSynth3();
virtual void _ReservedSynth4(); virtual void _ReservedSynth4();
void Init(); void _Init();
BPrivate::BSoftSynth* synth; BPrivate::BSoftSynth* fSynth;
synth_mode synthMode; synth_mode fSynthMode;
int32 clientCount; int32 fClientCount;
uint32 _reserved[10]; uint32 _reserved[10];
}; };
+124 -148
View File
@@ -1,372 +1,348 @@
/* /*
* Copyright (c) 2002-2003 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Michael Pfeiffer * Distributed under the terms of the MIT License.
* Copyright (c) 2002 Jerome Leveque
* Copyright (c) 2002 Paul Stadler
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Michael Pfeiffer
* and/or sell copies of the Software, and to permit persons to whom the * Jérôme Leveque
* Software is furnished to do so, subject to the following conditions: * Paul Stadler
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/ */
#include <List.h> #include <List.h>
#include <Midi.h>
#include <MidiProducer.h> #include <MidiProducer.h>
#include "Midi.h"
#include "MidiGlue.h" #include "MidiGlue.h"
#include "debug.h" #include "debug.h"
using namespace BPrivate; using namespace BPrivate;
//------------------------------------------------------------------------------
status_t _run_thread(void* data) status_t
_run_thread(void* data)
{ {
BMidi* midi = (BMidi*) data; BMidi* midi = (BMidi*) data;
midi->Run(); midi->Run();
midi->isRunning = false; midi->fIsRunning = false;
return 0; return 0;
} }
//------------------------------------------------------------------------------
BMidi::BMidi() BMidi::BMidi()
{ {
connections = new BList; fConnections = new BList;
threadId = -1; fThreadId = -1;
isRunning = false; fIsRunning = false;
producer = new BMidiLocalProducer("MidiGlue(out)"); fProducer = new BMidiLocalProducer("MidiGlue(out)");
consumer = new BMidiGlue(this, "MidiGlue(in)"); fConsumer = new BMidiGlue(this, "MidiGlue(in)");
} }
//------------------------------------------------------------------------------
BMidi::~BMidi() BMidi::~BMidi()
{ {
Stop(); Stop();
status_t result; status_t result;
wait_for_thread(threadId, &result); wait_for_thread(fThreadId, &result);
producer->Release(); fProducer->Release();
consumer->Release(); fConsumer->Release();
delete connections; delete fConnections;
} }
//------------------------------------------------------------------------------
void BMidi::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time) void
BMidi::NoteOff(uchar channel, uchar note, uchar velocity, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time) void
BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::KeyPressure( void
BMidi::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) uchar channel, uchar note, uchar pressure, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::ControlChange( void
BMidi::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time) void
BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time) void
BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) void
BMidi::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::SystemExclusive(void* data, size_t length, uint32 time) void
BMidi::SystemExclusive(void* data, size_t length, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::SystemCommon(uchar status, uchar data1, uchar data2, uint32 time) void
BMidi::SystemCommon(uchar status, uchar data1, uchar data2, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::SystemRealTime(uchar status, uint32 time) void
BMidi::SystemRealTime(uchar status, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::TempoChange(int32 beatsPerMinute, uint32 time) void
BMidi::TempoChange(int32 beatsPerMinute, uint32 time)
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::AllNotesOff(bool justChannel, uint32 time) void
BMidi::AllNotesOff(bool justChannel, uint32 time)
{ {
for (uchar channel = 1; channel <= 16; ++channel) for (uchar channel = 1; channel <= 16; ++channel) {
{
SprayControlChange(channel, B_ALL_NOTES_OFF, 0, time); SprayControlChange(channel, B_ALL_NOTES_OFF, 0, time);
if (!justChannel) if (!justChannel) {
{ for (uchar note = 0; note <= 0x7F; ++note) {
for (uchar note = 0; note <= 0x7F; ++note)
{
SprayNoteOff(channel, note, 0, time); SprayNoteOff(channel, note, 0, time);
} }
} }
} }
} }
//------------------------------------------------------------------------------
status_t BMidi::Start() status_t
BMidi::Start()
{ {
if (isRunning) { return B_OK; } if (fIsRunning)
return B_OK;
status_t err = spawn_thread( status_t err = spawn_thread(
_run_thread, "MidiRunThread", B_URGENT_PRIORITY, this); _run_thread, "MidiRunThread", B_URGENT_PRIORITY, this);
if (err < B_OK) { return err; } if (err < B_OK)
return err;
threadId = err; fThreadId = err;
isRunning = true; fIsRunning = true;
err = resume_thread(threadId); err = resume_thread(fThreadId);
if (err != B_OK) if (err != B_OK) {
{ fThreadId = -1;
threadId = -1; fIsRunning = false;
isRunning = false;
} }
return err; return err;
} }
//------------------------------------------------------------------------------
void BMidi::Stop() void
BMidi::Stop()
{ {
threadId = -1; fThreadId = -1;
} }
//------------------------------------------------------------------------------
bool BMidi::IsRunning() const bool
BMidi::IsRunning() const
{ {
return isRunning; return fIsRunning;
} }
//------------------------------------------------------------------------------
void BMidi::Connect(BMidi* toObject) void
BMidi::Connect(BMidi* toObject)
{ {
if (toObject != NULL) if (toObject != NULL) {
{ if (fProducer->Connect(toObject->fConsumer) == B_OK) {
if (producer->Connect(toObject->consumer) == B_OK) fConnections->AddItem(toObject);
{
connections->AddItem(toObject);
} }
} }
} }
//------------------------------------------------------------------------------
void BMidi::Disconnect(BMidi* fromObject) void
BMidi::Disconnect(BMidi* fromObject)
{ {
if (fromObject != NULL) if (fromObject == NULL)
{ return;
if (producer->Disconnect(fromObject->consumer) == B_OK)
{ if (fProducer->Disconnect(fromObject->fConsumer) == B_OK) {
connections->RemoveItem(fromObject); fConnections->RemoveItem(fromObject);
}
} }
} }
//------------------------------------------------------------------------------
bool BMidi::IsConnected(BMidi* toObject) const bool
BMidi::IsConnected(BMidi* toObject) const
{ {
if (toObject != NULL) if (toObject != NULL)
{ return fProducer->IsConnected(toObject->fConsumer);
return producer->IsConnected(toObject->consumer);
}
return false; return false;
} }
//------------------------------------------------------------------------------
BList* BMidi::Connections() const BList*
BMidi::Connections() const
{ {
return connections; return fConnections;
} }
//------------------------------------------------------------------------------
void BMidi::SnoozeUntil(uint32 time) const void
BMidi::SnoozeUntil(uint32 time) const
{ {
snooze_until(MAKE_BIGTIME(time), B_SYSTEM_TIMEBASE); snooze_until(MAKE_BIGTIME(time), B_SYSTEM_TIMEBASE);
} }
//------------------------------------------------------------------------------
bool BMidi::KeepRunning() bool
BMidi::KeepRunning()
{ {
return (threadId != -1); return (fThreadId != -1);
} }
//------------------------------------------------------------------------------
void BMidi::_ReservedMidi1() {} void BMidi::_ReservedMidi1() {}
void BMidi::_ReservedMidi2() {} void BMidi::_ReservedMidi2() {}
void BMidi::_ReservedMidi3() {} void BMidi::_ReservedMidi3() {}
//------------------------------------------------------------------------------
void BMidi::Run() void
BMidi::Run()
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidi::SprayNoteOff( void
BMidi::SprayNoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) const uchar channel, uchar note, uchar velocity, uint32 time) const
{ {
producer->SprayNoteOff( fProducer->SprayNoteOff(
channel - 1, note, velocity, MAKE_BIGTIME(time)); channel - 1, note, velocity, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayNoteOn( void
BMidi::SprayNoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) const uchar channel, uchar note, uchar velocity, uint32 time) const
{ {
producer->SprayNoteOn( fProducer->SprayNoteOn(
channel - 1, note, velocity, MAKE_BIGTIME(time)); channel - 1, note, velocity, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayKeyPressure( void
BMidi::SprayKeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) const uchar channel, uchar note, uchar pressure, uint32 time) const
{ {
producer->SprayKeyPressure( fProducer->SprayKeyPressure(
channel - 1, note, pressure, MAKE_BIGTIME(time)); channel - 1, note, pressure, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayControlChange( void
BMidi::SprayControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uchar channel, uchar controlNumber, uchar controlValue,
uint32 time) const uint32 time) const
{ {
producer->SprayControlChange( fProducer->SprayControlChange(
channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time)); channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayProgramChange( void
BMidi::SprayProgramChange(
uchar channel, uchar programNumber, uint32 time) const uchar channel, uchar programNumber, uint32 time) const
{ {
producer->SprayProgramChange( fProducer->SprayProgramChange(
channel - 1, programNumber, MAKE_BIGTIME(time)); channel - 1, programNumber, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayChannelPressure( void
BMidi::SprayChannelPressure(
uchar channel, uchar pressure, uint32 time) const uchar channel, uchar pressure, uint32 time) const
{ {
producer->SprayChannelPressure( fProducer->SprayChannelPressure(
channel - 1, pressure, MAKE_BIGTIME(time)); channel - 1, pressure, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayPitchBend( void
BMidi::SprayPitchBend(
uchar channel, uchar lsb, uchar msb, uint32 time) const uchar channel, uchar lsb, uchar msb, uint32 time) const
{ {
producer->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time)); fProducer->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SpraySystemExclusive( void
BMidi::SpraySystemExclusive(
void* data, size_t length, uint32 time) const void* data, size_t length, uint32 time) const
{ {
producer->SpraySystemExclusive(data, length, MAKE_BIGTIME(time)); fProducer->SpraySystemExclusive(data, length, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SpraySystemCommon( void
BMidi::SpraySystemCommon(
uchar status, uchar data1, uchar data2, uint32 time) const uchar status, uchar data1, uchar data2, uint32 time) const
{ {
producer->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time)); fProducer->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SpraySystemRealTime(uchar status, uint32 time) const void
BMidi::SpraySystemRealTime(uchar status, uint32 time) const
{ {
producer->SpraySystemRealTime(status, MAKE_BIGTIME(time)); fProducer->SpraySystemRealTime(status, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const void
BMidi::SprayTempoChange(int32 beatsPerMinute, uint32 time) const
{ {
producer->SprayTempoChange(beatsPerMinute, MAKE_BIGTIME(time)); fProducer->SprayTempoChange(beatsPerMinute, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
+77 -93
View File
@@ -1,222 +1,206 @@
/* /*
* Copyright (c) 2003 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Jerome Leveque * Distributed under the terms of the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* 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 <Midi.h>
#include "MidiGlue.h" #include "MidiGlue.h"
#include "MidiPort.h" #include <MidiPort.h>
using namespace BPrivate; using namespace BPrivate;
//------------------------------------------------------------------------------
BMidiGlue::BMidiGlue(BMidi* midiObject_, const char* name) BMidiGlue::BMidiGlue(BMidi* midiObject_, const char* name)
: BMidiLocalConsumer(name) : BMidiLocalConsumer(name)
{ {
midiObject = midiObject_; fMidiObject = midiObject_;
} }
//------------------------------------------------------------------------------
void BMidiGlue::NoteOff( void
BMidiGlue::NoteOff(
uchar channel, uchar note, uchar velocity, bigtime_t time) uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiObject->NoteOff(channel + 1, note, velocity, MAKE_TIME(time)); fMidiObject->NoteOff(channel + 1, note, velocity, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::NoteOn( void
BMidiGlue::NoteOn(
uchar channel, uchar note, uchar velocity, bigtime_t time) uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiObject->NoteOn(channel + 1, note, velocity, MAKE_TIME(time)); fMidiObject->NoteOn(channel + 1, note, velocity, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::KeyPressure( void
BMidiGlue::KeyPressure(
uchar channel, uchar note, uchar pressure, bigtime_t time) uchar channel, uchar note, uchar pressure, bigtime_t time)
{ {
midiObject->KeyPressure(channel + 1, note, pressure, MAKE_TIME(time)); fMidiObject->KeyPressure(channel + 1, note, pressure, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::ControlChange( void
BMidiGlue::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time) uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
{ {
midiObject->ControlChange( fMidiObject->ControlChange(
channel + 1, controlNumber, controlValue, MAKE_TIME(time)); channel + 1, controlNumber, controlValue, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::ProgramChange( void
BMidiGlue::ProgramChange(
uchar channel, uchar programNumber, bigtime_t time) uchar channel, uchar programNumber, bigtime_t time)
{ {
midiObject->ProgramChange(channel + 1, programNumber, MAKE_TIME(time)); fMidiObject->ProgramChange(channel + 1, programNumber, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::ChannelPressure( void
BMidiGlue::ChannelPressure(
uchar channel, uchar pressure, bigtime_t time) uchar channel, uchar pressure, bigtime_t time)
{ {
midiObject->ChannelPressure(channel + 1, pressure, MAKE_TIME(time)); fMidiObject->ChannelPressure(channel + 1, pressure, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::PitchBend( void
BMidiGlue::PitchBend(
uchar channel, uchar lsb, uchar msb, bigtime_t time) uchar channel, uchar lsb, uchar msb, bigtime_t time)
{ {
midiObject->PitchBend(channel + 1, lsb, msb, MAKE_TIME(time)); fMidiObject->PitchBend(channel + 1, lsb, msb, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::SystemExclusive( void
BMidiGlue::SystemExclusive(
void* data, size_t length, bigtime_t time) void* data, size_t length, bigtime_t time)
{ {
midiObject->SystemExclusive(data, length, MAKE_TIME(time)); fMidiObject->SystemExclusive(data, length, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::SystemCommon( void
BMidiGlue::SystemCommon(
uchar status, uchar data1, uchar data2, bigtime_t time) uchar status, uchar data1, uchar data2, bigtime_t time)
{ {
midiObject->SystemCommon(status, data1, data2, MAKE_TIME(time)); fMidiObject->SystemCommon(status, data1, data2, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::SystemRealTime(uchar status, bigtime_t time) void
BMidiGlue::SystemRealTime(uchar status, bigtime_t time)
{ {
midiObject->SystemRealTime(status, MAKE_TIME(time)); fMidiObject->SystemRealTime(status, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiGlue::TempoChange(int32 beatsPerMinute, bigtime_t time) void
BMidiGlue::TempoChange(int32 beatsPerMinute, bigtime_t time)
{ {
midiObject->TempoChange(beatsPerMinute, MAKE_TIME(time)); fMidiObject->TempoChange(beatsPerMinute, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
BMidiPortGlue::BMidiPortGlue(BMidiPort* midiObject_, const char* name) BMidiPortGlue::BMidiPortGlue(BMidiPort* midiObject_, const char* name)
: BMidiLocalConsumer(name) : BMidiLocalConsumer(name)
{ {
midiObject = midiObject_; fMidiObject = midiObject_;
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::NoteOff( void
BMidiPortGlue::NoteOff(
uchar channel, uchar note, uchar velocity, bigtime_t time) uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiObject->SprayNoteOff(channel + 1, note, velocity, MAKE_TIME(time)); fMidiObject->SprayNoteOff(channel + 1, note, velocity, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::NoteOn( void
BMidiPortGlue::NoteOn(
uchar channel, uchar note, uchar velocity, bigtime_t time) uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiObject->SprayNoteOn(channel + 1, note, velocity, MAKE_TIME(time)); fMidiObject->SprayNoteOn(channel + 1, note, velocity, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::KeyPressure( void
BMidiPortGlue::KeyPressure(
uchar channel, uchar note, uchar pressure, bigtime_t time) uchar channel, uchar note, uchar pressure, bigtime_t time)
{ {
midiObject->SprayKeyPressure( fMidiObject->SprayKeyPressure(
channel + 1, note, pressure, MAKE_TIME(time)); channel + 1, note, pressure, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::ControlChange( void
BMidiPortGlue::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time) uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time)
{ {
midiObject->SprayControlChange( fMidiObject->SprayControlChange(
channel + 1, controlNumber, controlValue, MAKE_TIME(time)); channel + 1, controlNumber, controlValue, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::ProgramChange( void
BMidiPortGlue::ProgramChange(
uchar channel, uchar programNumber, bigtime_t time) uchar channel, uchar programNumber, bigtime_t time)
{ {
midiObject->SprayProgramChange( fMidiObject->SprayProgramChange(
channel + 1, programNumber, MAKE_TIME(time)); channel + 1, programNumber, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::ChannelPressure( void
BMidiPortGlue::ChannelPressure(
uchar channel, uchar pressure, bigtime_t time) uchar channel, uchar pressure, bigtime_t time)
{ {
midiObject->SprayChannelPressure(channel + 1, pressure, MAKE_TIME(time)); fMidiObject->SprayChannelPressure(channel + 1, pressure, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::PitchBend( void
BMidiPortGlue::PitchBend(
uchar channel, uchar lsb, uchar msb, bigtime_t time) uchar channel, uchar lsb, uchar msb, bigtime_t time)
{ {
midiObject->SprayPitchBend(channel + 1, lsb, msb, MAKE_TIME(time)); fMidiObject->SprayPitchBend(channel + 1, lsb, msb, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::SystemExclusive( void
BMidiPortGlue::SystemExclusive(
void* data, size_t length, bigtime_t time) void* data, size_t length, bigtime_t time)
{ {
midiObject->SpraySystemExclusive(data, length, MAKE_TIME(time)); fMidiObject->SpraySystemExclusive(data, length, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::SystemCommon( void
BMidiPortGlue::SystemCommon(
uchar status, uchar data1, uchar data2, bigtime_t time) uchar status, uchar data1, uchar data2, bigtime_t time)
{ {
midiObject->SpraySystemCommon(status, data1, data2, MAKE_TIME(time)); fMidiObject->SpraySystemCommon(status, data1, data2, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::SystemRealTime(uchar status, bigtime_t time) void
BMidiPortGlue::SystemRealTime(uchar status, bigtime_t time)
{ {
midiObject->SpraySystemRealTime(status, MAKE_TIME(time)); fMidiObject->SpraySystemRealTime(status, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPortGlue::TempoChange(int32 beatsPerMinute, bigtime_t time) void
BMidiPortGlue::TempoChange(int32 beatsPerMinute, bigtime_t time)
{ {
midiObject->SprayTempoChange(beatsPerMinute, MAKE_TIME(time)); fMidiObject->SprayTempoChange(beatsPerMinute, MAKE_TIME(time));
} }
//------------------------------------------------------------------------------
+8 -21
View File
@@ -1,24 +1,11 @@
/* /*
* Copyright (c) 2003 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Jerome Leveque * Distributed under the terms of the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* 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 #ifndef _MIDI_GLUE_H
@@ -72,7 +59,7 @@ public:
private: private:
BMidi* midiObject; BMidi* fMidiObject;
}; };
class BMidiPortGlue: public BMidiLocalConsumer class BMidiPortGlue: public BMidiLocalConsumer
@@ -115,7 +102,7 @@ public:
private: private:
BMidiPort* midiObject; BMidiPort* fMidiObject;
}; };
} // namespace BPrivate } // namespace BPrivate
+119 -170
View File
@@ -1,354 +1,303 @@
/* /*
* Copyright (c) 2002-2003 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Jerome Leveque * Distributed under the terms of the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* 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 <MidiPort.h>
#include <MidiProducer.h> #include <MidiProducer.h>
#include <MidiRoster.h> #include <MidiRoster.h>
#include <stdlib.h> #include <stdlib.h>
#include "debug.h" #include "debug.h"
#include "MidiPort.h"
#include "MidiGlue.h" #include "MidiGlue.h"
using namespace BPrivate; using namespace BPrivate;
//------------------------------------------------------------------------------
BMidiPort::BMidiPort(const char* name) BMidiPort::BMidiPort(const char* name)
{ {
portName = NULL; fPortName = NULL;
devices = new BList; fDevices = new BList;
status = B_ERROR; fStatus = B_ERROR;
localSource = new BMidiLocalProducer("MidiPortGlue(out)"); fLocalSource = new BMidiLocalProducer("MidiPortGlue(out)");
localSink = new BMidiPortGlue(this, "MidiPortGlue(in)"); fLocalSink = new BMidiPortGlue(this, "MidiPortGlue(in)");
remoteSource = NULL; fRemoteSource = NULL;
remoteSink = NULL; fRemoteSink = NULL;
ScanDevices(); ScanDevices();
if (name != NULL) if (name != NULL)
{
Open(name); Open(name);
}
} }
//------------------------------------------------------------------------------
BMidiPort::~BMidiPort() BMidiPort::~BMidiPort()
{ {
Close(); Close();
EmptyDeviceList(); EmptyDeviceList();
delete devices; delete fDevices;
localSource->Release(); fLocalSource->Release();
localSink->Release(); fLocalSink->Release();
} }
//------------------------------------------------------------------------------
status_t BMidiPort::InitCheck() const status_t
BMidiPort::InitCheck() const
{ {
return status; return fStatus;
} }
//------------------------------------------------------------------------------
status_t BMidiPort::Open(const char* name) status_t
BMidiPort::Open(const char* name)
{ {
status = B_ERROR; fStatus = B_ERROR;
if (name != NULL) if (name != NULL) {
{
Close(); Close();
for (int32 t = 0; t < devices->CountItems(); ++t) for (int32 t = 0; t < fDevices->CountItems(); ++t) {
{ BMidiEndpoint* endp = (BMidiEndpoint*) fDevices->ItemAt(t);
BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(t); if (strcmp(name, endp->Name()) != 0)
if (strcmp(name, endp->Name()) == 0) continue;
{ if (!endp->IsValid()) // still exists?
if (endp->IsValid()) // still exists? continue;
{ if (endp->IsProducer()) {
if (endp->IsProducer()) if (fRemoteSource == NULL)
{ fRemoteSource = (BMidiProducer*) endp;
if (remoteSource == NULL) } else {
{ if (fRemoteSink == NULL) {
remoteSource = (BMidiProducer*) endp; fRemoteSink = (BMidiConsumer*) endp;
} fLocalSource->Connect(fRemoteSink);
}
else if (endp->IsConsumer())
{
if (remoteSink == NULL)
{
remoteSink = (BMidiConsumer*) endp;
localSource->Connect(remoteSink);
}
}
} }
} }
} }
if (remoteSource != NULL) if (fRemoteSource != NULL) {
{ fPortName = strdup(fRemoteSource->Name());
portName = strdup(remoteSource->Name()); fStatus = B_OK;
status = B_OK; } else if (fRemoteSink != NULL) {
} fPortName = strdup(fRemoteSink->Name());
else if (remoteSink != NULL) fStatus = B_OK;
{
portName = strdup(remoteSink->Name());
status = B_OK;
} }
} }
return status; return fStatus;
} }
//------------------------------------------------------------------------------
void BMidiPort::Close() void
BMidiPort::Close()
{ {
if (remoteSource != NULL) if (fRemoteSource != NULL) {
{ fRemoteSource->Disconnect(fLocalSink);
remoteSource->Disconnect(localSink); fRemoteSource = NULL;
remoteSource = NULL;
} }
if (remoteSink != NULL) if (fRemoteSink != NULL) {
{ fLocalSource->Disconnect(fRemoteSink);
localSource->Disconnect(remoteSink); fRemoteSink = NULL;
remoteSink = NULL;
} }
if (portName != NULL) if (fPortName != NULL) {
{ free(fPortName);
free(portName); fPortName = NULL;
portName = NULL;
} }
} }
//------------------------------------------------------------------------------
const char* BMidiPort::PortName() const const char*
BMidiPort::PortName() const
{ {
return portName; return fPortName;
} }
//------------------------------------------------------------------------------
void BMidiPort::NoteOff( void
BMidiPort::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
localSource->SprayNoteOff(channel - 1, note, velocity, MAKE_BIGTIME(time)); fLocalSource->SprayNoteOff(channel - 1, note, velocity, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::NoteOn( void
BMidiPort::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
localSource->SprayNoteOn(channel - 1, note, velocity, MAKE_BIGTIME(time)); fLocalSource->SprayNoteOn(channel - 1, note, velocity, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::KeyPressure( void
BMidiPort::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) uchar channel, uchar note, uchar pressure, uint32 time)
{ {
localSource->SprayKeyPressure( fLocalSource->SprayKeyPressure(
channel - 1, note, pressure, MAKE_BIGTIME(time)); channel - 1, note, pressure, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::ControlChange( void
BMidiPort::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
localSource->SprayControlChange( fLocalSource->SprayControlChange(
channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time)); channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::ProgramChange( void
BMidiPort::ProgramChange(
uchar channel, uchar programNumber, uint32 time) uchar channel, uchar programNumber, uint32 time)
{ {
localSource->SprayProgramChange( fLocalSource->SprayProgramChange(
channel - 1, programNumber, MAKE_BIGTIME(time)); channel - 1, programNumber, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time) void
BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
localSource->SprayChannelPressure( fLocalSource->SprayChannelPressure(
channel - 1, pressure, MAKE_BIGTIME(time)); 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)
{ {
localSource->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time)); fLocalSource->SprayPitchBend(channel - 1, lsb, msb, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::SystemExclusive(void* data, size_t length, uint32 time) void
BMidiPort::SystemExclusive(void* data, size_t length, uint32 time)
{ {
localSource->SpraySystemExclusive(data, length, MAKE_BIGTIME(time)); fLocalSource->SpraySystemExclusive(data, length, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::SystemCommon( void
BMidiPort::SystemCommon(
uchar status, uchar data1, uchar data2, uint32 time) uchar status, uchar data1, uchar data2, uint32 time)
{ {
localSource->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time)); fLocalSource->SpraySystemCommon(status, data1, data2, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
void BMidiPort::SystemRealTime(uchar status, uint32 time) void
BMidiPort::SystemRealTime(uchar status, uint32 time)
{ {
localSource->SpraySystemRealTime(status, MAKE_BIGTIME(time)); fLocalSource->SpraySystemRealTime(status, MAKE_BIGTIME(time));
} }
//------------------------------------------------------------------------------
status_t BMidiPort::Start() status_t
BMidiPort::Start()
{ {
status_t err = super::Start(); status_t err = super::Start();
if ((err == B_OK) && (remoteSource != NULL)) if ((err == B_OK) && (fRemoteSource != NULL)) {
{ return fRemoteSource->Connect(fLocalSink);
return remoteSource->Connect(localSink);
} }
return err; return err;
} }
//------------------------------------------------------------------------------
void BMidiPort::Stop() void
BMidiPort::Stop()
{ {
if (remoteSource != NULL) if (fRemoteSource != NULL) {
{ fRemoteSource->Disconnect(fLocalSink);
remoteSource->Disconnect(localSink);
} }
super::Stop(); super::Stop();
} }
//------------------------------------------------------------------------------
int32 BMidiPort::CountDevices() int32
BMidiPort::CountDevices()
{ {
return devices->CountItems(); return fDevices->CountItems();
} }
//------------------------------------------------------------------------------
status_t BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize) status_t
BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize)
{ {
BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(n); BMidiEndpoint* endp = (BMidiEndpoint*) fDevices->ItemAt(n);
if (endp == NULL) if (endp == NULL)
{
return B_BAD_VALUE; return B_BAD_VALUE;
}
size_t size = strlen(endp->Name()); size_t size = strlen(endp->Name());
if (size >= bufSize) if (size >= bufSize)
{
return B_NAME_TOO_LONG; return B_NAME_TOO_LONG;
}
strcpy(name, endp->Name()); strcpy(name, endp->Name());
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------
void BMidiPort::_ReservedMidiPort1() { } void BMidiPort::_ReservedMidiPort1() { }
void BMidiPort::_ReservedMidiPort2() { } void BMidiPort::_ReservedMidiPort2() { }
void BMidiPort::_ReservedMidiPort3() { } void BMidiPort::_ReservedMidiPort3() { }
//------------------------------------------------------------------------------
void BMidiPort::Run() void
BMidiPort::Run()
{ {
while (KeepRunning()) while (KeepRunning())
{
snooze(50000); snooze(50000);
}
} }
//------------------------------------------------------------------------------
void BMidiPort::ScanDevices() void
BMidiPort::ScanDevices()
{ {
EmptyDeviceList(); EmptyDeviceList();
int32 id = 0; int32 id = 0;
BMidiEndpoint* endp; BMidiEndpoint* endp;
while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL) while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL) {
{
// Each hardware port has two endpoints associated with it, a consumer // Each hardware port has two endpoints associated with it, a consumer
// and a producer. Both have the same name, so we add only one of them. // and a producer. Both have the same name, so we add only one of them.
bool addItem = true; bool addItem = true;
for (int32 t = 0; t < devices->CountItems(); ++t) for (int32 t = 0; t < fDevices->CountItems(); ++t) {
{ BMidiEndpoint* other = (BMidiEndpoint*) fDevices->ItemAt(t);
BMidiEndpoint* other = (BMidiEndpoint*) devices->ItemAt(t); if (strcmp(endp->Name(), other->Name()) == 0) {
if (strcmp(endp->Name(), other->Name()) == 0)
{
addItem = false; addItem = false;
break; break;
} }
} }
if (addItem) if (addItem) {
{ fDevices->AddItem(endp);
devices->AddItem(endp); } else {
}
else
{
endp->Release(); endp->Release();
} }
} }
} }
//------------------------------------------------------------------------------
void BMidiPort::EmptyDeviceList() void
BMidiPort::EmptyDeviceList()
{ {
for (int32 t = 0; t < devices->CountItems(); ++t) for (int32 t = 0; t < fDevices->CountItems(); ++t)
{ ((BMidiEndpoint*) fDevices->ItemAt(t))->Release();
((BMidiEndpoint*) devices->ItemAt(t))->Release();
}
devices->MakeEmpty(); fDevices->MakeEmpty();
} }
//------------------------------------------------------------------------------
+108 -124
View File
@@ -1,37 +1,23 @@
/* /*
* Copyright (c) 2002-2004 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Jerome Leveque * Distributed under the terms of the MIT License.
* Copyright (c) 2002 Paul Stadler
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* and/or sell copies of the Software, and to permit persons to whom the * Paul Stadler
* 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 <File.h> #include <File.h>
#include <List.h> #include <List.h>
#include <MidiDefs.h>
#include <MidiStore.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "MidiDefs.h"
#include "MidiStore.h"
#include "debug.h" #include "debug.h"
//------------------------------------------------------------------------------
struct BMidiEvent { struct BMidiEvent {
BMidiEvent() BMidiEvent()
@@ -74,29 +60,29 @@ compare_events(const void* event1, const void* event2)
BMidiStore::BMidiStore() BMidiStore::BMidiStore()
{ {
events = new BList; fEvents = new BList;
currentEvent = 0; fCurrentEvent = 0;
startTime = 0; fStartTime = 0;
needsSorting = false; fNeedsSorting = false;
beatsPerMinute = 60; fBeatsPerMinute = 60;
ticksPerBeat = 240; fTicksPerBeat = 240;
file = NULL; fFile = NULL;
hookFunc = NULL; fHookFunc = NULL;
looping = false; fLooping = false;
paused = false; fPaused = false;
finished = false; fFinished = false;
instruments = new bool[128]; fInstruments = new bool[128];
} }
BMidiStore::~BMidiStore() BMidiStore::~BMidiStore()
{ {
for (int32 t = 0; t < events->CountItems(); ++t) { for (int32 t = 0; t < fEvents->CountItems(); ++t) {
delete EventAt(t); delete EventAt(t);
} }
delete events; delete fEvents;
delete[] instruments; delete[] fInstruments;
} }
@@ -250,12 +236,12 @@ BMidiStore::TempoChange(int32 beatsPerMinute, uint32 time)
status_t status_t
BMidiStore::Import(const entry_ref* ref) BMidiStore::Import(const entry_ref* ref)
{ {
memset(instruments, 0, 128 * sizeof(bool)); memset(fInstruments, 0, 128 * sizeof(bool));
try { try {
file = new BFile(ref, B_READ_ONLY); fFile = new BFile(ref, B_READ_ONLY);
if (file->InitCheck() != B_OK) if (fFile->InitCheck() != B_OK)
throw file->InitCheck(); throw fFile->InitCheck();
char fourcc[4]; char fourcc[4];
ReadFourCC(fourcc); ReadFourCC(fourcc);
@@ -265,30 +251,30 @@ BMidiStore::Import(const entry_ref* ref)
if (Read32Bit() != 6) if (Read32Bit() != 6)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
format = Read16Bit(); fFormat = Read16Bit();
numTracks = Read16Bit(); fNumTracks = Read16Bit();
ticksPerBeat = Read16Bit(); fTicksPerBeat = Read16Bit();
if (ticksPerBeat & 0x8000) { if (fTicksPerBeat & 0x8000) {
// we don't support SMPTE time codes, // we don't support SMPTE time codes,
// only ticks per quarter note // only ticks per quarter note
ticksPerBeat = 240; fTicksPerBeat = 240;
} }
currTrack = 0; fCurrTrack = 0;
while (currTrack < numTracks) { while (fCurrTrack < fNumTracks) {
ReadChunk(); ReadChunk();
} }
} catch (status_t e) { } catch (status_t e) {
delete file; delete fFile;
file = NULL; fFile = NULL;
return e; return e;
} }
SortEvents(true); SortEvents(true);
delete file; delete fFile;
file = NULL; fFile = NULL;
return B_OK; return B_OK;
} }
@@ -297,9 +283,9 @@ status_t
BMidiStore::Export(const entry_ref* ref, int32 format) BMidiStore::Export(const entry_ref* ref, int32 format)
{ {
try { try {
file = new BFile(ref, B_READ_WRITE); fFile = new BFile(ref, B_READ_WRITE);
if (file->InitCheck() != B_OK) if (fFile->InitCheck() != B_OK)
throw file->InitCheck(); throw fFile->InitCheck();
SortEvents(true); SortEvents(true);
@@ -307,17 +293,17 @@ BMidiStore::Export(const entry_ref* ref, int32 format)
Write32Bit(6); Write32Bit(6);
Write16Bit(0); // we do only format 0 Write16Bit(0); // we do only format 0
Write16Bit(1); Write16Bit(1);
Write16Bit(ticksPerBeat); Write16Bit(fTicksPerBeat);
WriteTrack(); WriteTrack();
} catch (status_t e) { } catch (status_t e) {
delete file; delete fFile;
file = NULL; fFile = NULL;
return e; return e;
} }
delete file; delete fFile;
file = NULL; fFile = NULL;
return B_OK; return B_OK;
} }
@@ -325,9 +311,9 @@ BMidiStore::Export(const entry_ref* ref, int32 format)
void void
BMidiStore::SortEvents(bool force) BMidiStore::SortEvents(bool force)
{ {
if (force || needsSorting) { if (force || fNeedsSorting) {
events->SortItems(compare_events); fEvents->SortItems(compare_events);
needsSorting = false; fNeedsSorting = false;
} }
} }
@@ -335,21 +321,21 @@ BMidiStore::SortEvents(bool force)
uint32 uint32
BMidiStore::CountEvents() const BMidiStore::CountEvents() const
{ {
return events->CountItems(); return fEvents->CountItems();
} }
uint32 uint32
BMidiStore::CurrentEvent() const BMidiStore::CurrentEvent() const
{ {
return currentEvent; return fCurrentEvent;
} }
void void
BMidiStore::SetCurrentEvent(uint32 eventNumber) BMidiStore::SetCurrentEvent(uint32 eventNumber)
{ {
currentEvent = eventNumber; fCurrentEvent = eventNumber;
} }
@@ -373,7 +359,7 @@ BMidiStore::DeltaOfEvent(uint32 eventNumber) const
uint32 uint32
BMidiStore::EventAtDelta(uint32 time) const BMidiStore::EventAtDelta(uint32 time) const
{ {
for (int32 t = 0; t < events->CountItems(); ++t) { for (int32 t = 0; t < fEvents->CountItems(); ++t) {
if (GetEventTime(EventAt(t)) >= time) if (GetEventTime(EventAt(t)) >= time)
return t; return t;
} }
@@ -385,30 +371,28 @@ BMidiStore::EventAtDelta(uint32 time) const
uint32 uint32
BMidiStore::BeginTime() const BMidiStore::BeginTime() const
{ {
return startTime; return fStartTime;
} }
void void
BMidiStore::SetTempo(int32 beatsPerMinute_) BMidiStore::SetTempo(int32 beatsPerMinute_)
{ {
beatsPerMinute = beatsPerMinute_; fBeatsPerMinute = beatsPerMinute_;
} }
int32 int32
BMidiStore::Tempo() const BMidiStore::Tempo() const
{ {
return beatsPerMinute; return fBeatsPerMinute;
} }
//------------------------------------------------------------------------------
void BMidiStore::_ReservedMidiStore1() { } void BMidiStore::_ReservedMidiStore1() { }
void BMidiStore::_ReservedMidiStore2() { } void BMidiStore::_ReservedMidiStore2() { }
void BMidiStore::_ReservedMidiStore3() { } void BMidiStore::_ReservedMidiStore3() { }
//------------------------------------------------------------------------------
void void
BMidiStore::Run() BMidiStore::Run()
@@ -417,8 +401,8 @@ BMidiStore::Run()
// but also by BMidiSynthFile. The "paused", "finished", and "looping" // but also by BMidiSynthFile. The "paused", "finished", and "looping"
// flags, and the "stop hook" are especially provided for the latter. // flags, and the "stop hook" are especially provided for the latter.
paused = false; fPaused = false;
finished = false; fFinished = false;
int32 timeAdjust = 0; int32 timeAdjust = 0;
uint32 baseTime = 0; uint32 baseTime = 0;
@@ -426,26 +410,26 @@ BMidiStore::Run()
bool resetTime = false; bool resetTime = false;
while (KeepRunning()) { while (KeepRunning()) {
if (paused) { if (fPaused) {
resetTime = true; resetTime = true;
snooze(100000); snooze(100000);
continue; continue;
} }
BMidiEvent* event = EventAt(currentEvent); BMidiEvent* event = EventAt(fCurrentEvent);
if (event == NULL) { if (event == NULL) {
// no more events // no more events
if (looping) { if (fLooping) {
resetTime = true; resetTime = true;
currentEvent = 0; fCurrentEvent = 0;
} else } else
break; break;
} }
if (firstEvent) { if (firstEvent) {
startTime = B_NOW; fStartTime = B_NOW;
baseTime = startTime; baseTime = fStartTime;
} else if (resetTime) } else if (resetTime)
baseTime = B_NOW; baseTime = B_NOW;
@@ -457,22 +441,22 @@ BMidiStore::Run()
} else } else
SprayEvent(event, GetEventTime(event) + timeAdjust); SprayEvent(event, GetEventTime(event) + timeAdjust);
++currentEvent; ++fCurrentEvent;
} }
finished = true; fFinished = true;
paused = false; fPaused = false;
if (hookFunc != NULL) if (fHookFunc != NULL)
(*hookFunc)(hookArg); (*fHookFunc)(fHookArg);
} }
void void
BMidiStore::AddEvent(BMidiEvent* event) BMidiStore::AddEvent(BMidiEvent* event)
{ {
events->AddItem(event); fEvents->AddItem(event);
needsSorting = true; fNeedsSorting = true;
} }
@@ -538,7 +522,7 @@ BMidiStore::SprayEvent(const BMidiEvent* event, uint32 time)
case B_SYSTEM_RESET: case B_SYSTEM_RESET:
if (byte2 == 0x51 && byte3 == 0x03) { if (byte2 == 0x51 && byte3 == 0x03) {
SprayTempoChange(event->tempo, time); SprayTempoChange(event->tempo, time);
beatsPerMinute = event->tempo; fBeatsPerMinute = event->tempo;
} else } else
SpraySystemRealTime(byte1, time); SpraySystemRealTime(byte1, time);
return; return;
@@ -551,7 +535,7 @@ BMidiStore::SprayEvent(const BMidiEvent* event, uint32 time)
BMidiEvent* BMidiEvent*
BMidiStore::EventAt(int32 index) const BMidiStore::EventAt(int32 index) const
{ {
return (BMidiEvent*)events->ItemAt(index); return (BMidiEvent*)fEvents->ItemAt(index);
} }
@@ -568,21 +552,21 @@ BMidiStore::GetEventTime(const BMidiEvent* event) const
uint32 uint32
BMidiStore::TicksToMilliseconds(uint32 ticks) const BMidiStore::TicksToMilliseconds(uint32 ticks) const
{ {
return ((uint64)ticks * 60000) / (beatsPerMinute * ticksPerBeat); return ((uint64)ticks * 60000) / (fBeatsPerMinute * fTicksPerBeat);
} }
uint32 uint32
BMidiStore::MillisecondsToTicks(uint32 ms) const BMidiStore::MillisecondsToTicks(uint32 ms) const
{ {
return ((uint64)ms * beatsPerMinute * ticksPerBeat) / 60000; return ((uint64)ms * fBeatsPerMinute * fTicksPerBeat) / 60000;
} }
void void
BMidiStore::ReadFourCC(char* fourcc) BMidiStore::ReadFourCC(char* fourcc)
{ {
if (file->Read(fourcc, 4) != 4) if (fFile->Read(fourcc, 4) != 4)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
} }
@@ -592,7 +576,7 @@ BMidiStore::WriteFourCC(char a, char b, char c, char d)
{ {
char fourcc[4] = { a, b, c, d }; char fourcc[4] = { a, b, c, d };
if (file->Write(fourcc, 4) != 4) if (fFile->Write(fourcc, 4) != 4)
throw (status_t) B_ERROR; throw (status_t) B_ERROR;
} }
@@ -601,7 +585,7 @@ uint32
BMidiStore::Read32Bit() BMidiStore::Read32Bit()
{ {
uint8 buf[4]; uint8 buf[4];
if (file->Read(buf, 4) != 4) if (fFile->Read(buf, 4) != 4)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
return (buf[0] << 24L) | (buf[1] << 16L) | (buf[2] << 8L) | buf[3]; return (buf[0] << 24L) | (buf[1] << 16L) | (buf[2] << 8L) | buf[3];
@@ -617,7 +601,7 @@ BMidiStore::Write32Bit(uint32 val)
buf[2] = (val >> 8) & 0xFF; buf[2] = (val >> 8) & 0xFF;
buf[3] = val & 0xFF; buf[3] = val & 0xFF;
if (file->Write(buf, 4) != 4) if (fFile->Write(buf, 4) != 4)
throw (status_t) B_ERROR; throw (status_t) B_ERROR;
} }
@@ -626,7 +610,7 @@ uint16
BMidiStore::Read16Bit() BMidiStore::Read16Bit()
{ {
uint8 buf[2]; uint8 buf[2];
if (file->Read(buf, 2) != 2) if (fFile->Read(buf, 2) != 2)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
return (buf[0] << 8) | buf[1]; return (buf[0] << 8) | buf[1];
@@ -640,7 +624,7 @@ BMidiStore::Write16Bit(uint16 val)
buf[0] = (val >> 8) & 0xFF; buf[0] = (val >> 8) & 0xFF;
buf[1] = val & 0xFF; buf[1] = val & 0xFF;
if (file->Write(buf, 2) != 2) if (fFile->Write(buf, 2) != 2)
throw (status_t) B_ERROR; throw (status_t) B_ERROR;
} }
@@ -649,10 +633,10 @@ uint8
BMidiStore::PeekByte() BMidiStore::PeekByte()
{ {
uint8 buf; uint8 buf;
if (file->Read(&buf, 1) != 1) if (fFile->Read(&buf, 1) != 1)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
if (file->Seek(-1, SEEK_CUR) < 0) if (fFile->Seek(-1, SEEK_CUR) < 0)
throw (status_t) B_ERROR; throw (status_t) B_ERROR;
return buf; return buf;
@@ -663,10 +647,10 @@ uint8
BMidiStore::NextByte() BMidiStore::NextByte()
{ {
uint8 buf; uint8 buf;
if (file->Read(&buf, 1) != 1) if (fFile->Read(&buf, 1) != 1)
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
--byteCount; --fByteCount;
return buf; return buf;
} }
@@ -674,21 +658,21 @@ BMidiStore::NextByte()
void void
BMidiStore::WriteByte(uint8 val) BMidiStore::WriteByte(uint8 val)
{ {
if (file->Write(&val, 1) != 1) if (fFile->Write(&val, 1) != 1)
throw (status_t) B_ERROR; throw (status_t) B_ERROR;
++byteCount; ++fByteCount;
} }
void void
BMidiStore::SkipBytes(uint32 length) BMidiStore::SkipBytes(uint32 length)
{ {
if (file->Seek(length, SEEK_CUR) < 0) { if (fFile->Seek(length, SEEK_CUR) < 0) {
throw (status_t) B_BAD_MIDI_DATA; throw (status_t) B_BAD_MIDI_DATA;
} }
byteCount -= length; fByteCount -= length;
} }
@@ -735,7 +719,7 @@ BMidiStore::ReadChunk()
char fourcc[4]; char fourcc[4];
ReadFourCC(fourcc); ReadFourCC(fourcc);
byteCount = Read32Bit(); fByteCount = Read32Bit();
if (strncmp(fourcc, "MTrk", 4) == 0) if (strncmp(fourcc, "MTrk", 4) == 0)
ReadTrack(); ReadTrack();
@@ -743,7 +727,7 @@ BMidiStore::ReadChunk()
TRACE(("Skipping '%c%c%c%c' chunk (%lu bytes)", TRACE(("Skipping '%c%c%c%c' chunk (%lu bytes)",
fourcc[0], fourcc[1], fourcc[2], fourcc[3], byteCount)) fourcc[0], fourcc[1], fourcc[2], fourcc[3], byteCount))
SkipBytes(byteCount); SkipBytes(fByteCount);
} }
} }
@@ -756,11 +740,11 @@ BMidiStore::ReadTrack()
uint8 data2; uint8 data2;
BMidiEvent* event; BMidiEvent* event;
totalTicks = 0; fTotalTicks = 0;
while (byteCount > 0) { while (fByteCount > 0) {
uint32 ticks = ReadVarLength(); uint32 ticks = ReadVarLength();
totalTicks += ticks; fTotalTicks += ticks;
if (PeekByte() & 0x80) if (PeekByte() & 0x80)
status = NextByte(); status = NextByte();
@@ -774,7 +758,7 @@ BMidiStore::ReadTrack()
data1 = NextByte(); data1 = NextByte();
data2 = NextByte(); data2 = NextByte();
event = new BMidiEvent; event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = status; event->byte1 = status;
event->byte2 = data1; event->byte2 = data1;
@@ -786,14 +770,14 @@ BMidiStore::ReadTrack()
case B_CHANNEL_PRESSURE: case B_CHANNEL_PRESSURE:
data1 = NextByte(); data1 = NextByte();
event = new BMidiEvent; event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = status; event->byte1 = status;
event->byte2 = data1; event->byte2 = data1;
AddEvent(event); AddEvent(event);
if ((status & 0xF0) == B_PROGRAM_CHANGE) if ((status & 0xF0) == B_PROGRAM_CHANGE)
instruments[data1] = true; fInstruments[data1] = true;
break; break;
case 0xF0: case 0xF0:
@@ -810,7 +794,7 @@ BMidiStore::ReadTrack()
case B_STOP: case B_STOP:
case B_ACTIVE_SENSING: case B_ACTIVE_SENSING:
event = new BMidiEvent; event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = status; event->byte1 = status;
AddEvent(event); AddEvent(event);
@@ -821,7 +805,7 @@ BMidiStore::ReadTrack()
case B_CABLE_MESSAGE: case B_CABLE_MESSAGE:
data1 = NextByte(); data1 = NextByte();
event = new BMidiEvent; event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = status; event->byte1 = status;
event->byte2 = data1; event->byte2 = data1;
@@ -832,7 +816,7 @@ BMidiStore::ReadTrack()
data1 = NextByte(); data1 = NextByte();
data2 = NextByte(); data2 = NextByte();
event = new BMidiEvent; event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = status; event->byte1 = status;
event->byte2 = data1; event->byte2 = data1;
@@ -850,7 +834,7 @@ BMidiStore::ReadTrack()
event = NULL; event = NULL;
} }
++currTrack; ++fCurrTrack;
} }
@@ -879,7 +863,7 @@ BMidiStore::ReadMetaEvent()
uint32 val = (data[0] << 16) | (data[1] << 8) | data[2]; uint32 val = (data[0] << 16) | (data[1] << 8) | data[2];
BMidiEvent* event = new BMidiEvent; BMidiEvent* event = new BMidiEvent;
event->time = totalTicks; event->time = fTotalTicks;
event->ticks = true; event->ticks = true;
event->byte1 = 0xFF; event->byte1 = 0xFF;
event->byte2 = 0x51; event->byte2 = 0x51;
@@ -895,10 +879,10 @@ void
BMidiStore::WriteTrack() BMidiStore::WriteTrack()
{ {
WriteFourCC('M', 'T', 'r', 'k'); WriteFourCC('M', 'T', 'r', 'k');
off_t lengthPos = file->Position(); off_t lengthPos = fFile->Position();
Write32Bit(0); Write32Bit(0);
byteCount = 0; fByteCount = 0;
uint32 oldTime = 0; uint32 oldTime = 0;
uint32 newTime; uint32 newTime;
@@ -976,9 +960,9 @@ BMidiStore::WriteTrack()
WriteByte(0x2F); // marker is required WriteByte(0x2F); // marker is required
WriteByte(0x00); WriteByte(0x00);
file->Seek(lengthPos, SEEK_SET); fFile->Seek(lengthPos, SEEK_SET);
Write32Bit(byteCount); Write32Bit(fByteCount);
file->Seek(0, SEEK_END); fFile->Seek(0, SEEK_END);
} }
+89 -123
View File
@@ -1,24 +1,11 @@
/* /*
* Copyright (c) 2002-2004 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2003 Jerome Leveque * Distributed under the terms of the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* 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 <MidiSynth.h> #include <MidiSynth.h>
@@ -28,240 +15,219 @@
using namespace BPrivate; using namespace BPrivate;
//------------------------------------------------------------------------------
BMidiSynth::BMidiSynth() BMidiSynth::BMidiSynth()
{ {
if (be_synth == NULL) if (be_synth == NULL) {
{
new BSynth(); new BSynth();
} }
be_synth->clientCount++; be_synth->fClientCount++;
inputEnabled = false; fInputEnabled = false;
transpose = 0; fTranspose = 0;
creationTime = system_time(); fCreationTime = system_time();
} }
//------------------------------------------------------------------------------
BMidiSynth::~BMidiSynth() BMidiSynth::~BMidiSynth()
{ {
be_synth->clientCount--; be_synth->fClientCount--;
} }
//------------------------------------------------------------------------------
status_t BMidiSynth::EnableInput(bool enable, bool loadInstruments) status_t
BMidiSynth::EnableInput(bool enable, bool loadInstruments)
{ {
status_t err = B_OK; status_t err = B_OK;
inputEnabled = enable; fInputEnabled = enable;
if (loadInstruments) { if (loadInstruments) {
err = be_synth->synth->LoadAllInstruments(); err = be_synth->fSynth->LoadAllInstruments();
} }
return err; return err;
} }
//------------------------------------------------------------------------------
bool BMidiSynth::IsInputEnabled(void) const bool
BMidiSynth::IsInputEnabled() const
{ {
return inputEnabled; return fInputEnabled;
} }
//------------------------------------------------------------------------------
void BMidiSynth::SetVolume(double volume) void
BMidiSynth::SetVolume(double volume)
{ {
be_synth->synth->SetVolume(volume); be_synth->fSynth->SetVolume(volume);
} }
//------------------------------------------------------------------------------
double BMidiSynth::Volume(void) const double
BMidiSynth::Volume() const
{ {
return be_synth->synth->Volume(); return be_synth->fSynth->Volume();
} }
//------------------------------------------------------------------------------
void BMidiSynth::SetTransposition(int16 offset) void
BMidiSynth::SetTransposition(int16 offset)
{ {
transpose = offset; fTranspose = offset;
} }
//------------------------------------------------------------------------------
int16 BMidiSynth::Transposition(void) const int16
BMidiSynth::Transposition() const
{ {
return transpose; return fTranspose;
} }
//------------------------------------------------------------------------------
void BMidiSynth::MuteChannel(int16 channel, bool do_mute) void
BMidiSynth::MuteChannel(int16 channel, bool do_mute)
{ {
fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n"); fprintf(stderr, "[midi] MuteChannel is broken; don't use it\n");
} }
//------------------------------------------------------------------------------
void BMidiSynth::GetMuteMap(char* pChannels) const void
BMidiSynth::GetMuteMap(char* pChannels) const
{ {
fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n"); fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
} }
//------------------------------------------------------------------------------
void BMidiSynth::SoloChannel(int16 channel, bool do_solo) void
BMidiSynth::SoloChannel(int16 channel, bool do_solo)
{ {
fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n"); fprintf(stderr, "[midi] SoloChannel is broken; don't use it\n");
} }
//------------------------------------------------------------------------------
void BMidiSynth::GetSoloMap(char* pChannels) const void
BMidiSynth::GetSoloMap(char* pChannels) const
{ {
fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
} }
//------------------------------------------------------------------------------
status_t BMidiSynth::LoadInstrument(int16 instrument) status_t
BMidiSynth::LoadInstrument(int16 instrument)
{ {
return be_synth->synth->LoadInstrument(instrument); return be_synth->fSynth->LoadInstrument(instrument);
} }
//------------------------------------------------------------------------------
status_t BMidiSynth::UnloadInstrument(int16 instrument) status_t
BMidiSynth::UnloadInstrument(int16 instrument)
{ {
return be_synth->synth->UnloadInstrument(instrument); return be_synth->fSynth->UnloadInstrument(instrument);
} }
//------------------------------------------------------------------------------
status_t BMidiSynth::RemapInstrument(int16 from, int16 to) status_t
BMidiSynth::RemapInstrument(int16 from, int16 to)
{ {
return be_synth->synth->RemapInstrument(from, to); return be_synth->fSynth->RemapInstrument(from, to);
} }
//------------------------------------------------------------------------------
void BMidiSynth::FlushInstrumentCache(bool startStopCache) void
BMidiSynth::FlushInstrumentCache(bool startStopCache)
{ {
be_synth->synth->FlushInstrumentCache(startStopCache); be_synth->fSynth->FlushInstrumentCache(startStopCache);
} }
//------------------------------------------------------------------------------
uint32 BMidiSynth::Tick(void) const uint32
BMidiSynth::Tick() const
{ {
return (uint32) (system_time() - creationTime); return (uint32) (system_time() - fCreationTime);
} }
//------------------------------------------------------------------------------
void BMidiSynth::NoteOff( void
BMidiSynth::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->NoteOff(channel, note + fTranspose, velocity, time);
be_synth->synth->NoteOff(channel, note + transpose, velocity, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::NoteOn( void
BMidiSynth::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->NoteOn(channel, note + fTranspose, velocity, time);
be_synth->synth->NoteOn(channel, note + transpose, velocity, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::KeyPressure( void
BMidiSynth::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) uchar channel, uchar note, uchar pressure, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->KeyPressure(
be_synth->synth->KeyPressure( channel, note + fTranspose, pressure, time);
channel, note + transpose, pressure, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::ControlChange( void
BMidiSynth::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->ControlChange(
be_synth->synth->ControlChange(
channel, controlNumber, controlValue, time); channel, controlNumber, controlValue, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::ProgramChange( void
BMidiSynth::ProgramChange(
uchar channel, uchar programNumber, uint32 time) uchar channel, uchar programNumber, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->ProgramChange(channel, programNumber, time);
be_synth->synth->ProgramChange(channel, programNumber, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time) void
BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->ChannelPressure(channel, pressure, time);
be_synth->synth->ChannelPressure(channel, pressure, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) void
BMidiSynth::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->PitchBend(channel, lsb, msb, time);
be_synth->synth->PitchBend(channel, lsb, msb, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::AllNotesOff(bool justChannel, uint32 time) void
BMidiSynth::AllNotesOff(bool justChannel, uint32 time)
{ {
if (inputEnabled) if (fInputEnabled)
{ be_synth->fSynth->AllNotesOff(justChannel, time);
be_synth->synth->AllNotesOff(justChannel, time);
}
} }
//------------------------------------------------------------------------------
void BMidiSynth::_ReservedMidiSynth1() { } void BMidiSynth::_ReservedMidiSynth1() { }
void BMidiSynth::_ReservedMidiSynth2() { } void BMidiSynth::_ReservedMidiSynth2() { }
void BMidiSynth::_ReservedMidiSynth3() { } void BMidiSynth::_ReservedMidiSynth3() { }
void BMidiSynth::_ReservedMidiSynth4() { } void BMidiSynth::_ReservedMidiSynth4() { }
//------------------------------------------------------------------------------
void BMidiSynth::Run() void
BMidiSynth::Run()
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
+79 -103
View File
@@ -1,69 +1,49 @@
/* /*
* Copyright (c) 2002-2004 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2003 Jerome Leveque * Distributed under the terms of the MIT License.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Jérôme Leveque
* 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"
#include "MidiStore.h" #include <MidiStore.h>
#include "MidiSynthFile.h" #include <MidiSynthFile.h>
#include "SoftSynth.h" #include "SoftSynth.h"
using namespace BPrivate; using namespace BPrivate;
// -----------------------------------------------------------------------------
BMidiSynthFile::BMidiSynthFile() BMidiSynthFile::BMidiSynthFile()
{ {
store = new BMidiStore(); fStore = new BMidiStore();
} }
// -----------------------------------------------------------------------------
BMidiSynthFile::~BMidiSynthFile() BMidiSynthFile::~BMidiSynthFile()
{ {
Stop(); Stop();
delete store; delete fStore;
} }
// -----------------------------------------------------------------------------
status_t BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref) status_t
BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref)
{ {
if (midi_entry_ref == NULL) if (midi_entry_ref == NULL)
{
return B_BAD_VALUE; return B_BAD_VALUE;
}
EnableInput(true, false); EnableInput(true, false);
store->finished = true; fStore->fFinished = true;
status_t err = store->Import(midi_entry_ref); status_t err = fStore->Import(midi_entry_ref);
if (err == B_OK) if (err == B_OK) {
{ for (int t = 0; t < 128; ++t) {
for (int t = 0; t < 128; ++t) if (fStore->fInstruments[t]) {
{ be_synth->fSynth->LoadInstrument(t);
if (store->instruments[t])
{
be_synth->synth->LoadInstrument(t);
} }
} }
} }
@@ -71,84 +51,82 @@ status_t BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref)
return err; return err;
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::UnloadFile(void) void
BMidiSynthFile::UnloadFile(void)
{ {
delete store; delete fStore;
store = new BMidiStore(); fStore = new BMidiStore();
} }
// -----------------------------------------------------------------------------
status_t BMidiSynthFile::Start(void) status_t
BMidiSynthFile::Start(void)
{ {
store->Connect(this); fStore->Connect(this);
store->SetCurrentEvent(0); fStore->SetCurrentEvent(0);
return store->Start(); return fStore->Start();
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::Stop(void) void
BMidiSynthFile::Stop(void)
{ {
store->Stop(); fStore->Stop();
store->Disconnect(this); fStore->Disconnect(this);
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::Fade(void) void
BMidiSynthFile::Fade(void)
{ {
Stop(); // really quick fade :P Stop(); // really quick fade :P
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::Pause(void) void
BMidiSynthFile::Pause(void)
{ {
store->paused = true; fStore->fPaused = true;
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::Resume(void) void
BMidiSynthFile::Resume(void)
{ {
store->paused = false; fStore->fPaused = false;
} }
// -----------------------------------------------------------------------------
int32 BMidiSynthFile::Duration(void) const int32
BMidiSynthFile::Duration(void) const
{ {
return store->DeltaOfEvent(store->CountEvents()); return fStore->DeltaOfEvent(fStore->CountEvents());
} }
// -----------------------------------------------------------------------------
int32 BMidiSynthFile::Position(int32 ticks) const int32
BMidiSynthFile::Position(int32 ticks) const
{ {
return store->EventAtDelta(ticks); return fStore->EventAtDelta(ticks);
} }
// -----------------------------------------------------------------------------
int32 BMidiSynthFile::Seek() int32
BMidiSynthFile::Seek()
{ {
return store->CurrentEvent(); return fStore->CurrentEvent();
} }
// -----------------------------------------------------------------------------
status_t BMidiSynthFile::GetPatches( status_t
BMidiSynthFile::GetPatches(
int16* pArray768, int16* pReturnedCount) const int16* pArray768, int16* pReturnedCount) const
{ {
int16 count = 0; int16 count = 0;
for (int t = 0; t < 128; ++t) for (int t = 0; t < 128; ++t) {
{ if (fStore->fInstruments[t]) {
if (store->instruments[t])
{
pArray768[count++] = t; pArray768[count++] = t;
} }
} }
@@ -157,81 +135,79 @@ status_t BMidiSynthFile::GetPatches(
return B_OK; return B_OK;
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg) void
BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg)
{ {
store->hookFunc = pSongHook; fStore->fHookFunc = pSongHook;
store->hookArg = arg; fStore->fHookArg = arg;
} }
// -----------------------------------------------------------------------------
bool BMidiSynthFile::IsFinished(void) const bool
BMidiSynthFile::IsFinished() const
{ {
return store->finished; return fStore->fFinished;
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::ScaleTempoBy(double tempoFactor) void
BMidiSynthFile::ScaleTempoBy(double tempoFactor)
{ {
store->SetTempo((int32) (Tempo() * tempoFactor)); fStore->SetTempo((int32) (Tempo() * tempoFactor));
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::SetTempo(int32 newTempoBPM) void
BMidiSynthFile::SetTempo(int32 newTempoBPM)
{ {
store->SetTempo(newTempoBPM); fStore->SetTempo(newTempoBPM);
} }
// -----------------------------------------------------------------------------
int32 BMidiSynthFile::Tempo(void) const int32
BMidiSynthFile::Tempo(void) const
{ {
return store->Tempo(); return fStore->Tempo();
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::EnableLooping(bool loop) void
BMidiSynthFile::EnableLooping(bool loop)
{ {
store->looping = loop; fStore->fLooping = loop;
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::MuteTrack(int16 track, bool do_mute) void
BMidiSynthFile::MuteTrack(int16 track, bool do_mute)
{ {
fprintf(stderr, "[midi] MuteTrack is broken; don't use it\n"); fprintf(stderr, "[midi] MuteTrack is broken; don't use it\n");
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::GetMuteMap(char* pTracks) const void
BMidiSynthFile::GetMuteMap(char* pTracks) const
{ {
fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n"); fprintf(stderr, "[midi] GetMuteMap is broken; don't use it\n");
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::SoloTrack(int16 track, bool do_solo) void
BMidiSynthFile::SoloTrack(int16 track, bool do_solo)
{ {
fprintf(stderr, "[midi] SoloTrack is broken; don't use it\n"); fprintf(stderr, "[midi] SoloTrack is broken; don't use it\n");
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::GetSoloMap(char* pTracks) const void
BMidiSynthFile::GetSoloMap(char* pTracks) const
{ {
fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n");
} }
// -----------------------------------------------------------------------------
void BMidiSynthFile::_ReservedMidiSynthFile1() { } void BMidiSynthFile::_ReservedMidiSynthFile1() { }
void BMidiSynthFile::_ReservedMidiSynthFile2() { } void BMidiSynthFile::_ReservedMidiSynthFile2() { }
void BMidiSynthFile::_ReservedMidiSynthFile3() { } void BMidiSynthFile::_ReservedMidiSynthFile3() { }
// -----------------------------------------------------------------------------
+48 -69
View File
@@ -1,186 +1,165 @@
/* /*
* Copyright (c) 2002-2003 Matthijs Hollemans * Copyright 2002-2006, Haiku.
* Copyright (c) 2002 Jerome Leveque * Distributed under the terms of the MIT License.
* Copyright (c) 2002 Paul Stadler
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Authors:
* copy of this software and associated documentation files (the "Software"), * Jérôme Leveque
* to deal in the Software without restriction, including without limitation * Matthijs Hollemans
* the rights to use, copy, modify, merge, publish, distribute, sublicense, * Paul Stadler
* 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 <stdio.h> #include <stdio.h>
#include <MidiText.h>
#include "debug.h" #include "debug.h"
#include "MidiText.h"
//------------------------------------------------------------------------------
BMidiText::BMidiText() BMidiText::BMidiText()
{ {
startTime = 0; fStartTime = 0;
} }
//------------------------------------------------------------------------------
BMidiText::~BMidiText() BMidiText::~BMidiText()
{ {
// do nothing // do nothing
} }
//------------------------------------------------------------------------------
void BMidiText::NoteOff( void
BMidiText::NoteOff(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"B_NOTE OFF; channel = %d, note = %d, velocity = %d\n", "B_NOTE OFF; channel = %d, note = %d, velocity = %d\n",
channel, note, velocity); channel, note, velocity);
} }
//------------------------------------------------------------------------------
void BMidiText::NoteOn( void
BMidiText::NoteOn(
uchar channel, uchar note, uchar velocity, uint32 time) uchar channel, uchar note, uchar velocity, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"B_NOTE ON; channel = %d, note = %d, velocity = %d\n", "B_NOTE ON; channel = %d, note = %d, velocity = %d\n",
channel, note, velocity); channel, note, velocity);
} }
//------------------------------------------------------------------------------
void BMidiText::KeyPressure( void
BMidiText::KeyPressure(
uchar channel, uchar note, uchar pressure, uint32 time) uchar channel, uchar note, uchar pressure, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"KEY PRESSURE; channel = %d, note = %d, pressure = %d\n", "KEY PRESSURE; channel = %d, note = %d, pressure = %d\n",
channel, note, pressure); channel, note, pressure);
} }
//------------------------------------------------------------------------------
void BMidiText::ControlChange( void
BMidiText::ControlChange(
uchar channel, uchar controlNumber, uchar controlValue, uint32 time) uchar channel, uchar controlNumber, uchar controlValue, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"CONTROL CHANGE; channel = %d, control = %d, value = %d\n", "CONTROL CHANGE; channel = %d, control = %d, value = %d\n",
channel, controlNumber, controlValue); channel, controlNumber, controlValue);
} }
//------------------------------------------------------------------------------
void BMidiText::ProgramChange( void
BMidiText::ProgramChange(
uchar channel, uchar programNumber, uint32 time) uchar channel, uchar programNumber, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"PROGRAM CHANGE; channel = %d, program = %d\n", "PROGRAM CHANGE; channel = %d, program = %d\n",
channel, programNumber); channel, programNumber);
} }
//------------------------------------------------------------------------------
void BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time) void
BMidiText::ChannelPressure(uchar channel, uchar pressure, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"CHANNEL PRESSURE; channel = %d, pressure = %d\n", "CHANNEL PRESSURE; channel = %d, pressure = %d\n",
channel, pressure); channel, pressure);
} }
//------------------------------------------------------------------------------
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);
printf( printf(
"PITCH BEND; channel = %d, lsb = %d, msb = %d\n", "PITCH BEND; channel = %d, lsb = %d, msb = %d\n",
channel, lsb, msb); channel, lsb, msb);
} }
//------------------------------------------------------------------------------
void BMidiText::SystemExclusive(void* data, size_t length, uint32 time) void
BMidiText::SystemExclusive(void* data, size_t length, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf("SYSTEM EXCLUSIVE;\n"); printf("SYSTEM EXCLUSIVE;\n");
for (size_t t = 0; t < length; ++t) for (size_t t = 0; t < length; ++t)
{
printf("%02X ", ((uint8*) data)[t]); printf("%02X ", ((uint8*) data)[t]);
}
printf("\n"); printf("\n");
} }
//------------------------------------------------------------------------------
void BMidiText::SystemCommon( void
BMidiText::SystemCommon(
uchar status, uchar data1, uchar data2, uint32 time) uchar status, uchar data1, uchar data2, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf( printf(
"SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n", "SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n",
status, data1, data2); status, data1, data2);
} }
//------------------------------------------------------------------------------
void BMidiText::SystemRealTime(uchar status, uint32 time) void
BMidiText::SystemRealTime(uchar status, uint32 time)
{ {
WaitAndPrint(time); _WaitAndPrint(time);
printf("SYSTEM REAL TIME; status = %d\n", status); printf("SYSTEM REAL TIME; status = %d\n", status);
} }
//------------------------------------------------------------------------------
void BMidiText::ResetTimer(bool start) void
BMidiText::ResetTimer(bool start)
{ {
startTime = start ? B_NOW : 0; fStartTime = start ? B_NOW : 0;
} }
//------------------------------------------------------------------------------
void BMidiText::_ReservedMidiText1() { } void BMidiText::_ReservedMidiText1() { }
void BMidiText::_ReservedMidiText2() { } void BMidiText::_ReservedMidiText2() { }
void BMidiText::_ReservedMidiText3() { } void BMidiText::_ReservedMidiText3() { }
//------------------------------------------------------------------------------
void BMidiText::Run() void
BMidiText::Run()
{ {
while (KeepRunning()) while (KeepRunning())
{
snooze(50000); snooze(50000);
}
} }
//------------------------------------------------------------------------------
void BMidiText::WaitAndPrint(uint32 time) void
BMidiText::_WaitAndPrint(uint32 time)
{ {
if (startTime == 0) { startTime = time; } if (fStartTime == 0)
fStartTime = time;
SnoozeUntil(time); SnoozeUntil(time);
printf("%lu: ", time - startTime); printf("%lu: ", time - fStartTime);
} }
//------------------------------------------------------------------------------
+5 -5
View File
@@ -55,7 +55,7 @@ bool
BSoftSynth::InitCheck() BSoftSynth::InitCheck()
{ {
if (!fSynth) if (!fSynth)
Init(); _Init();
return fInitCheck; return fInitCheck;
} }
@@ -63,7 +63,7 @@ BSoftSynth::InitCheck()
void void
BSoftSynth::Unload(void) BSoftSynth::Unload(void)
{ {
Done(); _Done();
free(fInstrumentsFile); free(fInstrumentsFile);
fInstrumentsFile = NULL; fInstrumentsFile = NULL;
} }
@@ -418,12 +418,12 @@ BSoftSynth::AllNotesOff(bool justChannel, uint32 time)
void void
BSoftSynth::Init() BSoftSynth::_Init()
{ {
status_t err; status_t err;
fInitCheck = false; fInitCheck = false;
Done(); _Done();
fSettings = new_fluid_settings(); fSettings = new_fluid_settings();
fluid_settings_setnum(fSettings, "synth.sample-rate", fSampleRate); fluid_settings_setnum(fSettings, "synth.sample-rate", fSampleRate);
@@ -455,7 +455,7 @@ BSoftSynth::Init()
void void
BSoftSynth::Done() BSoftSynth::_Done()
{ {
if (fSoundPlayer) { if (fSoundPlayer) {
fSoundPlayer->SetHasData(false); fSoundPlayer->SetHasData(false);
+2 -2
View File
@@ -88,8 +88,8 @@ private:
BSoftSynth(); BSoftSynth();
~BSoftSynth(); ~BSoftSynth();
void Init(); void _Init();
void Done(); void _Done();
static void PlayBuffer(void * cookie, void * data, size_t size, const media_raw_audio_format & format); static void PlayBuffer(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
bool fInitCheck; bool fInitCheck;
+86 -94
View File
@@ -18,32 +18,29 @@ BSynth* be_synth = NULL;
using namespace BPrivate; using namespace BPrivate;
//------------------------------------------------------------------------------
BSynth::BSynth() BSynth::BSynth()
{ {
Init(); _Init();
} }
//------------------------------------------------------------------------------
BSynth::BSynth(synth_mode mode) BSynth::BSynth(synth_mode mode)
{ {
Init(); _Init();
synthMode = mode; fSynthMode = mode;
} }
//------------------------------------------------------------------------------
BSynth::~BSynth() BSynth::~BSynth()
{ {
delete synth; delete fSynth;
be_synth = NULL; be_synth = NULL;
} }
//------------------------------------------------------------------------------
status_t BSynth::LoadSynthData(entry_ref* instrumentsFile) status_t
BSynth::LoadSynthData(entry_ref* instrumentsFile)
{ {
if (instrumentsFile == NULL) { if (instrumentsFile == NULL) {
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -53,173 +50,170 @@ status_t BSynth::LoadSynthData(entry_ref* instrumentsFile)
status_t err = path.InitCheck(); status_t err = path.InitCheck();
if (err != B_OK) if (err != B_OK)
return err; return err;
return synth->SetInstrumentsFile(path.Path()); return fSynth->SetInstrumentsFile(path.Path());
} }
//------------------------------------------------------------------------------
status_t BSynth::LoadSynthData(synth_mode mode) status_t
BSynth::LoadSynthData(synth_mode mode)
{ {
// Our softsynth doesn't support multiple modes like Be's synth did. // Our softsynth doesn't support multiple modes like Be's synth did.
// Therefore, if you use this function, the synth will revert to its // Therefore, if you use this function, the synth will revert to its
// default instruments bank. However, we do keep track of the current // default instruments bank. However, we do keep track of the current
// synth_mode here, in order not to confuse old applications. // synth_mode here, in order not to confuse old applications.
synthMode = mode; fSynthMode = mode;
if (synthMode == B_SAMPLES_ONLY) if (fSynthMode == B_SAMPLES_ONLY) {
{
fprintf(stderr, "[midi] LoadSynthData: BSamples is not supported\n"); fprintf(stderr, "[midi] LoadSynthData: BSamples is not supported\n");
} }
return synth->SetDefaultInstrumentsFile(); return fSynth->SetDefaultInstrumentsFile();
} }
//------------------------------------------------------------------------------
synth_mode BSynth::SynthMode(void) synth_mode
BSynth::SynthMode()
{ {
return synthMode; return fSynthMode;
} }
//------------------------------------------------------------------------------
void BSynth::Unload(void) void
BSynth::Unload()
{ {
synth->Unload(); fSynth->Unload();
} }
//------------------------------------------------------------------------------
bool BSynth::IsLoaded(void) const bool
BSynth::IsLoaded() const
{ {
return synth->IsLoaded(); return fSynth->IsLoaded();
} }
//------------------------------------------------------------------------------
status_t BSynth::SetSamplingRate(int32 sample_rate) status_t
BSynth::SetSamplingRate(int32 sample_rate)
{ {
return synth->SetSamplingRate(sample_rate); return fSynth->SetSamplingRate(sample_rate);
} }
//------------------------------------------------------------------------------
int32 BSynth::SamplingRate() const int32
BSynth::SamplingRate() const
{ {
return synth->SamplingRate(); return fSynth->SamplingRate();
} }
//------------------------------------------------------------------------------
status_t BSynth::SetInterpolation(interpolation_mode interp_mode) status_t
BSynth::SetInterpolation(interpolation_mode interp_mode)
{ {
return synth->SetInterpolation(interp_mode); return fSynth->SetInterpolation(interp_mode);
} }
//------------------------------------------------------------------------------
interpolation_mode BSynth::Interpolation() const interpolation_mode
BSynth::Interpolation() const
{ {
return synth->Interpolation(); return fSynth->Interpolation();
} }
//------------------------------------------------------------------------------
void BSynth::SetReverb(reverb_mode rev_mode) void
BSynth::SetReverb(reverb_mode rev_mode)
{ {
synth->SetReverb(rev_mode); fSynth->SetReverb(rev_mode);
} }
//------------------------------------------------------------------------------
reverb_mode BSynth::Reverb() const reverb_mode
BSynth::Reverb() const
{ {
return synth->Reverb(); return fSynth->Reverb();
} }
//------------------------------------------------------------------------------
status_t BSynth::EnableReverb(bool reverb_enabled) status_t
BSynth::EnableReverb(bool reverb_enabled)
{ {
return synth->EnableReverb(reverb_enabled); return fSynth->EnableReverb(reverb_enabled);
} }
//------------------------------------------------------------------------------
bool BSynth::IsReverbEnabled() const bool
BSynth::IsReverbEnabled() const
{ {
return synth->IsReverbEnabled(); return fSynth->IsReverbEnabled();
} }
//------------------------------------------------------------------------------
status_t BSynth::SetVoiceLimits( status_t
BSynth::SetVoiceLimits(
int16 maxSynthVoices, int16 maxSampleVoices, int16 limiterThreshhold) int16 maxSynthVoices, int16 maxSampleVoices, int16 limiterThreshhold)
{ {
status_t err = B_OK; status_t err = B_OK;
err = synth->SetMaxVoices(maxSynthVoices); err = fSynth->SetMaxVoices(maxSynthVoices);
if (err == B_OK) if (err == B_OK) {
{ err = fSynth->SetLimiterThreshold(limiterThreshhold);
err = synth->SetLimiterThreshold(limiterThreshhold);
} }
return err; return err;
} }
//------------------------------------------------------------------------------
int16 BSynth::MaxSynthVoices(void) const int16
BSynth::MaxSynthVoices() const
{ {
return synth->MaxVoices(); return fSynth->MaxVoices();
} }
//------------------------------------------------------------------------------
int16 BSynth::MaxSampleVoices(void) const int16
BSynth::MaxSampleVoices() const
{ {
fprintf(stderr, "[midi] MaxSampleVoices: BSamples not supported\n"); fprintf(stderr, "[midi] MaxSampleVoices: BSamples not supported\n");
return 0; return 0;
} }
//------------------------------------------------------------------------------
int16 BSynth::LimiterThreshhold(void) const int16
BSynth::LimiterThreshhold() const
{ {
return synth->LimiterThreshold(); return fSynth->LimiterThreshold();
} }
//------------------------------------------------------------------------------
void BSynth::SetSynthVolume(double theVolume) void
BSynth::SetSynthVolume(double theVolume)
{ {
synth->SetVolume(theVolume); fSynth->SetVolume(theVolume);
} }
//------------------------------------------------------------------------------
double BSynth::SynthVolume(void) const double
BSynth::SynthVolume() const
{ {
return synth->Volume(); return fSynth->Volume();
} }
//------------------------------------------------------------------------------
void BSynth::SetSampleVolume(double theVolume) void
BSynth::SetSampleVolume(double theVolume)
{ {
fprintf(stderr, "[midi] SetSampleVolume: BSamples not supported\n"); fprintf(stderr, "[midi] SetSampleVolume: BSamples not supported\n");
} }
//------------------------------------------------------------------------------
double BSynth::SampleVolume(void) const double
BSynth::SampleVolume(void) const
{ {
fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n"); fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n");
return 0; return 0;
} }
//------------------------------------------------------------------------------
status_t BSynth::GetAudio( status_t
int16* pLeft, int16* pRight, int32 max_samples) const BSynth::GetAudio(int16* pLeft, int16* pRight, int32 max_samples) const
{ {
// We don't print a "not supported" message here. That would cause // We don't print a "not supported" message here. That would cause
// significant slowdowns because applications ask for this many times. // significant slowdowns because applications ask for this many times.
@@ -230,50 +224,48 @@ status_t BSynth::GetAudio(
return max_samples; return max_samples;
} }
//------------------------------------------------------------------------------
void BSynth::Pause(void) void
BSynth::Pause()
{ {
synth->Pause(); fSynth->Pause();
} }
//------------------------------------------------------------------------------
void BSynth::Resume(void) void
BSynth::Resume()
{ {
synth->Resume(); fSynth->Resume();
} }
//------------------------------------------------------------------------------
void BSynth::SetControllerHook(int16 controller, synth_controller_hook cback) void
BSynth::SetControllerHook(int16 controller, synth_controller_hook cback)
{ {
fprintf(stderr, "[midi] SetControllerHook is not supported\n"); fprintf(stderr, "[midi] SetControllerHook is not supported\n");
} }
//------------------------------------------------------------------------------
void BSynth::Init() void
BSynth::_Init()
{ {
delete be_synth; delete be_synth;
be_synth = this; be_synth = this;
synthMode = B_NO_SYNTH; fSynthMode = B_NO_SYNTH;
clientCount = 0; fClientCount = 0;
synth = new BSoftSynth(); fSynth = new BSoftSynth();
} }
//------------------------------------------------------------------------------
int32 BSynth::CountClients(void) const int32
BSynth::CountClients() const
{ {
return clientCount; return fClientCount;
} }
//------------------------------------------------------------------------------
void BSynth::_ReservedSynth1() { } void BSynth::_ReservedSynth1() { }
void BSynth::_ReservedSynth2() { } void BSynth::_ReservedSynth2() { }
void BSynth::_ReservedSynth3() { } void BSynth::_ReservedSynth3() { }
void BSynth::_ReservedSynth4() { } void BSynth::_ReservedSynth4() { }
//------------------------------------------------------------------------------