From 4810cdcdbce34442e72600c975882c2db8c621e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 19 Jun 2006 13:24:04 +0000 Subject: [PATCH] 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 --- headers/os/midi/Midi.h | 10 +- headers/os/midi/MidiPort.h | 14 +- headers/os/midi/MidiStore.h | 36 ++-- headers/os/midi/MidiSynth.h | 6 +- headers/os/midi/MidiSynthFile.h | 2 +- headers/os/midi/MidiText.h | 4 +- headers/os/midi/Synth.h | 8 +- src/kits/midi/Midi.cpp | 272 ++++++++++++++---------------- src/kits/midi/MidiGlue.cpp | 170 +++++++++---------- src/kits/midi/MidiGlue.h | 29 +--- src/kits/midi/MidiPort.cpp | 289 +++++++++++++------------------- src/kits/midi/MidiStore.cpp | 232 ++++++++++++------------- src/kits/midi/MidiSynth.cpp | 212 ++++++++++------------- src/kits/midi/MidiSynthFile.cpp | 182 +++++++++----------- src/kits/midi/MidiText.cpp | 117 ++++++------- src/kits/midi/SoftSynth.cpp | 10 +- src/kits/midi/SoftSynth.h | 4 +- src/kits/midi/Synth.cpp | 180 ++++++++++---------- 18 files changed, 785 insertions(+), 992 deletions(-) diff --git a/headers/os/midi/Midi.h b/headers/os/midi/Midi.h index 08fdd2a701..2e41f05faa 100644 --- a/headers/os/midi/Midi.h +++ b/headers/os/midi/Midi.h @@ -109,12 +109,12 @@ private: virtual void Run(); - BMidiLocalProducer* producer; - BMidiLocalConsumer* consumer; + BMidiLocalProducer* fProducer; + BMidiLocalConsumer* fConsumer; - BList* connections; - volatile thread_id threadId; - volatile bool isRunning; + BList* fConnections; + volatile thread_id fThreadId; + volatile bool fIsRunning; uint32 _reserved2[5]; }; diff --git a/headers/os/midi/MidiPort.h b/headers/os/midi/MidiPort.h index 55479d031a..af86f6fd98 100644 --- a/headers/os/midi/MidiPort.h +++ b/headers/os/midi/MidiPort.h @@ -75,14 +75,14 @@ private: void ScanDevices(); void EmptyDeviceList(); - BMidiLocalProducer* localSource; - BMidiLocalConsumer* localSink; - BMidiProducer* remoteSource; - BMidiConsumer* remoteSink; + BMidiLocalProducer* fLocalSource; + BMidiLocalConsumer* fLocalSink; + BMidiProducer* fRemoteSource; + BMidiConsumer* fRemoteSink; - char* portName; - status_t status; - BList* devices; + char* fPortName; + status_t fStatus; + BList* fDevices; uint32 _reserved[1]; }; diff --git a/headers/os/midi/MidiStore.h b/headers/os/midi/MidiStore.h index fe65520292..e519a2727a 100644 --- a/headers/os/midi/MidiStore.h +++ b/headers/os/midi/MidiStore.h @@ -85,12 +85,12 @@ private: uint32 TicksToMilliseconds(uint32 ticks) const; uint32 MillisecondsToTicks(uint32 ms) const; - BList* events; - int32 currentEvent; - uint32 startTime; - int32 beatsPerMinute; - int16 ticksPerBeat; - bool needsSorting; + BList* fEvents; + int32 fCurrentEvent; + uint32 fStartTime; + int32 fBeatsPerMinute; + int16 fTicksPerBeat; + bool fNeedsSorting; void ReadFourCC(char* fourcc); uint32 Read32Bit(); @@ -112,21 +112,21 @@ private: void WriteTrack(); void WriteMetaEvent(BMidiEvent* event); - BFile* file; - uint32 byteCount; - uint32 totalTicks; - uint16 numTracks; - uint16 currTrack; - uint16 format; + BFile* fFile; + uint32 fByteCount; + uint32 fTotalTicks; + uint16 fNumTracks; + uint16 fCurrTrack; + uint16 fFormat; uint16 _reserved1[1]; - bool* instruments; - synth_file_hook hookFunc; - int32 hookArg; - bool looping; - bool paused; - bool finished; + bool* fInstruments; + synth_file_hook fHookFunc; + int32 fHookArg; + bool fLooping; + bool fPaused; + bool fFinished; uint32 _reserved2[12]; }; diff --git a/headers/os/midi/MidiSynth.h b/headers/os/midi/MidiSynth.h index 1cb4b24502..c85f8b5f53 100644 --- a/headers/os/midi/MidiSynth.h +++ b/headers/os/midi/MidiSynth.h @@ -80,9 +80,9 @@ private: virtual void Run(); - bigtime_t creationTime; - int16 transpose; - bool inputEnabled; + bigtime_t fCreationTime; + int16 fTranspose; + bool fInputEnabled; }; #endif // _MIDI_SYNTH_H diff --git a/headers/os/midi/MidiSynthFile.h b/headers/os/midi/MidiSynthFile.h index 9f2e67844a..ffd0cb321e 100644 --- a/headers/os/midi/MidiSynthFile.h +++ b/headers/os/midi/MidiSynthFile.h @@ -57,7 +57,7 @@ private: virtual void _ReservedMidiSynthFile2(); virtual void _ReservedMidiSynthFile3(); - BMidiStore* store; + BMidiStore* fStore; int32 _reserved[3]; }; diff --git a/headers/os/midi/MidiText.h b/headers/os/midi/MidiText.h index 303d0427ae..8a18593943 100644 --- a/headers/os/midi/MidiText.h +++ b/headers/os/midi/MidiText.h @@ -53,9 +53,9 @@ private: virtual void Run(); - void WaitAndPrint(uint32 time); + void _WaitAndPrint(uint32 time); - uint32 startTime; + uint32 fStartTime; uint32 _reserved[4]; }; diff --git a/headers/os/midi/Synth.h b/headers/os/midi/Synth.h index 8ca71d9a64..7d0c1bd65b 100644 --- a/headers/os/midi/Synth.h +++ b/headers/os/midi/Synth.h @@ -95,11 +95,11 @@ private: virtual void _ReservedSynth3(); virtual void _ReservedSynth4(); - void Init(); + void _Init(); - BPrivate::BSoftSynth* synth; - synth_mode synthMode; - int32 clientCount; + BPrivate::BSoftSynth* fSynth; + synth_mode fSynthMode; + int32 fClientCount; uint32 _reserved[10]; }; diff --git a/src/kits/midi/Midi.cpp b/src/kits/midi/Midi.cpp index 32796ed33c..4e9426203d 100644 --- a/src/kits/midi/Midi.cpp +++ b/src/kits/midi/Midi.cpp @@ -1,372 +1,348 @@ /* - * Copyright (c) 2002-2003 Matthijs Hollemans - * Copyright (c) 2002 Michael Pfeiffer - * Copyright (c) 2002 Jerome Leveque - * Copyright (c) 2002 Paul Stadler + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Michael Pfeiffer + * Jérôme Leveque + * Paul Stadler */ #include +#include #include -#include "Midi.h" #include "MidiGlue.h" #include "debug.h" using namespace BPrivate; -//------------------------------------------------------------------------------ -status_t _run_thread(void* data) +status_t +_run_thread(void* data) { BMidi* midi = (BMidi*) data; midi->Run(); - midi->isRunning = false; + midi->fIsRunning = false; return 0; } -//------------------------------------------------------------------------------ BMidi::BMidi() { - connections = new BList; - threadId = -1; - isRunning = false; + fConnections = new BList; + fThreadId = -1; + fIsRunning = false; - producer = new BMidiLocalProducer("MidiGlue(out)"); - consumer = new BMidiGlue(this, "MidiGlue(in)"); + fProducer = new BMidiLocalProducer("MidiGlue(out)"); + fConsumer = new BMidiGlue(this, "MidiGlue(in)"); } -//------------------------------------------------------------------------------ BMidi::~BMidi() { Stop(); status_t result; - wait_for_thread(threadId, &result); + wait_for_thread(fThreadId, &result); - producer->Release(); - consumer->Release(); + fProducer->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 } -//------------------------------------------------------------------------------ -void BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time) +void +BMidi::NoteOn(uchar channel, uchar note, uchar velocity, uint32 time) { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::KeyPressure( +void +BMidi::KeyPressure( uchar channel, uchar note, uchar pressure, uint32 time) { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::ControlChange( +void +BMidi::ControlChange( uchar channel, uchar controlNumber, uchar controlValue, uint32 time) { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time) +void +BMidi::ProgramChange(uchar channel, uchar programNumber, uint32 time) { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time) +void +BMidi::ChannelPressure(uchar channel, uchar pressure, uint32 time) { // 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 } -//------------------------------------------------------------------------------ -void BMidi::SystemExclusive(void* data, size_t length, uint32 time) +void +BMidi::SystemExclusive(void* data, size_t length, uint32 time) { // 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 } -//------------------------------------------------------------------------------ -void BMidi::SystemRealTime(uchar status, uint32 time) +void +BMidi::SystemRealTime(uchar status, uint32 time) { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::TempoChange(int32 beatsPerMinute, uint32 time) +void +BMidi::TempoChange(int32 beatsPerMinute, uint32 time) { // 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); - if (!justChannel) - { - for (uchar note = 0; note <= 0x7F; ++note) - { + if (!justChannel) { + for (uchar note = 0; note <= 0x7F; ++note) { 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( _run_thread, "MidiRunThread", B_URGENT_PRIORITY, this); - if (err < B_OK) { return err; } + if (err < B_OK) + return err; - threadId = err; - isRunning = true; + fThreadId = err; + fIsRunning = true; - err = resume_thread(threadId); - if (err != B_OK) - { - threadId = -1; - isRunning = false; + err = resume_thread(fThreadId); + if (err != B_OK) { + fThreadId = -1; + fIsRunning = false; } 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 (producer->Connect(toObject->consumer) == B_OK) - { - connections->AddItem(toObject); + if (toObject != NULL) { + if (fProducer->Connect(toObject->fConsumer) == B_OK) { + fConnections->AddItem(toObject); } } } -//------------------------------------------------------------------------------ -void BMidi::Disconnect(BMidi* fromObject) +void +BMidi::Disconnect(BMidi* fromObject) { - if (fromObject != NULL) - { - if (producer->Disconnect(fromObject->consumer) == B_OK) - { - connections->RemoveItem(fromObject); - } + if (fromObject == NULL) + return; + + if (fProducer->Disconnect(fromObject->fConsumer) == B_OK) { + fConnections->RemoveItem(fromObject); } } -//------------------------------------------------------------------------------ -bool BMidi::IsConnected(BMidi* toObject) const +bool +BMidi::IsConnected(BMidi* toObject) const { if (toObject != NULL) - { - return producer->IsConnected(toObject->consumer); - } + return fProducer->IsConnected(toObject->fConsumer); 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); } -//------------------------------------------------------------------------------ -bool BMidi::KeepRunning() +bool +BMidi::KeepRunning() { - return (threadId != -1); + return (fThreadId != -1); } -//------------------------------------------------------------------------------ void BMidi::_ReservedMidi1() {} void BMidi::_ReservedMidi2() {} void BMidi::_ReservedMidi3() {} -//------------------------------------------------------------------------------ -void BMidi::Run() +void +BMidi::Run() { // do nothing } -//------------------------------------------------------------------------------ -void BMidi::SprayNoteOff( +void +BMidi::SprayNoteOff( uchar channel, uchar note, uchar velocity, uint32 time) const { - producer->SprayNoteOff( + fProducer->SprayNoteOff( channel - 1, note, velocity, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayNoteOn( +void +BMidi::SprayNoteOn( uchar channel, uchar note, uchar velocity, uint32 time) const { - producer->SprayNoteOn( + fProducer->SprayNoteOn( channel - 1, note, velocity, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayKeyPressure( +void +BMidi::SprayKeyPressure( uchar channel, uchar note, uchar pressure, uint32 time) const { - producer->SprayKeyPressure( + fProducer->SprayKeyPressure( channel - 1, note, pressure, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayControlChange( +void +BMidi::SprayControlChange( uchar channel, uchar controlNumber, uchar controlValue, uint32 time) const { - producer->SprayControlChange( + fProducer->SprayControlChange( channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayProgramChange( +void +BMidi::SprayProgramChange( uchar channel, uchar programNumber, uint32 time) const { - producer->SprayProgramChange( + fProducer->SprayProgramChange( channel - 1, programNumber, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayChannelPressure( +void +BMidi::SprayChannelPressure( uchar channel, uchar pressure, uint32 time) const { - producer->SprayChannelPressure( + fProducer->SprayChannelPressure( channel - 1, pressure, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidi::SprayPitchBend( +void +BMidi::SprayPitchBend( 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 { - 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 { - 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)); } -//------------------------------------------------------------------------------ diff --git a/src/kits/midi/MidiGlue.cpp b/src/kits/midi/MidiGlue.cpp index 68859106b7..98bf8f3a36 100644 --- a/src/kits/midi/MidiGlue.cpp +++ b/src/kits/midi/MidiGlue.cpp @@ -1,222 +1,206 @@ -/* - * Copyright (c) 2003 Matthijs Hollemans - * Copyright (c) 2002 Jerome Leveque +/* + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque */ -#include "Midi.h" +#include #include "MidiGlue.h" -#include "MidiPort.h" +#include using namespace BPrivate; -//------------------------------------------------------------------------------ BMidiGlue::BMidiGlue(BMidi* midiObject_, const char* name) : BMidiLocalConsumer(name) { - midiObject = midiObject_; + fMidiObject = midiObject_; } -//------------------------------------------------------------------------------ -void BMidiGlue::NoteOff( +void +BMidiGlue::NoteOff( 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) { - 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) { - 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) { - midiObject->ControlChange( + fMidiObject->ControlChange( channel + 1, controlNumber, controlValue, MAKE_TIME(time)); } -//------------------------------------------------------------------------------ -void BMidiGlue::ProgramChange( +void +BMidiGlue::ProgramChange( 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) { - 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) { - 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) { - 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) { - 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) : BMidiLocalConsumer(name) { - midiObject = midiObject_; + fMidiObject = midiObject_; } -//------------------------------------------------------------------------------ -void BMidiPortGlue::NoteOff( +void +BMidiPortGlue::NoteOff( 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) { - 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) { - midiObject->SprayKeyPressure( + fMidiObject->SprayKeyPressure( channel + 1, note, pressure, MAKE_TIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPortGlue::ControlChange( +void +BMidiPortGlue::ControlChange( uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time) { - midiObject->SprayControlChange( + fMidiObject->SprayControlChange( channel + 1, controlNumber, controlValue, MAKE_TIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPortGlue::ProgramChange( +void +BMidiPortGlue::ProgramChange( uchar channel, uchar programNumber, bigtime_t time) { - midiObject->SprayProgramChange( + fMidiObject->SprayProgramChange( channel + 1, programNumber, MAKE_TIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPortGlue::ChannelPressure( +void +BMidiPortGlue::ChannelPressure( 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) { - 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) { - 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) { - 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)); } -//------------------------------------------------------------------------------ diff --git a/src/kits/midi/MidiGlue.h b/src/kits/midi/MidiGlue.h index 51c7984e78..8db39e9454 100644 --- a/src/kits/midi/MidiGlue.h +++ b/src/kits/midi/MidiGlue.h @@ -1,24 +1,11 @@ /* - * Copyright (c) 2003 Matthijs Hollemans - * Copyright (c) 2002 Jerome Leveque + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque */ #ifndef _MIDI_GLUE_H @@ -72,7 +59,7 @@ public: private: - BMidi* midiObject; + BMidi* fMidiObject; }; class BMidiPortGlue: public BMidiLocalConsumer @@ -115,7 +102,7 @@ public: private: - BMidiPort* midiObject; + BMidiPort* fMidiObject; }; } // namespace BPrivate diff --git a/src/kits/midi/MidiPort.cpp b/src/kits/midi/MidiPort.cpp index 28c8ea2c2a..500590331d 100644 --- a/src/kits/midi/MidiPort.cpp +++ b/src/kits/midi/MidiPort.cpp @@ -1,354 +1,303 @@ /* - * Copyright (c) 2002-2003 Matthijs Hollemans - * Copyright (c) 2002 Jerome Leveque + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque */ +#include #include #include #include #include "debug.h" -#include "MidiPort.h" #include "MidiGlue.h" using namespace BPrivate; -//------------------------------------------------------------------------------ BMidiPort::BMidiPort(const char* name) { - portName = NULL; - devices = new BList; - status = B_ERROR; + fPortName = NULL; + fDevices = new BList; + fStatus = B_ERROR; - localSource = new BMidiLocalProducer("MidiPortGlue(out)"); - localSink = new BMidiPortGlue(this, "MidiPortGlue(in)"); + fLocalSource = new BMidiLocalProducer("MidiPortGlue(out)"); + fLocalSink = new BMidiPortGlue(this, "MidiPortGlue(in)"); - remoteSource = NULL; - remoteSink = NULL; + fRemoteSource = NULL; + fRemoteSink = NULL; ScanDevices(); if (name != NULL) - { Open(name); - } } -//------------------------------------------------------------------------------ BMidiPort::~BMidiPort() { Close(); EmptyDeviceList(); - delete devices; + delete fDevices; - localSource->Release(); - localSink->Release(); + fLocalSource->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(); - for (int32 t = 0; t < devices->CountItems(); ++t) - { - BMidiEndpoint* endp = (BMidiEndpoint*) devices->ItemAt(t); - if (strcmp(name, endp->Name()) == 0) - { - if (endp->IsValid()) // still exists? - { - if (endp->IsProducer()) - { - if (remoteSource == NULL) - { - remoteSource = (BMidiProducer*) endp; - } - } - else if (endp->IsConsumer()) - { - if (remoteSink == NULL) - { - remoteSink = (BMidiConsumer*) endp; - localSource->Connect(remoteSink); - } - } + for (int32 t = 0; t < fDevices->CountItems(); ++t) { + BMidiEndpoint* endp = (BMidiEndpoint*) fDevices->ItemAt(t); + if (strcmp(name, endp->Name()) != 0) + continue; + if (!endp->IsValid()) // still exists? + continue; + if (endp->IsProducer()) { + if (fRemoteSource == NULL) + fRemoteSource = (BMidiProducer*) endp; + } else { + if (fRemoteSink == NULL) { + fRemoteSink = (BMidiConsumer*) endp; + fLocalSource->Connect(fRemoteSink); } } } - if (remoteSource != NULL) - { - portName = strdup(remoteSource->Name()); - status = B_OK; - } - else if (remoteSink != NULL) - { - portName = strdup(remoteSink->Name()); - status = B_OK; + if (fRemoteSource != NULL) { + fPortName = strdup(fRemoteSource->Name()); + fStatus = B_OK; + } else if (fRemoteSink != NULL) { + fPortName = strdup(fRemoteSink->Name()); + fStatus = B_OK; } } - return status; + return fStatus; } -//------------------------------------------------------------------------------ -void BMidiPort::Close() +void +BMidiPort::Close() { - if (remoteSource != NULL) - { - remoteSource->Disconnect(localSink); - remoteSource = NULL; + if (fRemoteSource != NULL) { + fRemoteSource->Disconnect(fLocalSink); + fRemoteSource = NULL; } - if (remoteSink != NULL) - { - localSource->Disconnect(remoteSink); - remoteSink = NULL; + if (fRemoteSink != NULL) { + fLocalSource->Disconnect(fRemoteSink); + fRemoteSink = NULL; } - if (portName != NULL) - { - free(portName); - portName = NULL; + if (fPortName != NULL) { + free(fPortName); + fPortName = 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) { - 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) { - 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) { - localSource->SprayKeyPressure( + fLocalSource->SprayKeyPressure( channel - 1, note, pressure, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPort::ControlChange( +void +BMidiPort::ControlChange( uchar channel, uchar controlNumber, uchar controlValue, uint32 time) { - localSource->SprayControlChange( + fLocalSource->SprayControlChange( channel - 1, controlNumber, controlValue, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPort::ProgramChange( +void +BMidiPort::ProgramChange( uchar channel, uchar programNumber, uint32 time) { - localSource->SprayProgramChange( + fLocalSource->SprayProgramChange( channel - 1, programNumber, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time) +void +BMidiPort::ChannelPressure(uchar channel, uchar pressure, uint32 time) { - localSource->SprayChannelPressure( + fLocalSource->SprayChannelPressure( channel - 1, pressure, MAKE_BIGTIME(time)); } -//------------------------------------------------------------------------------ -void BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) +void +BMidiPort::PitchBend(uchar channel, uchar lsb, uchar msb, uint32 time) { - 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) { - 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(); - if ((err == B_OK) && (remoteSource != NULL)) - { - return remoteSource->Connect(localSink); + if ((err == B_OK) && (fRemoteSource != NULL)) { + return fRemoteSource->Connect(fLocalSink); } return err; } -//------------------------------------------------------------------------------ -void BMidiPort::Stop() +void +BMidiPort::Stop() { - if (remoteSource != NULL) - { - remoteSource->Disconnect(localSink); + if (fRemoteSource != NULL) { + fRemoteSource->Disconnect(fLocalSink); } 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) - { return B_BAD_VALUE; - } size_t size = strlen(endp->Name()); if (size >= bufSize) - { return B_NAME_TOO_LONG; - } strcpy(name, endp->Name()); return B_OK; } -//------------------------------------------------------------------------------ void BMidiPort::_ReservedMidiPort1() { } void BMidiPort::_ReservedMidiPort2() { } void BMidiPort::_ReservedMidiPort3() { } -//------------------------------------------------------------------------------ -void BMidiPort::Run() +void +BMidiPort::Run() { - while (KeepRunning()) - { + while (KeepRunning()) snooze(50000); - } } -//------------------------------------------------------------------------------ -void BMidiPort::ScanDevices() +void +BMidiPort::ScanDevices() { EmptyDeviceList(); int32 id = 0; 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 // and a producer. Both have the same name, so we add only one of them. bool addItem = true; - for (int32 t = 0; t < devices->CountItems(); ++t) - { - BMidiEndpoint* other = (BMidiEndpoint*) devices->ItemAt(t); - if (strcmp(endp->Name(), other->Name()) == 0) - { + for (int32 t = 0; t < fDevices->CountItems(); ++t) { + BMidiEndpoint* other = (BMidiEndpoint*) fDevices->ItemAt(t); + if (strcmp(endp->Name(), other->Name()) == 0) { addItem = false; break; } } - if (addItem) - { - devices->AddItem(endp); - } - else - { + if (addItem) { + fDevices->AddItem(endp); + } else { endp->Release(); } } } -//------------------------------------------------------------------------------ -void BMidiPort::EmptyDeviceList() +void +BMidiPort::EmptyDeviceList() { - for (int32 t = 0; t < devices->CountItems(); ++t) - { - ((BMidiEndpoint*) devices->ItemAt(t))->Release(); - } + for (int32 t = 0; t < fDevices->CountItems(); ++t) + ((BMidiEndpoint*) fDevices->ItemAt(t))->Release(); - devices->MakeEmpty(); + fDevices->MakeEmpty(); } -//------------------------------------------------------------------------------ diff --git a/src/kits/midi/MidiStore.cpp b/src/kits/midi/MidiStore.cpp index 25cf316c75..4820191647 100644 --- a/src/kits/midi/MidiStore.cpp +++ b/src/kits/midi/MidiStore.cpp @@ -1,37 +1,23 @@ /* - * Copyright (c) 2002-2004 Matthijs Hollemans - * Copyright (c) 2002 Jerome Leveque - * Copyright (c) 2002 Paul Stadler + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque + * Paul Stadler */ #include #include +#include +#include #include #include -#include "MidiDefs.h" -#include "MidiStore.h" #include "debug.h" -//------------------------------------------------------------------------------ struct BMidiEvent { BMidiEvent() @@ -74,29 +60,29 @@ compare_events(const void* event1, const void* event2) BMidiStore::BMidiStore() { - events = new BList; - currentEvent = 0; - startTime = 0; - needsSorting = false; - beatsPerMinute = 60; - ticksPerBeat = 240; - file = NULL; - hookFunc = NULL; - looping = false; - paused = false; - finished = false; - instruments = new bool[128]; + fEvents = new BList; + fCurrentEvent = 0; + fStartTime = 0; + fNeedsSorting = false; + fBeatsPerMinute = 60; + fTicksPerBeat = 240; + fFile = NULL; + fHookFunc = NULL; + fLooping = false; + fPaused = false; + fFinished = false; + fInstruments = new bool[128]; } BMidiStore::~BMidiStore() { - for (int32 t = 0; t < events->CountItems(); ++t) { + for (int32 t = 0; t < fEvents->CountItems(); ++t) { delete EventAt(t); } - delete events; - delete[] instruments; + delete fEvents; + delete[] fInstruments; } @@ -250,12 +236,12 @@ BMidiStore::TempoChange(int32 beatsPerMinute, uint32 time) status_t BMidiStore::Import(const entry_ref* ref) { - memset(instruments, 0, 128 * sizeof(bool)); + memset(fInstruments, 0, 128 * sizeof(bool)); try { - file = new BFile(ref, B_READ_ONLY); - if (file->InitCheck() != B_OK) - throw file->InitCheck(); + fFile = new BFile(ref, B_READ_ONLY); + if (fFile->InitCheck() != B_OK) + throw fFile->InitCheck(); char fourcc[4]; ReadFourCC(fourcc); @@ -265,30 +251,30 @@ BMidiStore::Import(const entry_ref* ref) if (Read32Bit() != 6) throw (status_t) B_BAD_MIDI_DATA; - format = Read16Bit(); - numTracks = Read16Bit(); - ticksPerBeat = Read16Bit(); + fFormat = Read16Bit(); + fNumTracks = Read16Bit(); + fTicksPerBeat = Read16Bit(); - if (ticksPerBeat & 0x8000) { + if (fTicksPerBeat & 0x8000) { // we don't support SMPTE time codes, // only ticks per quarter note - ticksPerBeat = 240; + fTicksPerBeat = 240; } - currTrack = 0; - while (currTrack < numTracks) { + fCurrTrack = 0; + while (fCurrTrack < fNumTracks) { ReadChunk(); } } catch (status_t e) { - delete file; - file = NULL; + delete fFile; + fFile = NULL; return e; } SortEvents(true); - delete file; - file = NULL; + delete fFile; + fFile = NULL; return B_OK; } @@ -297,9 +283,9 @@ status_t BMidiStore::Export(const entry_ref* ref, int32 format) { try { - file = new BFile(ref, B_READ_WRITE); - if (file->InitCheck() != B_OK) - throw file->InitCheck(); + fFile = new BFile(ref, B_READ_WRITE); + if (fFile->InitCheck() != B_OK) + throw fFile->InitCheck(); SortEvents(true); @@ -307,17 +293,17 @@ BMidiStore::Export(const entry_ref* ref, int32 format) Write32Bit(6); Write16Bit(0); // we do only format 0 Write16Bit(1); - Write16Bit(ticksPerBeat); + Write16Bit(fTicksPerBeat); WriteTrack(); } catch (status_t e) { - delete file; - file = NULL; + delete fFile; + fFile = NULL; return e; } - delete file; - file = NULL; + delete fFile; + fFile = NULL; return B_OK; } @@ -325,9 +311,9 @@ BMidiStore::Export(const entry_ref* ref, int32 format) void BMidiStore::SortEvents(bool force) { - if (force || needsSorting) { - events->SortItems(compare_events); - needsSorting = false; + if (force || fNeedsSorting) { + fEvents->SortItems(compare_events); + fNeedsSorting = false; } } @@ -335,21 +321,21 @@ BMidiStore::SortEvents(bool force) uint32 BMidiStore::CountEvents() const { - return events->CountItems(); + return fEvents->CountItems(); } uint32 BMidiStore::CurrentEvent() const { - return currentEvent; + return fCurrentEvent; } void BMidiStore::SetCurrentEvent(uint32 eventNumber) { - currentEvent = eventNumber; + fCurrentEvent = eventNumber; } @@ -373,7 +359,7 @@ BMidiStore::DeltaOfEvent(uint32 eventNumber) const uint32 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) return t; } @@ -385,30 +371,28 @@ BMidiStore::EventAtDelta(uint32 time) const uint32 BMidiStore::BeginTime() const { - return startTime; + return fStartTime; } void BMidiStore::SetTempo(int32 beatsPerMinute_) { - beatsPerMinute = beatsPerMinute_; + fBeatsPerMinute = beatsPerMinute_; } int32 BMidiStore::Tempo() const { - return beatsPerMinute; + return fBeatsPerMinute; } -//------------------------------------------------------------------------------ void BMidiStore::_ReservedMidiStore1() { } void BMidiStore::_ReservedMidiStore2() { } void BMidiStore::_ReservedMidiStore3() { } -//------------------------------------------------------------------------------ void BMidiStore::Run() @@ -417,8 +401,8 @@ BMidiStore::Run() // but also by BMidiSynthFile. The "paused", "finished", and "looping" // flags, and the "stop hook" are especially provided for the latter. - paused = false; - finished = false; + fPaused = false; + fFinished = false; int32 timeAdjust = 0; uint32 baseTime = 0; @@ -426,26 +410,26 @@ BMidiStore::Run() bool resetTime = false; while (KeepRunning()) { - if (paused) { + if (fPaused) { resetTime = true; snooze(100000); continue; } - BMidiEvent* event = EventAt(currentEvent); + BMidiEvent* event = EventAt(fCurrentEvent); if (event == NULL) { // no more events - if (looping) { + if (fLooping) { resetTime = true; - currentEvent = 0; + fCurrentEvent = 0; } else break; } if (firstEvent) { - startTime = B_NOW; - baseTime = startTime; + fStartTime = B_NOW; + baseTime = fStartTime; } else if (resetTime) baseTime = B_NOW; @@ -457,22 +441,22 @@ BMidiStore::Run() } else SprayEvent(event, GetEventTime(event) + timeAdjust); - ++currentEvent; + ++fCurrentEvent; } - finished = true; - paused = false; + fFinished = true; + fPaused = false; - if (hookFunc != NULL) - (*hookFunc)(hookArg); + if (fHookFunc != NULL) + (*fHookFunc)(fHookArg); } void BMidiStore::AddEvent(BMidiEvent* event) { - events->AddItem(event); - needsSorting = true; + fEvents->AddItem(event); + fNeedsSorting = true; } @@ -538,7 +522,7 @@ BMidiStore::SprayEvent(const BMidiEvent* event, uint32 time) case B_SYSTEM_RESET: if (byte2 == 0x51 && byte3 == 0x03) { SprayTempoChange(event->tempo, time); - beatsPerMinute = event->tempo; + fBeatsPerMinute = event->tempo; } else SpraySystemRealTime(byte1, time); return; @@ -551,7 +535,7 @@ BMidiStore::SprayEvent(const BMidiEvent* event, uint32 time) BMidiEvent* 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 BMidiStore::TicksToMilliseconds(uint32 ticks) const { - return ((uint64)ticks * 60000) / (beatsPerMinute * ticksPerBeat); + return ((uint64)ticks * 60000) / (fBeatsPerMinute * fTicksPerBeat); } uint32 BMidiStore::MillisecondsToTicks(uint32 ms) const { - return ((uint64)ms * beatsPerMinute * ticksPerBeat) / 60000; + return ((uint64)ms * fBeatsPerMinute * fTicksPerBeat) / 60000; } void BMidiStore::ReadFourCC(char* fourcc) { - if (file->Read(fourcc, 4) != 4) + if (fFile->Read(fourcc, 4) != 4) 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 }; - if (file->Write(fourcc, 4) != 4) + if (fFile->Write(fourcc, 4) != 4) throw (status_t) B_ERROR; } @@ -601,7 +585,7 @@ uint32 BMidiStore::Read32Bit() { uint8 buf[4]; - if (file->Read(buf, 4) != 4) + if (fFile->Read(buf, 4) != 4) throw (status_t) B_BAD_MIDI_DATA; 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[3] = val & 0xFF; - if (file->Write(buf, 4) != 4) + if (fFile->Write(buf, 4) != 4) throw (status_t) B_ERROR; } @@ -626,7 +610,7 @@ uint16 BMidiStore::Read16Bit() { uint8 buf[2]; - if (file->Read(buf, 2) != 2) + if (fFile->Read(buf, 2) != 2) throw (status_t) B_BAD_MIDI_DATA; return (buf[0] << 8) | buf[1]; @@ -640,7 +624,7 @@ BMidiStore::Write16Bit(uint16 val) buf[0] = (val >> 8) & 0xFF; buf[1] = val & 0xFF; - if (file->Write(buf, 2) != 2) + if (fFile->Write(buf, 2) != 2) throw (status_t) B_ERROR; } @@ -649,10 +633,10 @@ uint8 BMidiStore::PeekByte() { uint8 buf; - if (file->Read(&buf, 1) != 1) + if (fFile->Read(&buf, 1) != 1) 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; return buf; @@ -663,10 +647,10 @@ uint8 BMidiStore::NextByte() { uint8 buf; - if (file->Read(&buf, 1) != 1) + if (fFile->Read(&buf, 1) != 1) throw (status_t) B_BAD_MIDI_DATA; - --byteCount; + --fByteCount; return buf; } @@ -674,21 +658,21 @@ BMidiStore::NextByte() void BMidiStore::WriteByte(uint8 val) { - if (file->Write(&val, 1) != 1) + if (fFile->Write(&val, 1) != 1) throw (status_t) B_ERROR; - ++byteCount; + ++fByteCount; } void 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; } - byteCount -= length; + fByteCount -= length; } @@ -735,7 +719,7 @@ BMidiStore::ReadChunk() char fourcc[4]; ReadFourCC(fourcc); - byteCount = Read32Bit(); + fByteCount = Read32Bit(); if (strncmp(fourcc, "MTrk", 4) == 0) ReadTrack(); @@ -743,7 +727,7 @@ BMidiStore::ReadChunk() TRACE(("Skipping '%c%c%c%c' chunk (%lu bytes)", fourcc[0], fourcc[1], fourcc[2], fourcc[3], byteCount)) - SkipBytes(byteCount); + SkipBytes(fByteCount); } } @@ -756,11 +740,11 @@ BMidiStore::ReadTrack() uint8 data2; BMidiEvent* event; - totalTicks = 0; + fTotalTicks = 0; - while (byteCount > 0) { + while (fByteCount > 0) { uint32 ticks = ReadVarLength(); - totalTicks += ticks; + fTotalTicks += ticks; if (PeekByte() & 0x80) status = NextByte(); @@ -774,7 +758,7 @@ BMidiStore::ReadTrack() data1 = NextByte(); data2 = NextByte(); event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = status; event->byte2 = data1; @@ -786,14 +770,14 @@ BMidiStore::ReadTrack() case B_CHANNEL_PRESSURE: data1 = NextByte(); event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = status; event->byte2 = data1; AddEvent(event); if ((status & 0xF0) == B_PROGRAM_CHANGE) - instruments[data1] = true; + fInstruments[data1] = true; break; case 0xF0: @@ -810,7 +794,7 @@ BMidiStore::ReadTrack() case B_STOP: case B_ACTIVE_SENSING: event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = status; AddEvent(event); @@ -821,7 +805,7 @@ BMidiStore::ReadTrack() case B_CABLE_MESSAGE: data1 = NextByte(); event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = status; event->byte2 = data1; @@ -832,7 +816,7 @@ BMidiStore::ReadTrack() data1 = NextByte(); data2 = NextByte(); event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = status; event->byte2 = data1; @@ -850,7 +834,7 @@ BMidiStore::ReadTrack() event = NULL; } - ++currTrack; + ++fCurrTrack; } @@ -879,7 +863,7 @@ BMidiStore::ReadMetaEvent() uint32 val = (data[0] << 16) | (data[1] << 8) | data[2]; BMidiEvent* event = new BMidiEvent; - event->time = totalTicks; + event->time = fTotalTicks; event->ticks = true; event->byte1 = 0xFF; event->byte2 = 0x51; @@ -895,10 +879,10 @@ void BMidiStore::WriteTrack() { WriteFourCC('M', 'T', 'r', 'k'); - off_t lengthPos = file->Position(); + off_t lengthPos = fFile->Position(); Write32Bit(0); - byteCount = 0; + fByteCount = 0; uint32 oldTime = 0; uint32 newTime; @@ -976,9 +960,9 @@ BMidiStore::WriteTrack() WriteByte(0x2F); // marker is required WriteByte(0x00); - file->Seek(lengthPos, SEEK_SET); - Write32Bit(byteCount); - file->Seek(0, SEEK_END); + fFile->Seek(lengthPos, SEEK_SET); + Write32Bit(fByteCount); + fFile->Seek(0, SEEK_END); } diff --git a/src/kits/midi/MidiSynth.cpp b/src/kits/midi/MidiSynth.cpp index fdd1854597..9c20a19aac 100644 --- a/src/kits/midi/MidiSynth.cpp +++ b/src/kits/midi/MidiSynth.cpp @@ -1,24 +1,11 @@ /* - * Copyright (c) 2002-2004 Matthijs Hollemans - * Copyright (c) 2003 Jerome Leveque + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque */ #include @@ -28,240 +15,219 @@ using namespace BPrivate; -//------------------------------------------------------------------------------ BMidiSynth::BMidiSynth() { - if (be_synth == NULL) - { + if (be_synth == NULL) { new BSynth(); } - be_synth->clientCount++; + be_synth->fClientCount++; - inputEnabled = false; - transpose = 0; - creationTime = system_time(); + fInputEnabled = false; + fTranspose = 0; + fCreationTime = system_time(); } -//------------------------------------------------------------------------------ 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; - inputEnabled = enable; + fInputEnabled = enable; if (loadInstruments) { - err = be_synth->synth->LoadAllInstruments(); + err = be_synth->fSynth->LoadAllInstruments(); } 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"); } -//------------------------------------------------------------------------------ -void BMidiSynth::GetMuteMap(char* pChannels) const +void +BMidiSynth::GetMuteMap(char* pChannels) const { 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"); } -//------------------------------------------------------------------------------ -void BMidiSynth::GetSoloMap(char* pChannels) const +void +BMidiSynth::GetSoloMap(char* pChannels) const { 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) { - if (inputEnabled) - { - be_synth->synth->NoteOff(channel, note + transpose, velocity, time); - } + if (fInputEnabled) + be_synth->fSynth->NoteOff(channel, note + fTranspose, velocity, time); } -//------------------------------------------------------------------------------ -void BMidiSynth::NoteOn( +void +BMidiSynth::NoteOn( uchar channel, uchar note, uchar velocity, uint32 time) { - if (inputEnabled) - { - be_synth->synth->NoteOn(channel, note + transpose, velocity, time); - } + if (fInputEnabled) + be_synth->fSynth->NoteOn(channel, note + fTranspose, velocity, time); } -//------------------------------------------------------------------------------ -void BMidiSynth::KeyPressure( +void +BMidiSynth::KeyPressure( uchar channel, uchar note, uchar pressure, uint32 time) { - if (inputEnabled) - { - be_synth->synth->KeyPressure( - channel, note + transpose, pressure, time); - } + if (fInputEnabled) + be_synth->fSynth->KeyPressure( + channel, note + fTranspose, pressure, time); } -//------------------------------------------------------------------------------ -void BMidiSynth::ControlChange( +void +BMidiSynth::ControlChange( uchar channel, uchar controlNumber, uchar controlValue, uint32 time) { - if (inputEnabled) - { - be_synth->synth->ControlChange( + if (fInputEnabled) + be_synth->fSynth->ControlChange( channel, controlNumber, controlValue, time); - } } -//------------------------------------------------------------------------------ -void BMidiSynth::ProgramChange( +void +BMidiSynth::ProgramChange( uchar channel, uchar programNumber, uint32 time) { - if (inputEnabled) - { - be_synth->synth->ProgramChange(channel, programNumber, time); - } + if (fInputEnabled) + be_synth->fSynth->ProgramChange(channel, programNumber, time); } -//------------------------------------------------------------------------------ -void BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time) +void +BMidiSynth::ChannelPressure(uchar channel, uchar pressure, uint32 time) { - if (inputEnabled) - { - be_synth->synth->ChannelPressure(channel, pressure, time); - } + if (fInputEnabled) + be_synth->fSynth->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) - { - be_synth->synth->PitchBend(channel, lsb, msb, time); - } + if (fInputEnabled) + be_synth->fSynth->PitchBend(channel, lsb, msb, time); } -//------------------------------------------------------------------------------ -void BMidiSynth::AllNotesOff(bool justChannel, uint32 time) +void +BMidiSynth::AllNotesOff(bool justChannel, uint32 time) { - if (inputEnabled) - { - be_synth->synth->AllNotesOff(justChannel, time); - } + if (fInputEnabled) + be_synth->fSynth->AllNotesOff(justChannel, time); } -//------------------------------------------------------------------------------ void BMidiSynth::_ReservedMidiSynth1() { } void BMidiSynth::_ReservedMidiSynth2() { } void BMidiSynth::_ReservedMidiSynth3() { } void BMidiSynth::_ReservedMidiSynth4() { } -//------------------------------------------------------------------------------ -void BMidiSynth::Run() +void +BMidiSynth::Run() { // do nothing } -//------------------------------------------------------------------------------ diff --git a/src/kits/midi/MidiSynthFile.cpp b/src/kits/midi/MidiSynthFile.cpp index bcedfeb9a5..75cc757b3a 100644 --- a/src/kits/midi/MidiSynthFile.cpp +++ b/src/kits/midi/MidiSynthFile.cpp @@ -1,69 +1,49 @@ /* - * Copyright (c) 2002-2004 Matthijs Hollemans - * Copyright (c) 2003 Jerome Leveque + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * + * Matthijs Hollemans + * Jérôme Leveque */ #include "debug.h" -#include "MidiStore.h" -#include "MidiSynthFile.h" +#include +#include #include "SoftSynth.h" using namespace BPrivate; -// ----------------------------------------------------------------------------- BMidiSynthFile::BMidiSynthFile() { - store = new BMidiStore(); + fStore = new BMidiStore(); } -// ----------------------------------------------------------------------------- BMidiSynthFile::~BMidiSynthFile() { 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) - { return B_BAD_VALUE; - } 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) - { - for (int t = 0; t < 128; ++t) - { - if (store->instruments[t]) - { - be_synth->synth->LoadInstrument(t); + if (err == B_OK) { + for (int t = 0; t < 128; ++t) { + if (fStore->fInstruments[t]) { + be_synth->fSynth->LoadInstrument(t); } } } @@ -71,84 +51,82 @@ status_t BMidiSynthFile::LoadFile(const entry_ref* midi_entry_ref) return err; } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::UnloadFile(void) +void +BMidiSynthFile::UnloadFile(void) { - delete store; - store = new BMidiStore(); + delete fStore; + fStore = new BMidiStore(); } -// ----------------------------------------------------------------------------- -status_t BMidiSynthFile::Start(void) +status_t +BMidiSynthFile::Start(void) { - store->Connect(this); - store->SetCurrentEvent(0); - return store->Start(); + fStore->Connect(this); + fStore->SetCurrentEvent(0); + return fStore->Start(); } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::Stop(void) +void +BMidiSynthFile::Stop(void) { - store->Stop(); - store->Disconnect(this); + fStore->Stop(); + fStore->Disconnect(this); } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::Fade(void) +void +BMidiSynthFile::Fade(void) { 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 count = 0; - for (int t = 0; t < 128; ++t) - { - if (store->instruments[t]) - { + for (int t = 0; t < 128; ++t) { + if (fStore->fInstruments[t]) { pArray768[count++] = t; } } @@ -157,81 +135,79 @@ status_t BMidiSynthFile::GetPatches( return B_OK; } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg) +void +BMidiSynthFile::SetFileHook(synth_file_hook pSongHook, int32 arg) { - store->hookFunc = pSongHook; - store->hookArg = arg; + fStore->fHookFunc = pSongHook; + 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"); } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::GetMuteMap(char* pTracks) const +void +BMidiSynthFile::GetMuteMap(char* pTracks) const { 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"); } -// ----------------------------------------------------------------------------- -void BMidiSynthFile::GetSoloMap(char* pTracks) const +void +BMidiSynthFile::GetSoloMap(char* pTracks) const { fprintf(stderr, "[midi] GetSoloMap is broken; don't use it\n"); } -// ----------------------------------------------------------------------------- void BMidiSynthFile::_ReservedMidiSynthFile1() { } void BMidiSynthFile::_ReservedMidiSynthFile2() { } void BMidiSynthFile::_ReservedMidiSynthFile3() { } -// ----------------------------------------------------------------------------- diff --git a/src/kits/midi/MidiText.cpp b/src/kits/midi/MidiText.cpp index f9d093e978..4b44889772 100644 --- a/src/kits/midi/MidiText.cpp +++ b/src/kits/midi/MidiText.cpp @@ -1,186 +1,165 @@ /* - * Copyright (c) 2002-2003 Matthijs Hollemans - * Copyright (c) 2002 Jerome Leveque - * Copyright (c) 2002 Paul Stadler + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Authors: + * Jérôme Leveque + * Matthijs Hollemans + * Paul Stadler */ #include +#include #include "debug.h" -#include "MidiText.h" -//------------------------------------------------------------------------------ BMidiText::BMidiText() { - startTime = 0; + fStartTime = 0; } -//------------------------------------------------------------------------------ BMidiText::~BMidiText() { // do nothing } -//------------------------------------------------------------------------------ -void BMidiText::NoteOff( +void +BMidiText::NoteOff( uchar channel, uchar note, uchar velocity, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "B_NOTE OFF; channel = %d, note = %d, velocity = %d\n", channel, note, velocity); } -//------------------------------------------------------------------------------ -void BMidiText::NoteOn( +void +BMidiText::NoteOn( uchar channel, uchar note, uchar velocity, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "B_NOTE ON; channel = %d, note = %d, velocity = %d\n", channel, note, velocity); } -//------------------------------------------------------------------------------ -void BMidiText::KeyPressure( +void +BMidiText::KeyPressure( uchar channel, uchar note, uchar pressure, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "KEY PRESSURE; channel = %d, note = %d, pressure = %d\n", channel, note, pressure); } -//------------------------------------------------------------------------------ -void BMidiText::ControlChange( +void +BMidiText::ControlChange( uchar channel, uchar controlNumber, uchar controlValue, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "CONTROL CHANGE; channel = %d, control = %d, value = %d\n", channel, controlNumber, controlValue); } -//------------------------------------------------------------------------------ -void BMidiText::ProgramChange( +void +BMidiText::ProgramChange( uchar channel, uchar programNumber, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "PROGRAM CHANGE; channel = %d, program = %d\n", 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( "CHANNEL PRESSURE; channel = %d, pressure = %d\n", 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( "PITCH BEND; channel = %d, lsb = %d, msb = %d\n", 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"); for (size_t t = 0; t < length; ++t) - { printf("%02X ", ((uint8*) data)[t]); - } printf("\n"); } -//------------------------------------------------------------------------------ -void BMidiText::SystemCommon( +void +BMidiText::SystemCommon( uchar status, uchar data1, uchar data2, uint32 time) { - WaitAndPrint(time); + _WaitAndPrint(time); printf( "SYSTEM COMMON; status = %d, data1 = %d, data2 = %d\n", 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); } -//------------------------------------------------------------------------------ -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::_ReservedMidiText2() { } void BMidiText::_ReservedMidiText3() { } -//------------------------------------------------------------------------------ -void BMidiText::Run() +void +BMidiText::Run() { while (KeepRunning()) - { snooze(50000); - } } -//------------------------------------------------------------------------------ -void BMidiText::WaitAndPrint(uint32 time) +void +BMidiText::_WaitAndPrint(uint32 time) { - if (startTime == 0) { startTime = time; } + if (fStartTime == 0) + fStartTime = time; SnoozeUntil(time); - printf("%lu: ", time - startTime); + printf("%lu: ", time - fStartTime); } -//------------------------------------------------------------------------------ diff --git a/src/kits/midi/SoftSynth.cpp b/src/kits/midi/SoftSynth.cpp index 96f57d127e..ccccbd0c9f 100644 --- a/src/kits/midi/SoftSynth.cpp +++ b/src/kits/midi/SoftSynth.cpp @@ -55,7 +55,7 @@ bool BSoftSynth::InitCheck() { if (!fSynth) - Init(); + _Init(); return fInitCheck; } @@ -63,7 +63,7 @@ BSoftSynth::InitCheck() void BSoftSynth::Unload(void) { - Done(); + _Done(); free(fInstrumentsFile); fInstrumentsFile = NULL; } @@ -418,12 +418,12 @@ BSoftSynth::AllNotesOff(bool justChannel, uint32 time) void -BSoftSynth::Init() +BSoftSynth::_Init() { status_t err; fInitCheck = false; - Done(); + _Done(); fSettings = new_fluid_settings(); fluid_settings_setnum(fSettings, "synth.sample-rate", fSampleRate); @@ -455,7 +455,7 @@ BSoftSynth::Init() void -BSoftSynth::Done() +BSoftSynth::_Done() { if (fSoundPlayer) { fSoundPlayer->SetHasData(false); diff --git a/src/kits/midi/SoftSynth.h b/src/kits/midi/SoftSynth.h index 67ade30bb5..f2b8c1f1e5 100644 --- a/src/kits/midi/SoftSynth.h +++ b/src/kits/midi/SoftSynth.h @@ -88,8 +88,8 @@ private: BSoftSynth(); ~BSoftSynth(); - void Init(); - void Done(); + void _Init(); + void _Done(); static void PlayBuffer(void * cookie, void * data, size_t size, const media_raw_audio_format & format); bool fInitCheck; diff --git a/src/kits/midi/Synth.cpp b/src/kits/midi/Synth.cpp index 54feb75d01..efdbb54d2d 100644 --- a/src/kits/midi/Synth.cpp +++ b/src/kits/midi/Synth.cpp @@ -18,32 +18,29 @@ BSynth* be_synth = NULL; using namespace BPrivate; -//------------------------------------------------------------------------------ BSynth::BSynth() { - Init(); + _Init(); } -//------------------------------------------------------------------------------ BSynth::BSynth(synth_mode mode) { - Init(); - synthMode = mode; + _Init(); + fSynthMode = mode; } -//------------------------------------------------------------------------------ BSynth::~BSynth() { - delete synth; + delete fSynth; be_synth = NULL; } -//------------------------------------------------------------------------------ -status_t BSynth::LoadSynthData(entry_ref* instrumentsFile) +status_t +BSynth::LoadSynthData(entry_ref* instrumentsFile) { if (instrumentsFile == NULL) { return B_BAD_VALUE; @@ -53,173 +50,170 @@ status_t BSynth::LoadSynthData(entry_ref* instrumentsFile) status_t err = path.InitCheck(); if (err != B_OK) 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. // Therefore, if you use this function, the synth will revert to its // default instruments bank. However, we do keep track of the current // synth_mode here, in order not to confuse old applications. - synthMode = mode; - if (synthMode == B_SAMPLES_ONLY) - { + fSynthMode = mode; + if (fSynthMode == B_SAMPLES_ONLY) { 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) { status_t err = B_OK; - err = synth->SetMaxVoices(maxSynthVoices); - if (err == B_OK) - { - err = synth->SetLimiterThreshold(limiterThreshhold); + err = fSynth->SetMaxVoices(maxSynthVoices); + if (err == B_OK) { + err = fSynth->SetLimiterThreshold(limiterThreshhold); } 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"); 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"); } -//------------------------------------------------------------------------------ -double BSynth::SampleVolume(void) const +double +BSynth::SampleVolume(void) const { fprintf(stderr, "[midi] SampleVolume: BSamples not supported\n"); return 0; } -//------------------------------------------------------------------------------ -status_t BSynth::GetAudio( - int16* pLeft, int16* pRight, int32 max_samples) const +status_t +BSynth::GetAudio(int16* pLeft, int16* pRight, int32 max_samples) const { // We don't print a "not supported" message here. That would cause // significant slowdowns because applications ask for this many times. @@ -230,50 +224,48 @@ status_t BSynth::GetAudio( 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"); } -//------------------------------------------------------------------------------ -void BSynth::Init() +void +BSynth::_Init() { delete be_synth; be_synth = this; - synthMode = B_NO_SYNTH; - clientCount = 0; - synth = new BSoftSynth(); + fSynthMode = B_NO_SYNTH; + fClientCount = 0; + fSynth = new BSoftSynth(); } -//------------------------------------------------------------------------------ -int32 BSynth::CountClients(void) const +int32 +BSynth::CountClients() const { - return clientCount; + return fClientCount; } -//------------------------------------------------------------------------------ void BSynth::_ReservedSynth1() { } void BSynth::_ReservedSynth2() { } void BSynth::_ReservedSynth3() { } void BSynth::_ReservedSynth4() { } -//------------------------------------------------------------------------------