MidiPlayer: style overhaul

This commit is contained in:
John Scipione
2014-06-27 22:57:02 -04:00
parent e23f93739b
commit 42bcaa84c0
8 changed files with 429 additions and 431 deletions
+16 -8
View File
@@ -20,21 +20,30 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include "MidiPlayerApp.h"
#include <AboutWindow.h>
#include <Alert.h> #include <Alert.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <StorageKit.h> #include <StorageKit.h>
#include "MidiPlayerApp.h"
#include "MidiPlayerWindow.h" #include "MidiPlayerWindow.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Main Application" #define B_TRANSLATION_CONTEXT "Main Application"
// #pragma mark - MidiPlayerApp
MidiPlayerApp::MidiPlayerApp() MidiPlayerApp::MidiPlayerApp()
: BApplication(MIDI_PLAYER_SIGNATURE) :
BApplication(MIDI_PLAYER_SIGNATURE)
{ {
window = new MidiPlayerWindow; window = new MidiPlayerWindow();
} }
@@ -62,10 +71,10 @@ MidiPlayerApp::AboutRequested()
void void
MidiPlayerApp::RefsReceived(BMessage* msg) MidiPlayerApp::RefsReceived(BMessage* message)
{ {
msg->what = B_SIMPLE_DATA; message->what = B_SIMPLE_DATA;
window->PostMessage(msg); window->PostMessage(message);
} }
@@ -90,7 +99,7 @@ MidiPlayerApp::ArgvReceived(int32 argc, char** argv)
} }
// #pragma mark - // #pragma mark - main method
int int
@@ -100,4 +109,3 @@ main()
app.Run(); app.Run();
return 0; return 0;
} }
+7 -3
View File
@@ -19,13 +19,16 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef MIDI_PLAYER_APP_H #ifndef _MIDI_PLAYER_APP_H
#define MIDI_PLAYER_APP_H #define _MIDI_PLAYER_APP_H
#include <Application.h> #include <Application.h>
#define MIDI_PLAYER_SIGNATURE "application/x-vnd.Haiku-MidiPlayer" #define MIDI_PLAYER_SIGNATURE "application/x-vnd.Haiku-MidiPlayer"
class MidiPlayerWindow; class MidiPlayerWindow;
class MidiPlayerApp : public BApplication { class MidiPlayerApp : public BApplication {
@@ -42,4 +45,5 @@ class MidiPlayerApp : public BApplication {
MidiPlayerWindow* window; MidiPlayerWindow* window;
}; };
#endif // MIDI_PLAYER_APP_H
#endif // _MIDI_PLAYER_APP_H
+165 -161
View File
@@ -20,10 +20,12 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include "MidiPlayerWindow.h"
#include <Catalog.h> #include <Catalog.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <GridLayoutBuilder.h>
#include <Locale.h> #include <Locale.h>
#include <MidiProducer.h> #include <MidiProducer.h>
#include <MidiRoster.h> #include <MidiRoster.h>
@@ -31,7 +33,6 @@
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include "MidiPlayerApp.h" #include "MidiPlayerApp.h"
#include "MidiPlayerWindow.h"
#include "ScopeView.h" #include "ScopeView.h"
#include "SynthBridge.h" #include "SynthBridge.h"
@@ -44,25 +45,28 @@
#define B_TRANSLATION_CONTEXT "Main Window" #define B_TRANSLATION_CONTEXT "Main Window"
// #pragma mark - MidiPlayerWindow
MidiPlayerWindow::MidiPlayerWindow() MidiPlayerWindow::MidiPlayerWindow()
: :
BWindow(BRect(0, 0, 1, 1), B_TRANSLATE_SYSTEM_NAME("MidiPlayer"), BWindow(BRect(0, 0, 1, 1), B_TRANSLATE_SYSTEM_NAME("MidiPlayer"),
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE
| B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
playing = false; fIsPlaying = false;
scopeEnabled = true; fScopeEnabled = true;
reverb = B_REVERB_BALLROOM; fReverbMode = B_REVERB_BALLROOM;
volume = 75; fVolume = 75;
windowX = -1; fWindowX = -1;
windowY = -1; fWindowY = -1;
inputId = -1; fInputId = -1;
instrLoaded = false; fInstrumentLoaded = false;
be_synth->SetSamplingRate(44100); be_synth->SetSamplingRate(44100);
bridge = new SynthBridge; fSynthBridge = new SynthBridge;
//bridge->Register(); //fSynthBridge->Register();
CreateViews(); CreateViews();
LoadSettings(); LoadSettings();
@@ -74,8 +78,8 @@ MidiPlayerWindow::~MidiPlayerWindow()
{ {
StopSynth(); StopSynth();
//bridge->Unregister(); //fSynthBridge->Unregister();
bridge->Release(); fSynthBridge->Release();
} }
@@ -88,9 +92,9 @@ MidiPlayerWindow::QuitRequested()
void void
MidiPlayerWindow::MessageReceived(BMessage* msg) MidiPlayerWindow::MessageReceived(BMessage* message)
{ {
switch (msg->what) { switch (message->what) {
case MSG_PLAY_STOP: case MSG_PLAY_STOP:
OnPlayStop(); OnPlayStop();
break; break;
@@ -100,7 +104,7 @@ MidiPlayerWindow::MessageReceived(BMessage* msg)
break; break;
case MSG_INPUT_CHANGED: case MSG_INPUT_CHANGED:
OnInputChanged(msg); OnInputChanged(message);
break; break;
case MSG_REVERB_NONE: case MSG_REVERB_NONE:
@@ -132,11 +136,11 @@ MidiPlayerWindow::MessageReceived(BMessage* msg)
break; break;
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
OnDrop(msg); OnDrop(message);
break; break;
default: default:
super::MessageReceived(msg); super::MessageReceived(message);
break; break;
} }
} }
@@ -146,8 +150,8 @@ void
MidiPlayerWindow::FrameMoved(BPoint origin) MidiPlayerWindow::FrameMoved(BPoint origin)
{ {
super::FrameMoved(origin); super::FrameMoved(origin);
windowX = Frame().left; fWindowX = Frame().left;
windowY = Frame().top; fWindowY = Frame().top;
SaveSettings(); SaveSettings();
} }
@@ -155,23 +159,23 @@ MidiPlayerWindow::FrameMoved(BPoint origin)
void void
MidiPlayerWindow::MenusBeginning() MidiPlayerWindow::MenusBeginning()
{ {
for (int32 t = inputPopUp->CountItems() - 1; t > 0; --t) for (int32 t = fInputPopUpMenu->CountItems() - 1; t > 0; --t)
delete inputPopUp->RemoveItem(t); delete fInputPopUpMenu->RemoveItem(t);
// Note: if the selected endpoint no longer exists, then no endpoint is // Note: if the selected endpoint no longer exists, then no endpoint is
// marked. However, we won't disconnect it until you choose another one. // marked. However, we won't disconnect it until you choose another one.
inputOff->SetMarked(inputId == -1); fInputOffMenuItem->SetMarked(fInputId == -1);
int32 id = 0; int32 id = 0;
while (BMidiEndpoint* endpoint = BMidiRoster::NextEndpoint(&id)) { while (BMidiEndpoint* endpoint = BMidiRoster::NextEndpoint(&id)) {
if (endpoint->IsProducer()) { if (endpoint->IsProducer()) {
BMessage* msg = new BMessage(MSG_INPUT_CHANGED); BMessage* message = new BMessage(MSG_INPUT_CHANGED);
msg->AddInt32("id", id); message->AddInt32("id", id);
BMenuItem* item = new BMenuItem(endpoint->Name(), msg); BMenuItem* item = new BMenuItem(endpoint->Name(), message);
inputPopUp->AddItem(item); fInputPopUpMenu->AddItem(item);
item->SetMarked(inputId == id); item->SetMarked(fInputId == id);
} }
endpoint->Release(); endpoint->Release();
@@ -182,45 +186,44 @@ MidiPlayerWindow::MenusBeginning()
void void
MidiPlayerWindow::CreateInputMenu() MidiPlayerWindow::CreateInputMenu()
{ {
inputPopUp = new BPopUpMenu("inputPopUp"); fInputPopUpMenu = new BPopUpMenu("inputPopUp");
BMessage* msg = new BMessage; BMessage* message = new BMessage(MSG_INPUT_CHANGED);
msg->what = MSG_INPUT_CHANGED; message->AddInt32("id", -1);
msg->AddInt32("id", -1);
inputOff = new BMenuItem(B_TRANSLATE("Off"), msg); fInputOffMenuItem = new BMenuItem(B_TRANSLATE("Off"), message);
fInputPopUpMenu->AddItem(fInputOffMenuItem);
inputPopUp->AddItem(inputOff); fInputMenuField = new BMenuField(B_TRANSLATE("Live input:"),
fInputPopUpMenu);
inputMenu = new BMenuField(B_TRANSLATE("Live input:"), inputPopUp);
} }
void void
MidiPlayerWindow::CreateReverbMenu() MidiPlayerWindow::CreateReverbMenu()
{ {
BPopUpMenu* reverbPopUp = new BPopUpMenu("reverbPopUp"); BPopUpMenu* reverbPopUpMenu = new BPopUpMenu("reverbPopUp");
reverbNone = new BMenuItem( fReverbNoneMenuItem = new BMenuItem(B_TRANSLATE("None"),
B_TRANSLATE("None"), new BMessage(MSG_REVERB_NONE)); new BMessage(MSG_REVERB_NONE));
reverbCloset = new BMenuItem( fReverbClosetMenuItem = new BMenuItem(B_TRANSLATE("Closet"),
B_TRANSLATE("Closet"), new BMessage(MSG_REVERB_CLOSET)); new BMessage(MSG_REVERB_CLOSET));
reverbGarage = new BMenuItem( fReverbGarageMenuItem = new BMenuItem(B_TRANSLATE("Garage"),
B_TRANSLATE("Garage"), new BMessage(MSG_REVERB_GARAGE)); new BMessage(MSG_REVERB_GARAGE));
reverbIgor = new BMenuItem( fReverbIgorMenuItem = new BMenuItem(B_TRANSLATE("Igor's lab"),
B_TRANSLATE("Igor's lab"), new BMessage(MSG_REVERB_IGOR)); new BMessage(MSG_REVERB_IGOR));
reverbCavern = new BMenuItem( fReverbCavern = new BMenuItem(B_TRANSLATE("Cavern"),
B_TRANSLATE("Cavern"), new BMessage(MSG_REVERB_CAVERN)); new BMessage(MSG_REVERB_CAVERN));
reverbDungeon = new BMenuItem( fReverbDungeon = new BMenuItem(B_TRANSLATE("Dungeon"),
B_TRANSLATE("Dungeon"), new BMessage(MSG_REVERB_DUNGEON)); new BMessage(MSG_REVERB_DUNGEON));
reverbPopUp->AddItem(reverbNone); reverbPopUpMenu->AddItem(fReverbNoneMenuItem);
reverbPopUp->AddItem(reverbCloset); reverbPopUpMenu->AddItem(fReverbClosetMenuItem);
reverbPopUp->AddItem(reverbGarage); reverbPopUpMenu->AddItem(fReverbGarageMenuItem);
reverbPopUp->AddItem(reverbIgor); reverbPopUpMenu->AddItem(fReverbIgorMenuItem);
reverbPopUp->AddItem(reverbCavern); reverbPopUpMenu->AddItem(fReverbCavern);
reverbPopUp->AddItem(reverbDungeon); reverbPopUpMenu->AddItem(fReverbDungeon);
reverbMenu = new BMenuField(B_TRANSLATE("Reverb:"), reverbPopUp); fReverbMenuField = new BMenuField(B_TRANSLATE("Reverb:"), reverbPopUpMenu);
} }
@@ -228,29 +231,30 @@ void
MidiPlayerWindow::CreateViews() MidiPlayerWindow::CreateViews()
{ {
// Set up needed views // Set up needed views
scopeView = new ScopeView; fScopeView = new ScopeView();
showScope = new BCheckBox("showScope", B_TRANSLATE("Scope"), fShowScopeCheckBox = new BCheckBox("showScope", B_TRANSLATE("Scope"),
new BMessage(MSG_SHOW_SCOPE)); new BMessage(MSG_SHOW_SCOPE));
showScope->SetValue(B_CONTROL_ON); fShowScopeCheckBox->SetValue(B_CONTROL_ON);
CreateInputMenu(); CreateInputMenu();
CreateReverbMenu(); CreateReverbMenu();
volumeSlider = new BSlider("volumeSlider", NULL, NULL, 0, 100, fVolumeSlider = new BSlider("volumeSlider", NULL, NULL, 0, 100,
B_HORIZONTAL); B_HORIZONTAL);
rgb_color col = { 152, 152, 255 }; rgb_color color = (rgb_color){ 152, 152, 255 };
volumeSlider->UseFillColor(true, &col); fVolumeSlider->UseFillColor(true, &color);
volumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME)); fVolumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME));
fVolumeSlider->SetExplicitMinSize(
BSize(fScopeView->Frame().Width(), B_SIZE_UNSET));
playButton = new BButton("playButton", B_TRANSLATE("Play"), fPlayButton = new BButton("playButton", B_TRANSLATE("Play"),
new BMessage(MSG_PLAY_STOP)); new BMessage(MSG_PLAY_STOP));
playButton->SetEnabled(false); fPlayButton->SetEnabled(false);
BBox* divider = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS, BBox* divider = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS,
B_FANCY_BORDER); B_FANCY_BORDER);
divider->SetExplicitMaxSize( divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
BSize(B_SIZE_UNLIMITED, 1));
BStringView* volumeLabel = new BStringView(NULL, B_TRANSLATE("Volume:")); BStringView* volumeLabel = new BStringView(NULL, B_TRANSLATE("Volume:"));
volumeLabel->SetAlignment(B_ALIGN_LEFT); volumeLabel->SetAlignment(B_ALIGN_LEFT);
@@ -260,24 +264,24 @@ MidiPlayerWindow::CreateViews()
SetLayout(new BGroupLayout(B_HORIZONTAL)); SetLayout(new BGroupLayout(B_HORIZONTAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.Add(scopeView) .Add(fScopeView)
.Add(BGridLayoutBuilder(10, 10) .Add(BGridLayoutBuilder(10, 10)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 0) .Add(BSpaceLayoutItem::CreateGlue(), 0, 0)
.Add(showScope, 1, 0) .Add(fShowScopeCheckBox, 1, 0)
.Add(reverbMenu->CreateLabelLayoutItem(), 0, 1) .Add(fReverbMenuField->CreateLabelLayoutItem(), 0, 1)
.Add(reverbMenu->CreateMenuBarLayoutItem(), 1, 1) .Add(fReverbMenuField->CreateMenuBarLayoutItem(), 1, 1)
.Add(inputMenu->CreateLabelLayoutItem(), 0, 2) .Add(fInputMenuField->CreateLabelLayoutItem(), 0, 2)
.Add(inputMenu->CreateMenuBarLayoutItem(), 1, 2) .Add(fInputMenuField->CreateMenuBarLayoutItem(), 1, 2)
.Add(volumeLabel, 0, 3) .Add(volumeLabel, 0, 3)
.Add(volumeSlider, 1, 3) .Add(fVolumeSlider, 1, 3)
) )
.AddGlue() .AddGlue()
.Add(divider) .Add(divider)
.AddGlue() .AddGlue()
.Add(playButton) .Add(fPlayButton)
.AddGlue() .AddGlue()
.SetInsets(5, 5, 5, 5) .SetInsets(5, 5, 5, 5)
); );
@@ -289,23 +293,23 @@ MidiPlayerWindow::InitControls()
{ {
Lock(); Lock();
showScope->SetValue(scopeEnabled ? B_CONTROL_ON : B_CONTROL_OFF); fShowScopeCheckBox->SetValue(fScopeEnabled ? B_CONTROL_ON : B_CONTROL_OFF);
scopeView->SetEnabled(scopeEnabled); fScopeView->SetEnabled(fScopeEnabled);
inputOff->SetMarked(true); fInputOffMenuItem->SetMarked(true);
reverbNone->SetMarked(reverb == B_REVERB_NONE); fReverbNoneMenuItem->SetMarked(fReverbMode == B_REVERB_NONE);
reverbCloset->SetMarked(reverb == B_REVERB_CLOSET); fReverbClosetMenuItem->SetMarked(fReverbMode == B_REVERB_CLOSET);
reverbGarage->SetMarked(reverb == B_REVERB_GARAGE); fReverbGarageMenuItem->SetMarked(fReverbMode == B_REVERB_GARAGE);
reverbIgor->SetMarked(reverb == B_REVERB_BALLROOM); fReverbIgorMenuItem->SetMarked(fReverbMode == B_REVERB_BALLROOM);
reverbCavern->SetMarked(reverb == B_REVERB_CAVERN); fReverbCavern->SetMarked(fReverbMode == B_REVERB_CAVERN);
reverbDungeon->SetMarked(reverb == B_REVERB_DUNGEON); fReverbDungeon->SetMarked(fReverbMode == B_REVERB_DUNGEON);
be_synth->SetReverb(reverb); be_synth->SetReverb(fReverbMode);
volumeSlider->SetValue(volume); fVolumeSlider->SetValue(fVolume);
if (windowX != -1 && windowY != -1) if (fWindowX != -1 && fWindowY != -1)
MoveTo(windowX, windowY); MoveTo(fWindowX, fWindowY);
else else
CenterOnScreen(); CenterOnScreen();
@@ -320,11 +324,11 @@ MidiPlayerWindow::LoadSettings()
if (file.InitCheck() != B_OK || file.Lock() != B_OK) if (file.InitCheck() != B_OK || file.Lock() != B_OK)
return; return;
file.ReadAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool)); file.ReadAttr("Scope", B_BOOL_TYPE, 0, &fScopeEnabled, sizeof(bool));
file.ReadAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32)); file.ReadAttr("Reverb", B_INT32_TYPE, 0, &fReverbMode, sizeof(int32));
file.ReadAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32)); file.ReadAttr("Volume", B_INT32_TYPE, 0, &fWindowX, sizeof(int32));
file.ReadAttr("WindowX", B_FLOAT_TYPE, 0, &windowX, sizeof(float)); file.ReadAttr("WindowX", B_FLOAT_TYPE, 0, &fWindowX, sizeof(float));
file.ReadAttr("WindowY", B_FLOAT_TYPE, 0, &windowY, sizeof(float)); file.ReadAttr("WindowY", B_FLOAT_TYPE, 0, &fWindowY, sizeof(float));
file.Unlock(); file.Unlock();
} }
@@ -337,11 +341,11 @@ MidiPlayerWindow::SaveSettings()
if (file.InitCheck() != B_OK || file.Lock() != B_OK) if (file.InitCheck() != B_OK || file.Lock() != B_OK)
return; return;
file.WriteAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool)); file.WriteAttr("Scope", B_BOOL_TYPE, 0, &fScopeEnabled, sizeof(bool));
file.WriteAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32)); file.WriteAttr("Reverb", B_INT32_TYPE, 0, &fReverbMode, sizeof(int32));
file.WriteAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32)); file.WriteAttr("Volume", B_INT32_TYPE, 0, &fVolume, sizeof(int32));
file.WriteAttr("WindowX", B_FLOAT_TYPE, 0, &windowX, sizeof(float)); file.WriteAttr("WindowX", B_FLOAT_TYPE, 0, &fWindowX, sizeof(float));
file.WriteAttr("WindowY", B_FLOAT_TYPE, 0, &windowY, sizeof(float)); file.WriteAttr("WindowY", B_FLOAT_TYPE, 0, &fWindowY, sizeof(float));
file.Sync(); file.Sync();
file.Unlock(); file.Unlock();
@@ -351,35 +355,35 @@ MidiPlayerWindow::SaveSettings()
void void
MidiPlayerWindow::LoadFile(entry_ref* ref) MidiPlayerWindow::LoadFile(entry_ref* ref)
{ {
if (playing) { if (fIsPlaying) {
scopeView->SetPlaying(false); fScopeView->SetPlaying(false);
scopeView->Invalidate(); fScopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
StopSynth(); StopSynth();
} }
synth.UnloadFile(); fMidiSynthFile.UnloadFile();
if (synth.LoadFile(ref) == B_OK) { if (fMidiSynthFile.LoadFile(ref) == B_OK) {
// Ideally, we would call SetVolume() in InitControls(), // Ideally, we would call SetVolume() in InitControls(),
// but for some reason that doesn't work: BMidiSynthFile // but for some reason that doesn't work: BMidiSynthFile
// will use the default volume instead. So we do it here. // will use the default volume instead. So we do it here.
synth.SetVolume(volume / 100.0f); fMidiSynthFile.SetVolume(fVolume / 100.0f);
playButton->SetEnabled(true); fPlayButton->SetEnabled(true);
playButton->SetLabel(B_TRANSLATE("Stop")); fPlayButton->SetLabel(B_TRANSLATE("Stop"));
scopeView->SetHaveFile(true); fScopeView->SetHaveFile(true);
scopeView->SetPlaying(true); fScopeView->SetPlaying(true);
scopeView->Invalidate(); fScopeView->Invalidate();
StartSynth(); StartSynth();
} else { } else {
playButton->SetEnabled(false); fPlayButton->SetEnabled(false);
playButton->SetLabel(B_TRANSLATE("Play")); fPlayButton->SetLabel(B_TRANSLATE("Play"));
scopeView->SetHaveFile(false); fScopeView->SetHaveFile(false);
scopeView->SetPlaying(false); fScopeView->SetPlaying(false);
scopeView->Invalidate(); fScopeView->Invalidate();
BAlert* alert = new BAlert(NULL, B_TRANSLATE("Could not load song"), BAlert* alert = new BAlert(NULL, B_TRANSLATE("Could not load song"),
B_TRANSLATE("OK"), NULL, NULL, B_TRANSLATE("OK"), NULL, NULL,
@@ -393,19 +397,19 @@ MidiPlayerWindow::LoadFile(entry_ref* ref)
void void
MidiPlayerWindow::StartSynth() MidiPlayerWindow::StartSynth()
{ {
synth.Start(); fMidiSynthFile.Start();
synth.SetFileHook(_StopHook, (int32)(addr_t)this); fMidiSynthFile.SetFileHook(_StopHook, (int32)(addr_t)this);
playing = true; fIsPlaying = true;
} }
void void
MidiPlayerWindow::StopSynth() MidiPlayerWindow::StopSynth()
{ {
if (!synth.IsFinished()) if (!fMidiSynthFile.IsFinished())
synth.Fade(); fMidiSynthFile.Fade();
playing = false; fIsPlaying = false;
} }
@@ -422,12 +426,12 @@ MidiPlayerWindow::StopHook()
Lock(); Lock();
// we may be called from the synth's thread // we may be called from the synth's thread
playing = false; fIsPlaying = false;
scopeView->SetPlaying(false); fScopeView->SetPlaying(false);
scopeView->Invalidate(); fScopeView->Invalidate();
playButton->SetEnabled(true); fPlayButton->SetEnabled(true);
playButton->SetLabel(B_TRANSLATE("Play")); fPlayButton->SetLabel(B_TRANSLATE("Play"));
Unlock(); Unlock();
} }
@@ -436,17 +440,17 @@ MidiPlayerWindow::StopHook()
void void
MidiPlayerWindow::OnPlayStop() MidiPlayerWindow::OnPlayStop()
{ {
if (playing) { if (fIsPlaying) {
playButton->SetEnabled(false); fPlayButton->SetEnabled(false);
scopeView->SetPlaying(false); fScopeView->SetPlaying(false);
scopeView->Invalidate(); fScopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
StopSynth(); StopSynth();
} else { } else {
playButton->SetLabel(B_TRANSLATE("Stop")); fPlayButton->SetLabel(B_TRANSLATE("Stop"));
scopeView->SetPlaying(true); fScopeView->SetPlaying(true);
scopeView->Invalidate(); fScopeView->Invalidate();
StartSynth(); StartSynth();
} }
@@ -456,48 +460,48 @@ MidiPlayerWindow::OnPlayStop()
void void
MidiPlayerWindow::OnShowScope() MidiPlayerWindow::OnShowScope()
{ {
scopeEnabled = !scopeEnabled; fScopeEnabled = !fScopeEnabled;
scopeView->SetEnabled(scopeEnabled); fScopeView->SetEnabled(fScopeEnabled);
scopeView->Invalidate(); fScopeView->Invalidate();
SaveSettings(); SaveSettings();
} }
void void
MidiPlayerWindow::OnInputChanged(BMessage* msg) MidiPlayerWindow::OnInputChanged(BMessage* message)
{ {
int32 newId; int32 newId;
if (msg->FindInt32("id", &newId) == B_OK) { if (message->FindInt32("id", &newId) == B_OK) {
BMidiProducer* endpoint = BMidiRoster::FindProducer(inputId); BMidiProducer* endpoint = BMidiRoster::FindProducer(fInputId);
if (endpoint != NULL) { if (endpoint != NULL) {
endpoint->Disconnect(bridge); endpoint->Disconnect(fSynthBridge);
endpoint->Release(); endpoint->Release();
} }
inputId = newId; fInputId = newId;
endpoint = BMidiRoster::FindProducer(inputId); endpoint = BMidiRoster::FindProducer(fInputId);
if (endpoint != NULL) { if (endpoint != NULL) {
if (!instrLoaded) { if (!fInstrumentLoaded) {
scopeView->SetLoading(true); fScopeView->SetLoading(true);
scopeView->Invalidate(); fScopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
bridge->Init(B_BIG_SYNTH); fSynthBridge->Init(B_BIG_SYNTH);
instrLoaded = true; fInstrumentLoaded = true;
scopeView->SetLoading(false); fScopeView->SetLoading(false);
scopeView->Invalidate(); fScopeView->Invalidate();
} }
endpoint->Connect(bridge); endpoint->Connect(fSynthBridge);
endpoint->Release(); endpoint->Release();
scopeView->SetLiveInput(true); fScopeView->SetLiveInput(true);
scopeView->Invalidate(); fScopeView->Invalidate();
} else { } else {
scopeView->SetLiveInput(false); fScopeView->SetLiveInput(false);
scopeView->Invalidate(); fScopeView->Invalidate();
} }
} }
} }
@@ -506,8 +510,8 @@ MidiPlayerWindow::OnInputChanged(BMessage* msg)
void void
MidiPlayerWindow::OnReverb(reverb_mode mode) MidiPlayerWindow::OnReverb(reverb_mode mode)
{ {
reverb = mode; fReverbMode = mode;
be_synth->SetReverb(reverb); be_synth->SetReverb(fReverbMode);
SaveSettings(); SaveSettings();
} }
@@ -515,16 +519,16 @@ MidiPlayerWindow::OnReverb(reverb_mode mode)
void void
MidiPlayerWindow::OnVolume() MidiPlayerWindow::OnVolume()
{ {
volume = volumeSlider->Value(); fVolume = fVolumeSlider->Value();
synth.SetVolume(volume / 100.0f); fMidiSynthFile.SetVolume(fVolume / 100.0f);
SaveSettings(); SaveSettings();
} }
void void
MidiPlayerWindow::OnDrop(BMessage* msg) MidiPlayerWindow::OnDrop(BMessage* message)
{ {
entry_ref ref; entry_ref ref;
if (msg->FindRef("refs", &ref) == B_OK) if (message->FindRef("refs", &ref) == B_OK)
LoadFile(&ref); LoadFile(&ref);
} }
+35 -34
View File
@@ -19,15 +19,17 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef _MIDI_PLAYER_WINDOW_H
#define _MIDI_PLAYER_WINDOW_H
#ifndef MIDI_PLAYER_WINDOW_H
#define MIDI_PLAYER_WINDOW_H
#include <InterfaceKit.h> #include <InterfaceKit.h>
#include <MidiSynthFile.h> #include <MidiSynthFile.h>
#define SETTINGS_FILE "/boot/home/config/settings/MidiPlayerSettings" #define SETTINGS_FILE "/boot/home/config/settings/MidiPlayerSettings"
enum enum
{ {
MSG_PLAY_STOP = 1000, MSG_PLAY_STOP = 1000,
@@ -42,23 +44,21 @@ enum
MSG_VOLUME, MSG_VOLUME,
}; };
class ScopeView; class ScopeView;
class SynthBridge; class SynthBridge;
class MidiPlayerWindow : public BWindow class MidiPlayerWindow : public BWindow {
{
public: public:
MidiPlayerWindow(); MidiPlayerWindow();
virtual ~MidiPlayerWindow(); virtual ~MidiPlayerWindow();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage* msg); virtual void MessageReceived(BMessage* message);
virtual void FrameMoved(BPoint origin); virtual void FrameMoved(BPoint origin);
virtual void MenusBeginning(); virtual void MenusBeginning();
private: private:
typedef BWindow super; typedef BWindow super;
void CreateInputMenu(); void CreateInputMenu();
@@ -77,36 +77,37 @@ private:
void OnPlayStop(); void OnPlayStop();
void OnShowScope(); void OnShowScope();
void OnInputChanged(BMessage* msg); void OnInputChanged(BMessage* message);
void OnReverb(reverb_mode mode); void OnReverb(reverb_mode mode);
void OnVolume(); void OnVolume();
void OnDrop(BMessage* msg); void OnDrop(BMessage* message);
ScopeView* scopeView; ScopeView* fScopeView;
BCheckBox* showScope; BCheckBox* fShowScopeCheckBox;
BMenuField* inputMenu; BMenuField* fInputMenuField;
BPopUpMenu* inputPopUp; BPopUpMenu* fInputPopUpMenu;
BMenuItem* inputOff; BMenuItem* fInputOffMenuItem;
BMenuField* reverbMenu; BMenuField* fReverbMenuField;
BMenuItem* reverbNone; BMenuItem* fReverbNoneMenuItem;
BMenuItem* reverbCloset; BMenuItem* fReverbClosetMenuItem;
BMenuItem* reverbGarage; BMenuItem* fReverbGarageMenuItem;
BMenuItem* reverbIgor; BMenuItem* fReverbIgorMenuItem;
BMenuItem* reverbCavern; BMenuItem* fReverbCavern;
BMenuItem* reverbDungeon; BMenuItem* fReverbDungeon;
BSlider* volumeSlider; BSlider* fVolumeSlider;
BButton* playButton; BButton* fPlayButton;
bool playing; bool fIsPlaying;
bool scopeEnabled; bool fScopeEnabled;
int32 inputId; int32 fInputId;
reverb_mode reverb; reverb_mode fReverbMode;
int32 volume; int32 fVolume;
float windowX; float fWindowX;
float windowY; float fWindowY;
BMidiSynthFile synth; BMidiSynthFile fMidiSynthFile;
SynthBridge* bridge; SynthBridge* fSynthBridge;
bool instrLoaded; bool fInstrumentLoaded;
}; };
#endif // MIDI_PLAYER_WINDOW_H
#endif // _MIDI_PLAYER_WINDOW_H
+77 -124
View File
@@ -20,237 +20,192 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include "ScopeView.h"
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <Synth.h> #include <Synth.h>
#include <Window.h> #include <Window.h>
#include "ScopeView.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Scope View" #define B_TRANSLATION_CONTEXT "Scope View"
//------------------------------------------------------------------------------ // #pragma mark - ScopeView
ScopeView::ScopeView() ScopeView::ScopeView()
: BView(BRect(0, 0, 180, 63), NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, :
B_WILL_DRAW) BView(BRect(0, 0, 180, 63), NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW),
fIsPlaying(false),
fIsEnabled(true),
fHaveFile(false),
fIsLoading(false),
fIsLiveInput(false),
fSampleCount(Bounds().IntegerWidth()),
fLeftSamples(new int16[fSampleCount]),
fRightSamples(new int16[fSampleCount]),
fScopeThreadID(-1)
{ {
SetViewColor(0, 0, 0);
playing = false;
enabled = true;
haveFile = false;
loading = false;
liveInput = false;
sampleCount = (int32) Bounds().Width();
leftSamples = new int16[sampleCount];
rightSamples = new int16[sampleCount];
} }
//------------------------------------------------------------------------------
ScopeView::~ScopeView() ScopeView::~ScopeView()
{ {
delete[] leftSamples; delete[] fLeftSamples;
delete[] rightSamples; delete[] fRightSamples;
} }
//------------------------------------------------------------------------------
void ScopeView::AttachedToWindow() void ScopeView::AttachedToWindow()
{ {
finished = false; SetViewColor(0, 0, 0);
threadId = spawn_thread(_Thread, "ScopeThread", B_NORMAL_PRIORITY, this);
if (threadId >= B_OK) fIsFinished = false;
{ fScopeThreadID = spawn_thread(_Thread, "ScopeThread",
resume_thread(threadId); B_NORMAL_PRIORITY, this);
} if (fScopeThreadID > 0)
resume_thread(fScopeThreadID);
} }
//------------------------------------------------------------------------------
void ScopeView::DetachedFromWindow() void
ScopeView::DetachedFromWindow()
{ {
if (threadId >= B_OK) if (fScopeThreadID > 0) {
{ fIsFinished = true;
finished = true;
status_t exitValue; status_t exitValue;
wait_for_thread(threadId, &exitValue); wait_for_thread(fScopeThreadID, &exitValue);
} }
} }
//------------------------------------------------------------------------------
void ScopeView::Draw(BRect updateRect) void
ScopeView::Draw(BRect updateRect)
{ {
super::Draw(updateRect); super::Draw(updateRect);
if (loading) if (fIsLoading)
{
DrawLoading(); DrawLoading();
} else if (!fHaveFile && !fIsLiveInput)
else if (!haveFile && !liveInput)
{
DrawNoFile(); DrawNoFile();
} else if (!fIsEnabled)
else if (!enabled)
{
DrawDisabled(); DrawDisabled();
} else if (fIsPlaying || fIsLiveInput)
else if (playing || liveInput)
{
DrawPlaying(); DrawPlaying();
}
else else
{
DrawStopped(); DrawStopped();
} }
}
//------------------------------------------------------------------------------
void ScopeView::SetPlaying(bool flag) int32
{ ScopeView::_Thread(void* data)
playing = flag;
}
//------------------------------------------------------------------------------
void ScopeView::SetEnabled(bool flag)
{
enabled = flag;
}
//------------------------------------------------------------------------------
void ScopeView::SetHaveFile(bool flag)
{
haveFile = flag;
}
//------------------------------------------------------------------------------
void ScopeView::SetLoading(bool flag)
{
loading = flag;
}
//------------------------------------------------------------------------------
void ScopeView::SetLiveInput(bool flag)
{
liveInput = flag;
}
//------------------------------------------------------------------------------
int32 ScopeView::_Thread(void* data)
{ {
return ((ScopeView*) data)->Thread(); return ((ScopeView*) data)->Thread();
} }
//------------------------------------------------------------------------------
int32 ScopeView::Thread() int32
ScopeView::Thread()
{ {
// Because Pulse() was too slow, I created a thread that tells the // Because Pulse() was too slow, I created a thread that tells the
// ScopeView to repaint itself. Note that we need to call LockLooper // ScopeView to repaint itself. Note that we need to call LockLooper
// with a timeout, otherwise we'll deadlock in DetachedFromWindow(). // with a timeout, otherwise we'll deadlock in DetachedFromWindow().
while (!finished) while (!fIsFinished) {
{ if (fIsEnabled && (fIsPlaying || fIsLiveInput)) {
if (enabled && (playing || liveInput)) if (LockLooperWithTimeout(50000) == B_OK) {
{
if (LockLooperWithTimeout(50000) == B_OK)
{
Invalidate(); Invalidate();
UnlockLooper(); UnlockLooper();
} }
} }
snooze(50000); snooze(50000);
} }
return 0; return 0;
} }
//------------------------------------------------------------------------------
void ScopeView::DrawLoading() void
ScopeView::DrawLoading()
{ {
DrawText("Loading instruments" B_UTF8_ELLIPSIS); DrawText(B_TRANSLATE("Loading instruments" B_UTF8_ELLIPSIS));
} }
//------------------------------------------------------------------------------
void ScopeView::DrawNoFile() void
ScopeView::DrawNoFile()
{ {
DrawText(B_TRANSLATE("Drop MIDI file here")); DrawText(B_TRANSLATE("Drop MIDI file here"));
} }
//------------------------------------------------------------------------------
void ScopeView::DrawDisabled() void
ScopeView::DrawDisabled()
{ {
SetHighColor(64, 64, 64); SetHighColor(64, 64, 64);
StrokeLine( StrokeLine(BPoint(0, Bounds().Height() / 2),
BPoint(0, Bounds().Height() / 2),
BPoint(Bounds().Width(), Bounds().Height() / 2)); BPoint(Bounds().Width(), Bounds().Height() / 2));
} }
//------------------------------------------------------------------------------
void ScopeView::DrawStopped() void
ScopeView::DrawStopped()
{ {
SetHighColor(0, 130, 0); SetHighColor(0, 130, 0);
StrokeLine( StrokeLine(BPoint(0, Bounds().Height() / 2),
BPoint(0, Bounds().Height() / 2),
BPoint(Bounds().Width(), Bounds().Height() / 2)); BPoint(Bounds().Width(), Bounds().Height() / 2));
} }
//------------------------------------------------------------------------------
void ScopeView::DrawPlaying() void
ScopeView::DrawPlaying()
{ {
int32 width = (int32) Bounds().Width(); int32 width = (int32) Bounds().Width();
int32 height = (int32) Bounds().Height(); int32 height = (int32) Bounds().Height();
// Scope drawing magic based on code by Michael Pfeiffer. // Scope drawing magic based on code by Michael Pfeiffer.
int32 size = be_synth->GetAudio(leftSamples, rightSamples, sampleCount); int32 size = be_synth->GetAudio(fLeftSamples, fRightSamples, fSampleCount);
if (size > 0) if (size > 0) {
{
SetHighColor(255, 0, 130); SetHighColor(255, 0, 130);
SetLowColor(0, 130, 0); SetLowColor(0, 130, 0);
#define N 16
int32 x, y, sx = 0, f = (height << N) / 65535, dy = height / 2 + 1; int32 x;
for (int32 i = 0; i < width; i++) int32 y;
{ int32 sx = 0;
int32 f = (height << 16) / 65535;
int32 dy = height / 2 + 1;
for (int32 i = 0; i < width; i++) {
x = sx / width; x = sx / width;
y = ((leftSamples[x] * f) >> N) + dy; y = ((fLeftSamples[x] * f) >> 16) + dy;
FillRect(BRect(i, y, i, y)); FillRect(BRect(i, y, i, y));
y = ((rightSamples[x] * f) >> N) + dy;
y = ((fRightSamples[x] * f) >> 16) + dy;
FillRect(BRect(i, y, i, y), B_SOLID_LOW); FillRect(BRect(i, y, i, y), B_SOLID_LOW);
sx += size; sx += size;
} }
} }
} }
//------------------------------------------------------------------------------
void ScopeView::DrawText(const char* text) void
ScopeView::DrawText(const char* text)
{ {
font_height height; font_height height;
GetFontHeight(&height); GetFontHeight(&height);
float strWidth = StringWidth(text); float stringWidth = StringWidth(text);
float strHeight = height.ascent + height.descent; float stringHeight = height.ascent + height.descent;
float x = (Bounds().Width() - strWidth)/2; float x = (Bounds().Width() - stringWidth) / 2;
float y = height.ascent + (Bounds().Height() - strHeight)/2; float y = height.ascent + (Bounds().Height() - stringHeight) / 2;
SetHighColor(255, 255, 255); SetHighColor(255, 255, 255);
SetLowColor(ViewColor()); SetLowColor(ViewColor());
@@ -258,5 +213,3 @@ void ScopeView::DrawText(const char* text)
DrawString(text, BPoint(x, y)); DrawString(text, BPoint(x, y));
} }
//------------------------------------------------------------------------------
+58 -22
View File
@@ -19,16 +19,15 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef _SCOPE_VIEW_H
#define _SCOPE_VIEW_H
#ifndef SCOPE_VIEW_H
#define SCOPE_VIEW_H
#include <View.h> #include <View.h>
class ScopeView : public BView
{
public:
class ScopeView : public BView {
public:
ScopeView(); ScopeView();
virtual ~ScopeView(); virtual ~ScopeView();
@@ -36,14 +35,13 @@ public:
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
void SetPlaying(bool flag); void SetPlaying(bool playing);
void SetEnabled(bool flag); void SetEnabled(bool enabled);
void SetHaveFile(bool flag); void SetHaveFile(bool haveFile);
void SetLoading(bool flag); void SetLoading(bool loading);
void SetLiveInput(bool flag); void SetLiveInput(bool liveInput);
private: private:
typedef BView super; typedef BView super;
static int32 _Thread(void* data); static int32 _Thread(void* data);
@@ -57,16 +55,54 @@ private:
void DrawText(const char* text); void DrawText(const char* text);
bool finished; bool fIsFinished;
bool playing; bool fIsPlaying;
bool enabled; bool fIsEnabled;
bool haveFile; bool fHaveFile;
bool loading; bool fIsLoading;
bool liveInput; bool fIsLiveInput;
int32 sampleCount;
int16* leftSamples; int32 fSampleCount;
int16* rightSamples; int16* fLeftSamples;
thread_id threadId; int16* fRightSamples;
thread_id fScopeThreadID;
}; };
#endif // SCOPE_VIEW_H
inline void
ScopeView::SetPlaying(bool playing)
{
fIsPlaying = playing;
}
inline void
ScopeView::SetEnabled(bool enabled)
{
fIsEnabled = enabled;
}
inline void
ScopeView::SetHaveFile(bool haveFile)
{
fHaveFile = haveFile;
}
inline void
ScopeView::SetLoading(bool loading)
{
fIsLoading = loading;
}
inline void
ScopeView::SetLiveInput(bool liveInput)
{
fIsLiveInput = liveInput;
}
#endif // _SCOPE_VIEW_H
+41 -45
View File
@@ -20,97 +20,93 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include "SynthBridge.h" #include "SynthBridge.h"
//------------------------------------------------------------------------------
// #pragma mark - SynthBridge
SynthBridge::SynthBridge() SynthBridge::SynthBridge()
: BMidiLocalConsumer("Internal Synthesizer") :
BMidiLocalConsumer("Internal Synthesizer")
{ {
// do nothing
} }
//------------------------------------------------------------------------------
bool SynthBridge::Init(synth_mode mode) bool
SynthBridge::Init(synth_mode mode)
{ {
if (be_synth->LoadSynthData(mode) == B_OK) if (be_synth->LoadSynthData(mode) == B_OK) {
{ fMidiSynth.EnableInput(true, true);
midiSynth.EnableInput(true, true);
return true; return true;
} }
return false; return false;
} }
//------------------------------------------------------------------------------
BMidiSynth* SynthBridge::MidiSynth() BMidiSynth*
SynthBridge::MidiSynth()
{ {
return &midiSynth; return &fMidiSynth;
} }
//------------------------------------------------------------------------------
void SynthBridge::NoteOff( void
uchar channel, uchar note, uchar velocity, bigtime_t time) SynthBridge::NoteOff(uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiSynth.NoteOff(channel + 1, note, velocity, time / 1000); fMidiSynth.NoteOff(channel + 1, note, velocity, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::NoteOn( void
uchar channel, uchar note, uchar velocity, bigtime_t time) SynthBridge::NoteOn(uchar channel, uchar note, uchar velocity, bigtime_t time)
{ {
midiSynth.NoteOn(channel + 1, note, velocity, time / 1000); fMidiSynth.NoteOn(channel + 1, note, velocity, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::KeyPressure( void
uchar channel, uchar note, uchar pressure, bigtime_t time) SynthBridge::KeyPressure(uchar channel, uchar note, uchar pressure,
bigtime_t time)
{ {
midiSynth.KeyPressure(channel + 1, note, pressure, time / 1000); fMidiSynth.KeyPressure(channel + 1, note, pressure, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::ControlChange( void
uchar channel, uchar controlNumber, uchar controlValue, bigtime_t time) SynthBridge::ControlChange(uchar channel, uchar controlNumber,
uchar controlValue, bigtime_t time)
{ {
midiSynth.ControlChange( fMidiSynth.ControlChange(channel + 1, controlNumber, controlValue,
channel + 1, controlNumber, controlValue, time / 1000); time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::ProgramChange( void
uchar channel, uchar programNumber, bigtime_t time) SynthBridge::ProgramChange(uchar channel, uchar programNumber, bigtime_t time)
{ {
midiSynth.ProgramChange(channel + 1, programNumber, time / 1000); fMidiSynth.ProgramChange(channel + 1, programNumber, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::ChannelPressure( void
uchar channel, uchar pressure, bigtime_t time) SynthBridge::ChannelPressure(uchar channel, uchar pressure, bigtime_t time)
{ {
midiSynth.ChannelPressure(channel + 1, pressure, time / 1000); fMidiSynth.ChannelPressure(channel + 1, pressure, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::PitchBend( void
uchar channel, uchar lsb, uchar msb, bigtime_t time) SynthBridge::PitchBend(uchar channel, uchar lsb, uchar msb, bigtime_t time)
{ {
midiSynth.PitchBend(channel + 1, lsb, msb, time / 1000); fMidiSynth.PitchBend(channel + 1, lsb, msb, time / 1000);
} }
//------------------------------------------------------------------------------
void SynthBridge::AllNotesOff(bool justChannel, bigtime_t time) void
SynthBridge::AllNotesOff(bool justChannel, bigtime_t time)
{ {
midiSynth.AllNotesOff(justChannel, time / 1000); fMidiSynth.AllNotesOff(justChannel, time / 1000);
} }
//------------------------------------------------------------------------------
+24 -28
View File
@@ -19,55 +19,51 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef _SYNTH_BRIDGE_H
#define _SYNTH_BRIDGE_H
#ifndef SYNTH_BRIDGE_H
#define SYNTH_BRIDGE_H
#include <MidiConsumer.h> #include <MidiConsumer.h>
#include <MidiSynth.h> #include <MidiSynth.h>
class SynthBridge : public BMidiLocalConsumer
{
public:
class SynthBridge : public BMidiLocalConsumer {
public:
SynthBridge(); SynthBridge();
bool Init(synth_mode mode); bool Init(synth_mode mode);
BMidiSynth* MidiSynth(); BMidiSynth* MidiSynth();
virtual void NoteOff( virtual void NoteOff(uchar channel, uchar note, uchar velocity,
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); bigtime_t time);
virtual void ProgramChange( virtual void NoteOn(uchar channel, uchar note, uchar velocity,
uchar channel, uchar programNumber, bigtime_t time); bigtime_t time);
virtual void ChannelPressure( virtual void KeyPressure(uchar channel, uchar note, uchar pressure,
uchar channel, uchar pressure, bigtime_t time); bigtime_t time);
virtual void PitchBend( virtual void ControlChange(uchar channel, uchar controlNumber,
uchar channel, uchar lsb, uchar msb, bigtime_t time); uchar controlValue, bigtime_t time);
virtual void AllNotesOff( virtual void ProgramChange(uchar channel, uchar programNumber,
bool justChannel, bigtime_t time); 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: protected:
virtual ~SynthBridge() {} virtual ~SynthBridge() {}
private: private:
BMidiSynth fMidiSynth;
BMidiSynth midiSynth;
}; };
#endif // SYNTH_BRIDGE_H
#endif // _SYNTH_BRIDGE_H