From 5592b1d7e0ca637e525a93cb2184b98f5ceb773e Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 6 Nov 2014 16:19:11 +0100 Subject: [PATCH] PatchBay: complain when there are no MIDI devices The empty window that would show when no MIDI devices are found would confuse Haiku users. This was not a problem on the BeBox or older PCs where a sound card with MPU401 port was standard, so there would always be something to show. Fixes #9977. --- src/apps/patchbay/Jamfile | 7 ++++++- src/apps/patchbay/PatchView.cpp | 27 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/apps/patchbay/Jamfile b/src/apps/patchbay/Jamfile index a3dd8b3e31..10528b90c7 100644 --- a/src/apps/patchbay/Jamfile +++ b/src/apps/patchbay/Jamfile @@ -11,8 +11,13 @@ SimpleTest PatchBay EndpointInfo.cpp MidiEventMeter.cpp : - midi midi2 be libicon.a [ TargetLibstdc++ ] + midi midi2 be libicon.a localestub [ TargetLibstdc++ ] : PatchBay.rdef ; +DoCatalogs PatchBay : + x-vnd.Haiku.PatchBay + : + PatchView.cpp +; diff --git a/src/apps/patchbay/PatchView.cpp b/src/apps/patchbay/PatchView.cpp index c43d6c8b93..f3966b406a 100644 --- a/src/apps/patchbay/PatchView.cpp +++ b/src/apps/patchbay/PatchView.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,9 @@ #include "UnknownDeviceIcons.h" +#define B_TRANSLATION_CONTEXT "Patch Bay" + + PatchView::PatchView(BRect rect) : BView(rect, "PatchView", B_FOLLOW_ALL, B_WILL_DRAW), @@ -149,14 +153,31 @@ PatchView::Draw(BRect /* updateRect */) const BBitmap* bitmap = (i->Icon()) ? i->Icon() : fUnknownDeviceIcon; DrawBitmapAsync(bitmap, RowIconFrameAt(index++).LeftTop()); } - + // draw consumer icons - index = 0; + int32 index2 = 0; for (list::const_iterator i = fConsumers.begin(); i != fConsumers.end(); i++) { const BBitmap* bitmap = (i->Icon()) ? i->Icon() : fUnknownDeviceIcon; - DrawBitmapAsync(bitmap, ColumnIconFrameAt(index++).LeftTop()); + DrawBitmapAsync(bitmap, ColumnIconFrameAt(index2++).LeftTop()); } + + if (index == 0 && index2 == 0) { + const char* message = B_TRANSLATE("No MIDI devices found!"); + float width = StringWidth(message); + BRect rect = Bounds(); + + rect.top = rect.top + rect.bottom / 2; + rect.left = rect.left + rect.right / 2; + rect.left -= width / 2; + + DrawString(message, rect.LeftTop()); + + // Since the message is centered, we need to redraw the whole view in + // this case. + SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE); + } else + SetFlags(Flags() & ~B_FULL_UPDATE_ON_RESIZE); }