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