From c75d8265c98e85615b0aa96280c5e03eb6c3db98 Mon Sep 17 00:00:00 2001 From: mahlzeit Date: Mon, 28 Jun 2004 16:35:11 +0000 Subject: [PATCH] It was already after dark when he finally closed the lid of his laptop. The source code was written, compiled, and checked in. The bugs fixed, trampled, squashed. And the MidiPlayer had working Live Input. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8222 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/midiplayer/MidiPlayerWindow.cpp | 55 ++++++++---------- src/apps/midiplayer/ScopeView.cpp | 72 ++++++++++++++++-------- src/apps/midiplayer/ScopeView.h | 7 ++- 3 files changed, 79 insertions(+), 55 deletions(-) diff --git a/src/apps/midiplayer/MidiPlayerWindow.cpp b/src/apps/midiplayer/MidiPlayerWindow.cpp index 93048f7eab..e581dae432 100644 --- a/src/apps/midiplayer/MidiPlayerWindow.cpp +++ b/src/apps/midiplayer/MidiPlayerWindow.cpp @@ -150,13 +150,10 @@ void MidiPlayerWindow::MenusBeginning() delete inputPopUp->RemoveItem(t); } - bool seenInput = false; + // Note: if the selected endpoint no longer exists, then no endpoint is + // marked. However, we won't disconnect it until you choose another one. - if (inputId == -1) - { - inputOff->SetMarked(true); - seenInput = true; - } + inputOff->SetMarked(inputId == -1); int32 id = 0; BMidiEndpoint* endp; @@ -170,21 +167,11 @@ void MidiPlayerWindow::MenusBeginning() BMenuItem* item = new BMenuItem(endp->Name(), msg); inputPopUp->AddItem(item); - - if (inputId == id) - { - item->SetMarked(true); - seenInput = true; - } + item->SetMarked(inputId == id); } endp->Release(); } - - if (!seenInput) // endpoint no longer exists - { - inputOff->SetMarked(true); - } } //------------------------------------------------------------------------------ @@ -556,19 +543,6 @@ 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); @@ -583,8 +557,29 @@ void MidiPlayerWindow::OnInputChanged(BMessage* msg) endp = BMidiRoster::FindProducer(inputId); if (endp != NULL) { + if (!instrLoaded) + { + scopeView->SetLoading(true); + scopeView->Invalidate(); + UpdateIfNeeded(); + + bridge->Init(B_BIG_SYNTH); + instrLoaded = true; + + scopeView->SetLoading(false); + scopeView->Invalidate(); + } + endp->Connect(bridge); endp->Release(); + + scopeView->SetLiveInput(true); + scopeView->Invalidate(); + } + else + { + scopeView->SetLiveInput(false); + scopeView->Invalidate(); } } } diff --git a/src/apps/midiplayer/ScopeView.cpp b/src/apps/midiplayer/ScopeView.cpp index ccbc3cac01..95c49c67fc 100644 --- a/src/apps/midiplayer/ScopeView.cpp +++ b/src/apps/midiplayer/ScopeView.cpp @@ -37,7 +37,8 @@ ScopeView::ScopeView() enabled = true; haveFile = false; loading = false; - + liveInput = false; + sampleCount = (int32) Bounds().Width(); leftSamples = new int16[sampleCount]; rightSamples = new int16[sampleCount]; @@ -81,7 +82,11 @@ void ScopeView::Draw(BRect updateRect) { super::Draw(updateRect); - if (!haveFile) + if (loading) + { + DrawLoading(); + } + else if (!haveFile && !liveInput) { DrawNoFile(); } @@ -89,14 +94,14 @@ void ScopeView::Draw(BRect updateRect) { DrawDisabled(); } - else if (!playing) - { - DrawStopped(); - } - else + else if (playing || liveInput) { DrawPlaying(); } + else + { + DrawStopped(); + } } //------------------------------------------------------------------------------ @@ -129,6 +134,13 @@ void ScopeView::SetLoading(bool flag) //------------------------------------------------------------------------------ +void ScopeView::SetLiveInput(bool flag) +{ + liveInput = flag; +} + +//------------------------------------------------------------------------------ + int32 ScopeView::_Thread(void* data) { return ((ScopeView*) data)->Thread(); @@ -144,7 +156,7 @@ int32 ScopeView::Thread() while (!finished) { - if (enabled && playing && haveFile) + if (enabled && (playing || liveInput)) { if (LockLooperWithTimeout(50000) == B_OK) { @@ -159,24 +171,16 @@ int32 ScopeView::Thread() //------------------------------------------------------------------------------ +void ScopeView::DrawLoading() +{ + DrawText("Loading instruments..."); +} + +//------------------------------------------------------------------------------ + void ScopeView::DrawNoFile() { - const char* string = "Drop MIDI file here"; - - font_height height; - GetFontHeight(&height); - - float strWidth = StringWidth(string); - float strHeight = height.ascent + height.descent; - - float x = (Bounds().Width() - strWidth)/2; - float y = height.ascent + (Bounds().Height() - strHeight)/2; - - SetHighColor(255, 255, 255); - SetLowColor(ViewColor()); - SetDrawingMode(B_OP_OVER); - - DrawString(string, BPoint(x, y)); + DrawText("Drop MIDI file here"); } //------------------------------------------------------------------------------ @@ -230,3 +234,23 @@ void ScopeView::DrawPlaying() } //------------------------------------------------------------------------------ + +void ScopeView::DrawText(const char* text) +{ + font_height height; + GetFontHeight(&height); + + float strWidth = StringWidth(text); + float strHeight = height.ascent + height.descent; + + float x = (Bounds().Width() - strWidth)/2; + float y = height.ascent + (Bounds().Height() - strHeight)/2; + + SetHighColor(255, 255, 255); + SetLowColor(ViewColor()); + SetDrawingMode(B_OP_OVER); + + DrawString(text, BPoint(x, y)); +} + +//------------------------------------------------------------------------------ diff --git a/src/apps/midiplayer/ScopeView.h b/src/apps/midiplayer/ScopeView.h index ad93562f95..310314b41d 100644 --- a/src/apps/midiplayer/ScopeView.h +++ b/src/apps/midiplayer/ScopeView.h @@ -40,6 +40,7 @@ public: void SetEnabled(bool flag); void SetHaveFile(bool flag); void SetLoading(bool flag); + void SetLiveInput(bool flag); private: @@ -47,17 +48,21 @@ private: static int32 _Thread(void* data); int32 Thread(); - + + void DrawLoading(); void DrawNoFile(); void DrawDisabled(); void DrawStopped(); void DrawPlaying(); + void DrawText(const char* text); + bool finished; bool playing; bool enabled; bool haveFile; bool loading; + bool liveInput; int32 sampleCount; int16* leftSamples; int16* rightSamples;