Added Live Input. Not complete yet.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8168 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@ App MidiPlayer :
|
||||
MidiPlayerApp.cpp
|
||||
MidiPlayerWindow.cpp
|
||||
ScopeView.cpp
|
||||
SynthBridge.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs MidiPlayer :
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <MidiProducer.h>
|
||||
#include <MidiRoster.h>
|
||||
#include <StorageKit.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -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 <MidiConsumer.h>
|
||||
#include <MidiSynth.h>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user