From c79a596fb1f36d327a265b0e84340e03f710df81 Mon Sep 17 00:00:00 2001 From: mahlzeit Date: Fri, 25 Jun 2004 15:19:29 +0000 Subject: [PATCH] Added Live Input. Not complete yet. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8168 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/midiplayer/Jamfile | 1 + src/apps/midiplayer/MidiPlayerWindow.cpp | 44 +++++++-- src/apps/midiplayer/MidiPlayerWindow.h | 3 + src/apps/midiplayer/ScopeView.cpp | 8 ++ src/apps/midiplayer/ScopeView.h | 2 + src/apps/midiplayer/SynthBridge.cpp | 116 +++++++++++++++++++++++ src/apps/midiplayer/SynthBridge.h | 73 ++++++++++++++ 7 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 src/apps/midiplayer/SynthBridge.cpp create mode 100644 src/apps/midiplayer/SynthBridge.h diff --git a/src/apps/midiplayer/Jamfile b/src/apps/midiplayer/Jamfile index a9de4cd0fa..ca29f7293e 100644 --- a/src/apps/midiplayer/Jamfile +++ b/src/apps/midiplayer/Jamfile @@ -8,6 +8,7 @@ App MidiPlayer : MidiPlayerApp.cpp MidiPlayerWindow.cpp ScopeView.cpp + SynthBridge.cpp ; LinkSharedOSLibs MidiPlayer : diff --git a/src/apps/midiplayer/MidiPlayerWindow.cpp b/src/apps/midiplayer/MidiPlayerWindow.cpp index 39afe18857..93048f7eab 100644 --- a/src/apps/midiplayer/MidiPlayerWindow.cpp +++ b/src/apps/midiplayer/MidiPlayerWindow.cpp @@ -20,12 +20,14 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include #include #include "MidiPlayerApp.h" #include "MidiPlayerWindow.h" #include "ScopeView.h" +#include "SynthBridge.h" #define _W(a) (a->Frame().Width()) #define _H(a) (a->Frame().Height()) @@ -43,9 +45,13 @@ MidiPlayerWindow::MidiPlayerWindow() windowX = -1; windowY = -1; inputId = -1; + instrLoaded = false; be_synth->SetSamplingRate(44100); + bridge = new SynthBridge; + //bridge->Register(); + CreateViews(); LoadSettings(); InitControls(); @@ -56,6 +62,9 @@ MidiPlayerWindow::MidiPlayerWindow() MidiPlayerWindow::~MidiPlayerWindow() { StopSynth(); + + //bridge->Unregister(); + bridge->Release(); } //------------------------------------------------------------------------------ @@ -547,15 +556,36 @@ void MidiPlayerWindow::OnInputChanged(BMessage* msg) int32 newId; if (msg->FindInt32("id", &newId) == B_OK) { + if (!instrLoaded) + { + scopeView->SetLoading(true); + scopeView->Invalidate(); + UpdateIfNeeded(); + + bridge->Init(B_BIG_SYNTH); + instrLoaded = true; + + scopeView->SetLoading(false); + scopeView->Invalidate(); + } + + BMidiProducer* endp; + + endp = BMidiRoster::FindProducer(inputId); + if (endp != NULL) + { + endp->Disconnect(bridge); + endp->Release(); + } + inputId = newId; - // if (!instrLoaded) - // be_synth->LoadInstruments(all) - - // if id != -1 - // connect SynthBridge (from MidiUtil) to producer endpoint - // else if SynthBridge still connected - // disconnect SynthBridge + endp = BMidiRoster::FindProducer(inputId); + if (endp != NULL) + { + endp->Connect(bridge); + endp->Release(); + } } } diff --git a/src/apps/midiplayer/MidiPlayerWindow.h b/src/apps/midiplayer/MidiPlayerWindow.h index d305fcc76a..7fb57db353 100644 --- a/src/apps/midiplayer/MidiPlayerWindow.h +++ b/src/apps/midiplayer/MidiPlayerWindow.h @@ -43,6 +43,7 @@ enum }; class ScopeView; +class SynthBridge; class MidiPlayerWindow : public BWindow { @@ -105,6 +106,8 @@ private: float windowX; float windowY; BMidiSynthFile synth; + SynthBridge* bridge; + bool instrLoaded; }; #endif // MIDI_PLAYER_WINDOW_H diff --git a/src/apps/midiplayer/ScopeView.cpp b/src/apps/midiplayer/ScopeView.cpp index ba9c514044..ccbc3cac01 100644 --- a/src/apps/midiplayer/ScopeView.cpp +++ b/src/apps/midiplayer/ScopeView.cpp @@ -36,6 +36,7 @@ ScopeView::ScopeView() playing = false; enabled = true; haveFile = false; + loading = false; sampleCount = (int32) Bounds().Width(); leftSamples = new int16[sampleCount]; @@ -121,6 +122,13 @@ void ScopeView::SetHaveFile(bool flag) //------------------------------------------------------------------------------ +void ScopeView::SetLoading(bool flag) +{ + loading = flag; +} + +//------------------------------------------------------------------------------ + int32 ScopeView::_Thread(void* data) { return ((ScopeView*) data)->Thread(); diff --git a/src/apps/midiplayer/ScopeView.h b/src/apps/midiplayer/ScopeView.h index a0451d2af3..ad93562f95 100644 --- a/src/apps/midiplayer/ScopeView.h +++ b/src/apps/midiplayer/ScopeView.h @@ -39,6 +39,7 @@ public: void SetPlaying(bool flag); void SetEnabled(bool flag); void SetHaveFile(bool flag); + void SetLoading(bool flag); private: @@ -56,6 +57,7 @@ private: bool playing; bool enabled; bool haveFile; + bool loading; int32 sampleCount; int16* leftSamples; int16* rightSamples; diff --git a/src/apps/midiplayer/SynthBridge.cpp b/src/apps/midiplayer/SynthBridge.cpp new file mode 100644 index 0000000000..85eaa40235 --- /dev/null +++ b/src/apps/midiplayer/SynthBridge.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2004 Matthijs Hollemans + * + * 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. + */ + +#include "SynthBridge.h" + +//------------------------------------------------------------------------------ + +SynthBridge::SynthBridge() + : BMidiLocalConsumer("Internal Synthesizer") +{ + // do nothing +} + +//------------------------------------------------------------------------------ + +bool SynthBridge::Init(synth_mode mode) +{ + if (be_synth->LoadSynthData(mode) == B_OK) + { + midiSynth.EnableInput(true, true); + return true; + } + return false; +} + +//------------------------------------------------------------------------------ + +BMidiSynth* SynthBridge::MidiSynth() +{ + return &midiSynth; +} + +//------------------------------------------------------------------------------ + +void SynthBridge::NoteOff( + uchar channel, uchar note, uchar velocity, bigtime_t time) +{ + midiSynth.NoteOff(channel + 1, note, velocity, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::NoteOn( + uchar channel, uchar note, uchar velocity, bigtime_t time) +{ + midiSynth.NoteOn(channel + 1, note, velocity, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::KeyPressure( + uchar channel, uchar note, uchar pressure, bigtime_t time) +{ + midiSynth.KeyPressure(channel + 1, note, pressure, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::ControlChange( + uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time) +{ + midiSynth.ControlChange( + channel + 1, controlNumber, controlValue, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::ProgramChange( + uchar channel, uchar programNumber, bigtime_t time) +{ + midiSynth.ProgramChange(channel + 1, programNumber, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::ChannelPressure( + uchar channel, uchar pressure, bigtime_t time) +{ + midiSynth.ChannelPressure(channel + 1, pressure, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::PitchBend( + uchar channel, uchar lsb, uchar msb, bigtime_t time) +{ + midiSynth.PitchBend(channel + 1, lsb, msb, time / 1000); +} + +//------------------------------------------------------------------------------ + +void SynthBridge::AllNotesOff(bool justChannel, bigtime_t time) +{ + midiSynth.AllNotesOff(justChannel, time / 1000); +} + +//------------------------------------------------------------------------------ diff --git a/src/apps/midiplayer/SynthBridge.h b/src/apps/midiplayer/SynthBridge.h new file mode 100644 index 0000000000..d1e5634914 --- /dev/null +++ b/src/apps/midiplayer/SynthBridge.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2004 Matthijs Hollemans + * + * 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. + */ + +#ifndef SYNTH_BRIDGE_H +#define SYNTH_BRIDGE_H + +#include +#include + +class SynthBridge : public BMidiLocalConsumer +{ +public: + + SynthBridge(); + + bool Init(synth_mode mode); + + BMidiSynth* MidiSynth(); + + virtual void NoteOff( + uchar channel, uchar note, uchar velocity, bigtime_t time); + + virtual void NoteOn( + uchar channel, uchar note, uchar velocity, bigtime_t time); + + virtual void KeyPressure( + uchar channel, uchar note, uchar pressure, bigtime_t time); + + virtual void ControlChange( + uchar channel, uchar controlNumber, uchar controlValue, + bigtime_t time); + + virtual void ProgramChange( + uchar channel, uchar programNumber, bigtime_t time); + + virtual void ChannelPressure( + uchar channel, uchar pressure, bigtime_t time); + + virtual void PitchBend( + uchar channel, uchar lsb, uchar msb, bigtime_t time); + + virtual void AllNotesOff( + bool justChannel, bigtime_t time); + +protected: + + virtual ~SynthBridge() { } + +private: + + BMidiSynth midiSynth; +}; + +#endif // SYNTH_BRIDGE_H