[haiku-commits] r41348 - haiku/trunk/src/apps/midiplayer

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 6 May 2011 21:46:56 +0200 (CEST)

Author: axeld
Date: 2011-05-06 21:46:55 +0200 (Fri, 06 May 2011)
New Revision: 41348
Changeset: https://dev.haiku-os.org/changeset/41348

Modified:
   haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp
Log:
* Style cleanup.


Modified: haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp
===================================================================
--- haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp        2011-05-06 
19:39:39 UTC (rev 41347)
+++ haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp        2011-05-06 
19:46:55 UTC (rev 41348)
@@ -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 @@
        InitControls();
 }
 
-//------------------------------------------------------------------------------
 
 MidiPlayerWindow::~MidiPlayerWindow()
 {
@@ -78,20 +78,19 @@
        bridge->Release();
 }
 
-//------------------------------------------------------------------------------
 
-bool MidiPlayerWindow::QuitRequested()
+bool
+MidiPlayerWindow::QuitRequested()
 {
        be_app->PostMessage(B_QUIT_REQUESTED);
        return true;
 }
 
-//------------------------------------------------------------------------------
 
-void MidiPlayerWindow::MessageReceived(BMessage* msg)
+void
+MidiPlayerWindow::MessageReceived(BMessage* msg)
 {
-       switch (msg->what)
-       {
+       switch (msg->what) {
                case MSG_PLAY_STOP:
                        OnPlayStop();
                        break;
@@ -142,9 +141,9 @@
        }
 }
 
-//------------------------------------------------------------------------------
 
-void MidiPlayerWindow::FrameMoved(BPoint origin)
+void
+MidiPlayerWindow::FrameMoved(BPoint origin)
 {
        super::FrameMoved(origin);
        windowX = Frame().left;
@@ -152,14 +151,12 @@
        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 @@
        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 @@
 
        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 @@
        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::InitControls()
+void
+MidiPlayerWindow::InitControls()
 {
        Lock();
 
@@ -318,26 +305,21 @@
        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 || file.Lock() != B_OK)
+               return;
 
-       if (file.InitCheck() != B_OK) { return; }
-       if (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));
        file.ReadAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32));
@@ -347,15 +329,14 @@
        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 || file.Lock() != B_OK)
+               return;
 
-       if (file.InitCheck() != B_OK) { return; }
-       if (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));
        file.WriteAttr("Volume", B_INT32_TYPE, 0, &volume, sizeof(int32));
@@ -366,12 +347,11 @@
        file.Unlock();
 }
 
-//------------------------------------------------------------------------------
 
-void MidiPlayerWindow::LoadFile(entry_ref* ref)
+void
+MidiPlayerWindow::LoadFile(entry_ref* ref)
 {
-       if (playing)
-       {
+       if (playing) {
                scopeView->SetPlaying(false);
                scopeView->Invalidate();
                UpdateIfNeeded();
@@ -381,8 +361,7 @@
 
        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 @@
                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();
+       ((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 @@
        Unlock();
 }
 
-//------------------------------------------------------------------------------
 
-void MidiPlayerWindow::OnPlayStop()
+void
+MidiPlayerWindow::OnPlayStop()
 {
-       if (playing)
-       {
+       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::OnShowScope()
+void
+MidiPlayerWindow::OnShowScope()
 {
        scopeEnabled = !scopeEnabled;
        scopeView->SetEnabled(scopeEnabled);
@@ -488,29 +460,23 @@
        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 @@
                                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);
-       }
 }
-
-//------------------------------------------------------------------------------


Other related posts:

  • » [haiku-commits] r41348 - haiku/trunk/src/apps/midiplayer - axeld