* Style cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41348 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-05-06 19:46:55 +00:00
parent ff3b4246cc
commit 10785555c1

View File

@ -35,13 +35,14 @@
#include "ScopeView.h" #include "ScopeView.h"
#include "SynthBridge.h" #include "SynthBridge.h"
#define _W(a) (a->Frame().Width()) #define _W(a) (a->Frame().Width())
#define _H(a) (a->Frame().Height()) #define _H(a) (a->Frame().Height())
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Main Window" #define B_TRANSLATE_CONTEXT "Main Window"
//------------------------------------------------------------------------------
MidiPlayerWindow::MidiPlayerWindow() MidiPlayerWindow::MidiPlayerWindow()
: :
@ -68,7 +69,6 @@ MidiPlayerWindow::MidiPlayerWindow()
InitControls(); InitControls();
} }
//------------------------------------------------------------------------------
MidiPlayerWindow::~MidiPlayerWindow() MidiPlayerWindow::~MidiPlayerWindow()
{ {
@ -78,20 +78,19 @@ MidiPlayerWindow::~MidiPlayerWindow()
bridge->Release(); bridge->Release();
} }
//------------------------------------------------------------------------------
bool MidiPlayerWindow::QuitRequested() bool
MidiPlayerWindow::QuitRequested()
{ {
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::MessageReceived(BMessage* msg) void
{ MidiPlayerWindow::MessageReceived(BMessage* msg)
switch (msg->what)
{ {
switch (msg->what) {
case MSG_PLAY_STOP: case MSG_PLAY_STOP:
OnPlayStop(); OnPlayStop();
break; break;
@ -142,9 +141,9 @@ void MidiPlayerWindow::MessageReceived(BMessage* msg)
} }
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::FrameMoved(BPoint origin) void
MidiPlayerWindow::FrameMoved(BPoint origin)
{ {
super::FrameMoved(origin); super::FrameMoved(origin);
windowX = Frame().left; windowX = Frame().left;
@ -152,14 +151,12 @@ void MidiPlayerWindow::FrameMoved(BPoint origin)
SaveSettings(); SaveSettings();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::MenusBeginning() void
MidiPlayerWindow::MenusBeginning()
{ {
for (int32 t = inputPopUp->CountItems() - 1; t > 0; --t) for (int32 t = inputPopUp->CountItems() - 1; t > 0; --t)
{
delete inputPopUp->RemoveItem(t); delete inputPopUp->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.
@ -167,27 +164,23 @@ void MidiPlayerWindow::MenusBeginning()
inputOff->SetMarked(inputId == -1); inputOff->SetMarked(inputId == -1);
int32 id = 0; int32 id = 0;
BMidiEndpoint* endp; while (BMidiEndpoint* endpoint = BMidiRoster::NextEndpoint(&id)) {
while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL) if (endpoint->IsProducer()) {
{ BMessage* msg = new BMessage(MSG_INPUT_CHANGED);
if (endp->IsProducer())
{
BMessage* msg = new BMessage;
msg->what = MSG_INPUT_CHANGED;
msg->AddInt32("id", id); msg->AddInt32("id", id);
BMenuItem* item = new BMenuItem(endp->Name(), msg); BMenuItem* item = new BMenuItem(endpoint->Name(), msg);
inputPopUp->AddItem(item); inputPopUp->AddItem(item);
item->SetMarked(inputId == id); item->SetMarked(inputId == id);
} }
endp->Release(); endpoint->Release();
} }
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::CreateInputMenu() void
MidiPlayerWindow::CreateInputMenu()
{ {
inputPopUp = new BPopUpMenu("inputPopUp"); inputPopUp = new BPopUpMenu("inputPopUp");
@ -199,30 +192,24 @@ void MidiPlayerWindow::CreateInputMenu()
inputPopUp->AddItem(inputOff); inputPopUp->AddItem(inputOff);
inputMenu = new BMenuField(B_TRANSLATE("Live input:"), inputPopUp, NULL); inputMenu = new BMenuField(B_TRANSLATE("Live input:"), inputPopUp);
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::CreateReverbMenu() void
MidiPlayerWindow::CreateReverbMenu()
{ {
BPopUpMenu* reverbPopUp = new BPopUpMenu("reverbPopUp"); BPopUpMenu* reverbPopUp = new BPopUpMenu("reverbPopUp");
reverbNone = new BMenuItem( reverbNone = new BMenuItem(
B_TRANSLATE("None"), new BMessage(MSG_REVERB_NONE)); B_TRANSLATE("None"), new BMessage(MSG_REVERB_NONE));
reverbCloset = new BMenuItem( reverbCloset = new BMenuItem(
B_TRANSLATE("Closet"), new BMessage(MSG_REVERB_CLOSET)); B_TRANSLATE("Closet"), new BMessage(MSG_REVERB_CLOSET));
reverbGarage = new BMenuItem( reverbGarage = new BMenuItem(
B_TRANSLATE("Garage"), new BMessage(MSG_REVERB_GARAGE)); B_TRANSLATE("Garage"), new BMessage(MSG_REVERB_GARAGE));
reverbIgor = new BMenuItem( reverbIgor = new BMenuItem(
B_TRANSLATE("Igor's lab"), new BMessage(MSG_REVERB_IGOR)); B_TRANSLATE("Igor's lab"), new BMessage(MSG_REVERB_IGOR));
reverbCavern = new BMenuItem( reverbCavern = new BMenuItem(
B_TRANSLATE("Cavern"), new BMessage(MSG_REVERB_CAVERN)); B_TRANSLATE("Cavern"), new BMessage(MSG_REVERB_CAVERN));
reverbDungeon = new BMenuItem( reverbDungeon = new BMenuItem(
B_TRANSLATE("Dungeon"), new BMessage(MSG_REVERB_DUNGEON)); B_TRANSLATE("Dungeon"), new BMessage(MSG_REVERB_DUNGEON));
@ -233,12 +220,12 @@ void MidiPlayerWindow::CreateReverbMenu()
reverbPopUp->AddItem(reverbCavern); reverbPopUp->AddItem(reverbCavern);
reverbPopUp->AddItem(reverbDungeon); reverbPopUp->AddItem(reverbDungeon);
reverbMenu = new BMenuField(B_TRANSLATE("Reverb:"), reverbPopUp, NULL); reverbMenu = new BMenuField(B_TRANSLATE("Reverb:"), reverbPopUp);
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::CreateViews() void
MidiPlayerWindow::CreateViews()
{ {
// Set up needed views // Set up needed views
scopeView = new ScopeView; scopeView = new ScopeView;
@ -296,9 +283,9 @@ void MidiPlayerWindow::CreateViews()
); );
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::InitControls() void
MidiPlayerWindow::InitControls()
{ {
Lock(); Lock();
@ -318,25 +305,20 @@ void MidiPlayerWindow::InitControls()
volumeSlider->SetValue(volume); volumeSlider->SetValue(volume);
if (windowX != -1 && windowY != -1) if (windowX != -1 && windowY != -1)
{
MoveTo(windowX, windowY); MoveTo(windowX, windowY);
}
else else
{
CenterOnScreen(); CenterOnScreen();
}
Unlock(); Unlock();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::LoadSettings() void
MidiPlayerWindow::LoadSettings()
{ {
BFile file(SETTINGS_FILE, B_READ_ONLY); BFile file(SETTINGS_FILE, B_READ_ONLY);
if (file.InitCheck() != B_OK || file.Lock() != B_OK)
if (file.InitCheck() != B_OK) { return; } return;
if (file.Lock() != B_OK) { return; }
file.ReadAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool)); file.ReadAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool));
file.ReadAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32)); file.ReadAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32));
@ -347,14 +329,13 @@ void MidiPlayerWindow::LoadSettings()
file.Unlock(); file.Unlock();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::SaveSettings() void
MidiPlayerWindow::SaveSettings()
{ {
BFile file(SETTINGS_FILE, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); BFile file(SETTINGS_FILE, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() != B_OK || file.Lock() != B_OK)
if (file.InitCheck() != B_OK) { return; } return;
if (file.Lock() != B_OK) { return; }
file.WriteAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool)); file.WriteAttr("Scope", B_BOOL_TYPE, 0, &scopeEnabled, sizeof(bool));
file.WriteAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32)); file.WriteAttr("Reverb", B_INT32_TYPE, 0, &reverb, sizeof(int32));
@ -366,12 +347,11 @@ void MidiPlayerWindow::SaveSettings()
file.Unlock(); file.Unlock();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::LoadFile(entry_ref* ref) void
{ MidiPlayerWindow::LoadFile(entry_ref* ref)
if (playing)
{ {
if (playing) {
scopeView->SetPlaying(false); scopeView->SetPlaying(false);
scopeView->Invalidate(); scopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
@ -381,8 +361,7 @@ void MidiPlayerWindow::LoadFile(entry_ref* ref)
synth.UnloadFile(); synth.UnloadFile();
if (synth.LoadFile(ref) == B_OK) if (synth.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.
@ -395,55 +374,51 @@ void MidiPlayerWindow::LoadFile(entry_ref* ref)
scopeView->Invalidate(); scopeView->Invalidate();
StartSynth(); StartSynth();
} } else {
else
{
playButton->SetEnabled(false); playButton->SetEnabled(false);
playButton->SetLabel(B_TRANSLATE("Play")); playButton->SetLabel(B_TRANSLATE("Play"));
scopeView->SetHaveFile(false); scopeView->SetHaveFile(false);
scopeView->SetPlaying(false); scopeView->SetPlaying(false);
scopeView->Invalidate(); scopeView->Invalidate();
(new BAlert(NULL, (new BAlert(NULL, B_TRANSLATE("Could not load song"),
B_TRANSLATE("Could not load song"),
B_TRANSLATE("OK"), NULL, NULL, B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
} }
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::StartSynth() void
MidiPlayerWindow::StartSynth()
{ {
synth.Start(); synth.Start();
synth.SetFileHook(_StopHook, (int32) this); synth.SetFileHook(_StopHook, (int32) this);
playing = true; playing = true;
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::StopSynth() void
MidiPlayerWindow::StopSynth()
{ {
if (!synth.IsFinished()) if (!synth.IsFinished())
{
synth.Fade(); synth.Fade();
}
playing = false; playing = false;
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::_StopHook(int32 arg) void
MidiPlayerWindow::_StopHook(int32 arg)
{ {
((MidiPlayerWindow*)arg)->StopHook(); ((MidiPlayerWindow*)arg)->StopHook();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::StopHook() void
MidiPlayerWindow::StopHook()
{ {
Lock(); // we may be called from the synth's thread Lock();
// we may be called from the synth's thread
playing = false; playing = false;
@ -455,21 +430,18 @@ void MidiPlayerWindow::StopHook()
Unlock(); Unlock();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnPlayStop() void
{ MidiPlayerWindow::OnPlayStop()
if (playing)
{ {
if (playing) {
playButton->SetEnabled(false); playButton->SetEnabled(false);
scopeView->SetPlaying(false); scopeView->SetPlaying(false);
scopeView->Invalidate(); scopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
StopSynth(); StopSynth();
} } else {
else
{
playButton->SetLabel(B_TRANSLATE("Stop")); playButton->SetLabel(B_TRANSLATE("Stop"));
scopeView->SetPlaying(true); scopeView->SetPlaying(true);
scopeView->Invalidate(); scopeView->Invalidate();
@ -478,9 +450,9 @@ void MidiPlayerWindow::OnPlayStop()
} }
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnShowScope() void
MidiPlayerWindow::OnShowScope()
{ {
scopeEnabled = !scopeEnabled; scopeEnabled = !scopeEnabled;
scopeView->SetEnabled(scopeEnabled); scopeView->SetEnabled(scopeEnabled);
@ -488,29 +460,23 @@ void MidiPlayerWindow::OnShowScope()
SaveSettings(); SaveSettings();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnInputChanged(BMessage* msg) void
MidiPlayerWindow::OnInputChanged(BMessage* msg)
{ {
int32 newId; int32 newId;
if (msg->FindInt32("id", &newId) == B_OK) if (msg->FindInt32("id", &newId) == B_OK) {
{ BMidiProducer* endpoint = BMidiRoster::FindProducer(inputId);
BMidiProducer* endp; if (endpoint != NULL) {
endpoint->Disconnect(bridge);
endp = BMidiRoster::FindProducer(inputId); endpoint->Release();
if (endp != NULL)
{
endp->Disconnect(bridge);
endp->Release();
} }
inputId = newId; inputId = newId;
endp = BMidiRoster::FindProducer(inputId); endpoint = BMidiRoster::FindProducer(inputId);
if (endp != NULL) if (endpoint != NULL) {
{ if (!instrLoaded) {
if (!instrLoaded)
{
scopeView->SetLoading(true); scopeView->SetLoading(true);
scopeView->Invalidate(); scopeView->Invalidate();
UpdateIfNeeded(); UpdateIfNeeded();
@ -522,47 +488,41 @@ void MidiPlayerWindow::OnInputChanged(BMessage* msg)
scopeView->Invalidate(); scopeView->Invalidate();
} }
endp->Connect(bridge); endpoint->Connect(bridge);
endp->Release(); endpoint->Release();
scopeView->SetLiveInput(true); scopeView->SetLiveInput(true);
scopeView->Invalidate(); scopeView->Invalidate();
} } else {
else
{
scopeView->SetLiveInput(false); scopeView->SetLiveInput(false);
scopeView->Invalidate(); scopeView->Invalidate();
} }
} }
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnReverb(reverb_mode mode) void
MidiPlayerWindow::OnReverb(reverb_mode mode)
{ {
reverb = mode; reverb = mode;
be_synth->SetReverb(reverb); be_synth->SetReverb(reverb);
SaveSettings(); SaveSettings();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnVolume() void
MidiPlayerWindow::OnVolume()
{ {
volume = volumeSlider->Value(); volume = volumeSlider->Value();
synth.SetVolume(volume / 100.0f); synth.SetVolume(volume / 100.0f);
SaveSettings(); SaveSettings();
} }
//------------------------------------------------------------------------------
void MidiPlayerWindow::OnDrop(BMessage* msg) void
MidiPlayerWindow::OnDrop(BMessage* msg)
{ {
entry_ref ref; entry_ref ref;
if (msg->FindRef("refs", &ref) == B_OK) if (msg->FindRef("refs", &ref) == B_OK)
{
LoadFile(&ref); LoadFile(&ref);
} }
}
//------------------------------------------------------------------------------