From 42b7984a6e679841ed4571cf243364142d9607ed Mon Sep 17 00:00:00 2001 From: Pete Goodeve Date: Tue, 2 Apr 2013 17:07:36 -0700 Subject: [PATCH] PatchBay revisions for Haiku --- src/apps/Jamfile | 1 + src/apps/patchbay/CountEventConsumer.h | 46 ++ .../midi => apps}/patchbay/EndpointInfo.cpp | 110 ++-- .../midi => apps}/patchbay/EndpointInfo.h | 36 +- .../kits/midi => apps}/patchbay/Jamfile | 5 +- .../midi => apps}/patchbay/MidiEventMeter.cpp | 92 ++-- src/apps/patchbay/MidiEventMeter.h | 42 ++ src/apps/patchbay/PatchApp.cpp | 46 ++ src/apps/patchbay/PatchApp.h | 27 + src/apps/patchbay/PatchBay.rdef | 75 +++ .../kits/midi => apps}/patchbay/PatchRow.cpp | 158 +++--- .../kits/midi => apps}/patchbay/PatchRow.h | 16 +- src/apps/patchbay/PatchView.cpp | 484 ++++++++++++++++++ .../kits/midi => apps}/patchbay/PatchView.h | 44 +- src/apps/patchbay/PatchWin.cpp | 36 ++ src/apps/patchbay/PatchWin.h | 30 ++ src/apps/patchbay/UnknownDeviceIcons.h | 105 ++++ src/tests/kits/midi/Jamfile | 2 +- .../kits/midi/patchbay/CountEventConsumer.h | 30 -- src/tests/kits/midi/patchbay/MidiEventMeter.h | 36 -- src/tests/kits/midi/patchbay/PatchApp.cpp | 44 -- src/tests/kits/midi/patchbay/PatchApp.h | 26 - src/tests/kits/midi/patchbay/PatchBay.rsrc | Bin 2861 -> 0 bytes src/tests/kits/midi/patchbay/PatchView.cpp | 462 ----------------- src/tests/kits/midi/patchbay/PatchWin.cpp | 26 - src/tests/kits/midi/patchbay/PatchWin.h | 24 - src/tests/kits/midi/patchbay/TToolTip.cpp | 357 ------------- src/tests/kits/midi/patchbay/TToolTip.h | 86 ---- .../kits/midi/patchbay/UnknownDeviceIcons.h | 106 ---- 29 files changed, 1172 insertions(+), 1380 deletions(-) create mode 100644 src/apps/patchbay/CountEventConsumer.h rename src/{tests/kits/midi => apps}/patchbay/EndpointInfo.cpp (61%) rename src/{tests/kits/midi => apps}/patchbay/EndpointInfo.h (52%) rename src/{tests/kits/midi => apps}/patchbay/Jamfile (77%) rename src/{tests/kits/midi => apps}/patchbay/MidiEventMeter.cpp (58%) create mode 100644 src/apps/patchbay/MidiEventMeter.h create mode 100644 src/apps/patchbay/PatchApp.cpp create mode 100644 src/apps/patchbay/PatchApp.h create mode 100644 src/apps/patchbay/PatchBay.rdef rename src/{tests/kits/midi => apps}/patchbay/PatchRow.cpp (54%) rename src/{tests/kits/midi => apps}/patchbay/PatchRow.h (65%) create mode 100644 src/apps/patchbay/PatchView.cpp rename src/{tests/kits/midi => apps}/patchbay/PatchView.h (58%) create mode 100644 src/apps/patchbay/PatchWin.cpp create mode 100644 src/apps/patchbay/PatchWin.h create mode 100644 src/apps/patchbay/UnknownDeviceIcons.h delete mode 100644 src/tests/kits/midi/patchbay/CountEventConsumer.h delete mode 100644 src/tests/kits/midi/patchbay/MidiEventMeter.h delete mode 100644 src/tests/kits/midi/patchbay/PatchApp.cpp delete mode 100644 src/tests/kits/midi/patchbay/PatchApp.h delete mode 100644 src/tests/kits/midi/patchbay/PatchBay.rsrc delete mode 100644 src/tests/kits/midi/patchbay/PatchView.cpp delete mode 100644 src/tests/kits/midi/patchbay/PatchWin.cpp delete mode 100644 src/tests/kits/midi/patchbay/PatchWin.h delete mode 100644 src/tests/kits/midi/patchbay/TToolTip.cpp delete mode 100644 src/tests/kits/midi/patchbay/TToolTip.h delete mode 100644 src/tests/kits/midi/patchbay/UnknownDeviceIcons.h diff --git a/src/apps/Jamfile b/src/apps/Jamfile index 4cc22a1bd2..d2c4b1a85e 100644 --- a/src/apps/Jamfile +++ b/src/apps/Jamfile @@ -43,6 +43,7 @@ HaikuSubInclude overlayimage ; HaikuSubInclude packageinstaller ; HaikuSubInclude packagemanager ; HaikuSubInclude pairs ; +HaikuSubInclude patchbay ; HaikuSubInclude people ; HaikuSubInclude poorman ; HaikuSubInclude powerstatus ; diff --git a/src/apps/patchbay/CountEventConsumer.h b/src/apps/patchbay/CountEventConsumer.h new file mode 100644 index 0000000000..d6fe12f100 --- /dev/null +++ b/src/apps/patchbay/CountEventConsumer.h @@ -0,0 +1,46 @@ +/* CountEventConsumer.h + * -------------------- + * A simple MIDI consumer that counts incoming MIDI events. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#ifndef _CountEventConsumer_h +#define _CountEventConsumer_h + +#include +#include + +class CountEventConsumer : public BMidiLocalConsumer +{ +public: + CountEventConsumer(const char* name) + : + BMidiLocalConsumer(name), + fEventCount(0) + {} + void Reset() + { + fEventCount = 0; + } + int32 CountEvents() + { + return fEventCount; + } + + void Data(uchar*, size_t, bool, bigtime_t) + { + atomic_add(&fEventCount, 1); + } + +private: + int32 fEventCount; +}; + +#endif /* _CountEventConsumer_h */ diff --git a/src/tests/kits/midi/patchbay/EndpointInfo.cpp b/src/apps/patchbay/EndpointInfo.cpp similarity index 61% rename from src/tests/kits/midi/patchbay/EndpointInfo.cpp rename to src/apps/patchbay/EndpointInfo.cpp index a4caf5af51..4ee9911d2a 100644 --- a/src/tests/kits/midi/patchbay/EndpointInfo.cpp +++ b/src/apps/patchbay/EndpointInfo.cpp @@ -1,10 +1,15 @@ -// EndpointInfo.cpp -// ---------------- -// Implements the EndpointInfo object. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - +/* EndpointInfo.cpp + * ---------------- + * Implements the EndpointInfo object. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ #include "EndpointInfo.h" #include @@ -16,7 +21,7 @@ const char* LARGE_ICON_NAME = "be:large_icon"; const char* MINI_ICON_NAME = "be:mini_icon"; -const char* VECTOR_ICON_NAME = "icon"; +const char* VECTOR_ICON_NAME = "icon"; const uint32 LARGE_ICON_TYPE = 'ICON'; const uint32 MINI_ICON_TYPE = 'MICN'; const uint32 VECTOR_ICON_TYPE = 'VICN'; @@ -27,12 +32,18 @@ extern const color_space ICON_COLOR_SPACE = B_CMAP8; static BBitmap* CreateIcon(const BMessage* msg, icon_size which); + EndpointInfo::EndpointInfo() - : m_id(-1), m_icon(NULL) + : + fId(-1), + fIcon(NULL) {} + EndpointInfo::EndpointInfo(int32 id) - : m_id(id), m_icon(NULL) + : + fId(id), + fIcon(NULL) { BMidiRoster* roster = BMidiRoster::MidiRoster(); if (roster) { @@ -41,68 +52,60 @@ EndpointInfo::EndpointInfo(int32 id) printf("endpoint %ld = %p\n", id, endpoint); BMessage msg; if (endpoint->GetProperties(&msg) == B_OK) { - m_icon = CreateIcon(&msg, DISPLAY_ICON_SIZE); + fIcon = CreateIcon(&msg, DISPLAY_ICON_SIZE); } endpoint->Release(); } } } + EndpointInfo::EndpointInfo(const EndpointInfo& info) - : m_id(info.m_id) + : + fId(info.fId) { - m_icon = (info.m_icon) ? new BBitmap(info.m_icon) : NULL; + fIcon = (info.fIcon) ? new BBitmap(info.fIcon) : NULL; } -EndpointInfo& EndpointInfo::operator=(const EndpointInfo& info) + +EndpointInfo& +EndpointInfo::operator=(const EndpointInfo& info) { if (&info != this) { - m_id = info.m_id; - delete m_icon; - m_icon = (info.m_icon) ? new BBitmap(info.m_icon) : NULL; + fId = info.fId; + delete fIcon; + fIcon = (info.fIcon) ? new BBitmap(info.fIcon) : NULL; } return *this; } + EndpointInfo::~EndpointInfo() { - delete m_icon; + delete fIcon; } -void EndpointInfo::UpdateProperties(const BMessage* props) + +void +EndpointInfo::UpdateProperties(const BMessage* props) { - delete m_icon; - m_icon = CreateIcon(props, DISPLAY_ICON_SIZE); + delete fIcon; + fIcon = CreateIcon(props, DISPLAY_ICON_SIZE); } -static BBitmap* CreateIcon(const BMessage* msg, icon_size which) + +static BBitmap* +CreateIcon(const BMessage* msg, icon_size which) { - float iconSize; - uint32 iconType; - const char* iconName; - - if (which == B_LARGE_ICON) { - iconSize = LARGE_ICON_SIZE; - iconType = LARGE_ICON_TYPE; - iconName = LARGE_ICON_NAME; - } else if (which == B_MINI_ICON) { - iconSize = MINI_ICON_SIZE; - iconType = MINI_ICON_TYPE; - iconName = MINI_ICON_NAME; - } else { - return NULL; - } - + const void* data; ssize_t size; BBitmap* bitmap = NULL; -#ifdef __HAIKU__ - iconSize = LARGE_ICON_SIZE; - + // See if a Haiku Vector Icon available if (msg->FindData(VECTOR_ICON_NAME, VECTOR_ICON_TYPE, &data, &size) == B_OK) { - BRect r(0, 0, iconSize-1, iconSize-1); + BRect r(0, 0, LARGE_ICON_SIZE - 1, LARGE_ICON_SIZE - 1); bitmap = new BBitmap(r, B_RGBA32); if (BIconUtils::GetVectorIcon((const uint8*)data, size, bitmap) == B_OK) { @@ -111,12 +114,29 @@ static BBitmap* CreateIcon(const BMessage* msg, icon_size which) } else delete bitmap; } -#endif + // If not, look for BeOS style icon + float bmapSize; + uint32 iconType; + const char* iconName; + + if (which == B_LARGE_ICON) { + bmapSize = LARGE_ICON_SIZE - 1; + iconType = LARGE_ICON_TYPE; + iconName = LARGE_ICON_NAME; + } else if (which == B_MINI_ICON) { + bmapSize = MINI_ICON_SIZE - 1; + iconType = MINI_ICON_TYPE; + iconName = MINI_ICON_NAME; + } else { + return NULL; + } + if (msg->FindData(iconName, iconType, &data, &size) == B_OK) { - BRect r(0, 0, iconSize-1, iconSize-1); - bitmap = new BBitmap(r, ICON_COLOR_SPACE); + ; + bitmap = new BBitmap(BRect(0, 0, bmapSize, bmapSize), + ICON_COLOR_SPACE); ASSERT((bitmap->BitsLength() == size)); memcpy(bitmap->Bits(), data, size); } diff --git a/src/tests/kits/midi/patchbay/EndpointInfo.h b/src/apps/patchbay/EndpointInfo.h similarity index 52% rename from src/tests/kits/midi/patchbay/EndpointInfo.h rename to src/apps/patchbay/EndpointInfo.h index b75c9a8035..92a65dc6f5 100644 --- a/src/tests/kits/midi/patchbay/EndpointInfo.h +++ b/src/apps/patchbay/EndpointInfo.h @@ -1,11 +1,17 @@ -// EndpointInfo.h -// -------------- -// A simple structure that describes a MIDI object. -// Currently, it only contains icon data associated with the object. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - +/* EndpointInfo.h + * -------------- + * A simple structure that describes a MIDI object. + * Currently, it only contains icon data associated with the object. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + #ifndef _EndpointInfo_h #define _EndpointInfo_h @@ -28,13 +34,19 @@ public: EndpointInfo& operator=(const EndpointInfo& info); ~EndpointInfo(); - int32 ID() const { return m_id; } - const BBitmap* Icon() const { return m_icon; } + int32 ID() const + { + return fId; + } + const BBitmap* Icon() const + { + return fIcon; + } void UpdateProperties(const BMessage* props); private: - int32 m_id; - BBitmap* m_icon; + int32 fId; + BBitmap* fIcon; }; #endif /* _EndpointInfo_h */ diff --git a/src/tests/kits/midi/patchbay/Jamfile b/src/apps/patchbay/Jamfile similarity index 77% rename from src/tests/kits/midi/patchbay/Jamfile rename to src/apps/patchbay/Jamfile index 7cea736e59..193ad8563c 100644 --- a/src/tests/kits/midi/patchbay/Jamfile +++ b/src/apps/patchbay/Jamfile @@ -1,4 +1,4 @@ -SubDir HAIKU_TOP src tests kits midi patchbay ; +SubDir HAIKU_TOP src apps patchbay ; SetSubDirSupportedPlatformsBeOSCompatible ; @@ -10,8 +10,9 @@ SimpleTest PatchBay PatchRow.cpp EndpointInfo.cpp MidiEventMeter.cpp - TToolTip.cpp : midi midi2 be libicon.a $(TARGET_LIBSTDC++) + : + PatchBay.rdef ; diff --git a/src/tests/kits/midi/patchbay/MidiEventMeter.cpp b/src/apps/patchbay/MidiEventMeter.cpp similarity index 58% rename from src/tests/kits/midi/patchbay/MidiEventMeter.cpp rename to src/apps/patchbay/MidiEventMeter.cpp index f625be0cfa..719cf619e8 100644 --- a/src/tests/kits/midi/patchbay/MidiEventMeter.cpp +++ b/src/apps/patchbay/MidiEventMeter.cpp @@ -1,10 +1,16 @@ -// MidiEventMeter.cpp -// ------------------ -// Implements the MidiEventMeter class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - +/* MidiEventMeter.cpp + * ------------------ + * Implements the MidiEventMeter class. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + #include #include #include @@ -13,7 +19,7 @@ #include "CountEventConsumer.h" #include "MidiEventMeter.h" -static const BRect METER_BOUNDS(0,0,7,31); +static const BRect METER_BOUNDS(0, 0, 7, 31); // If we get this number of events per pulse or greater, we will // max out the event meter. @@ -21,8 +27,11 @@ static const BRect METER_BOUNDS(0,0,7,31); // keyboard controller with a pulse of 200ms. static const int32 METER_SCALE = 10; + MidiEventMeter::MidiEventMeter(int32 producerID) - : m_counter(NULL), m_meterLevel(0) + : + fCounter(NULL), + fMeterLevel(0) { BMidiRoster* roster = BMidiRoster::MidiRoster(); if (roster) { @@ -30,37 +39,45 @@ MidiEventMeter::MidiEventMeter(int32 producerID) if (producer) { BString name; name << producer->Name() << " Event Meter"; - m_counter = new CountEventConsumer(name.String()); - producer->Connect(m_counter); + fCounter = new CountEventConsumer(name.String()); + producer->Connect(fCounter); producer->Release(); } } } + MidiEventMeter::~MidiEventMeter() { - if (m_counter) m_counter->Release(); + if (fCounter) + fCounter->Release(); } -void MidiEventMeter::Pulse(BView* view) + +void +MidiEventMeter::Pulse(BView* view) { - int32 newLevel = m_meterLevel; - if (m_counter) { - newLevel = CalcMeterLevel(m_counter->CountEvents()); - m_counter->Reset(); + int32 newLevel = fMeterLevel; + if (fCounter) { + newLevel = CalcMeterLevel(fCounter->CountEvents()); + fCounter->Reset(); } - if (newLevel != m_meterLevel) { - m_meterLevel = newLevel; - view->Invalidate(BRect(METER_BOUNDS).InsetBySelf(1,1)); + if (newLevel != fMeterLevel) { + fMeterLevel = newLevel; + view->Invalidate(BRect(METER_BOUNDS).InsetBySelf(1, 1)); } } -BRect MidiEventMeter::Bounds() const + +BRect +MidiEventMeter::Bounds() const { return METER_BOUNDS; } -void MidiEventMeter::Draw(BView* view) + +void +MidiEventMeter::Draw(BView* view) { const rgb_color METER_BLACK = { 0, 0, 0, 255 }; const rgb_color METER_GREY = { 180, 180, 180, 255 }; @@ -80,16 +97,21 @@ void MidiEventMeter::Draw(BView* view) // draw the cells BRect cell = METER_BOUNDS; - cell.InsetBy(1,1); + cell.InsetBy(1, 1); cell.bottom = cell.top + (cell.Height() + 1) / 5; cell.bottom--; - const float kTintArray[] = { B_DARKEN_4_TINT, B_DARKEN_3_TINT, B_DARKEN_2_TINT, B_DARKEN_1_TINT, B_NO_TINT }; + const float kTintArray[] = + {B_DARKEN_4_TINT, + B_DARKEN_3_TINT, + B_DARKEN_2_TINT, + B_DARKEN_1_TINT, + B_NO_TINT}; - for (int32 i=4; i>=0; i--) + for (int32 i = 4; i >= 0; i--) { rgb_color color; - if (m_meterLevel > i) { + if (fMeterLevel > i) { color = tint_color(METER_GREEN, kTintArray[i]); } else { color = METER_GREY; @@ -102,21 +124,21 @@ void MidiEventMeter::Draw(BView* view) view->PopState(); } -int32 MidiEventMeter::CalcMeterLevel(int32 eventCount) const + +int32 +MidiEventMeter::CalcMeterLevel(int32 eventCount) const { // we use an approximately logarithmic scale for determing the actual // drawn meter level, so that low-density event streams show up well. - if (eventCount == 0) { + if (eventCount == 0) return 0; - } else if (eventCount < (int32)(.5*METER_SCALE)) { + else if (eventCount < (int32)(0.5 * METER_SCALE)) return 1; - } else if (eventCount < (int32)(.75*METER_SCALE)) { + else if (eventCount < (int32)(0.75 * METER_SCALE)) return 2; - } else if (eventCount < (int32)(.9*METER_SCALE)) { + else if (eventCount < (int32)(0.9 * METER_SCALE)) return 3; - } else if (eventCount < METER_SCALE) { + else if (eventCount < METER_SCALE) return 4; - } else { - return 5; - } + return 5; } diff --git a/src/apps/patchbay/MidiEventMeter.h b/src/apps/patchbay/MidiEventMeter.h new file mode 100644 index 0000000000..5866e6ec96 --- /dev/null +++ b/src/apps/patchbay/MidiEventMeter.h @@ -0,0 +1,42 @@ +/* MidiEventMeter.h + * ---------------- + * A UI widget that measures the amount of MIDI data generated by a + * consumer. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#ifndef _MidiEventMeter_h +#define _MidiEventMeter_h + +#include +#include + +class BMidiProducer; +class CountEventConsumer; +class BView; + +class MidiEventMeter +{ +public: + MidiEventMeter(int32 producerID); + ~MidiEventMeter(); + + void Pulse(BView* view); + BRect Bounds() const; + void Draw(BView* view); + +private: + int32 CalcMeterLevel(int32 eventCount) const; + + CountEventConsumer* fCounter; + int32 fMeterLevel; +}; + +#endif /* _MidiMeterWidget_h */ diff --git a/src/apps/patchbay/PatchApp.cpp b/src/apps/patchbay/PatchApp.cpp new file mode 100644 index 0000000000..acf351233d --- /dev/null +++ b/src/apps/patchbay/PatchApp.cpp @@ -0,0 +1,46 @@ +/* PatchApp.cpp + * ------------ + * Implements the PatchBay application class and main(). + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#include "PatchApp.h" + +#include +#include "PatchWin.h" + +PatchApp::PatchApp() + : + BApplication("application/x-vnd.Haiku.PatchBay") +{} + + +void +PatchApp::ReadyToRun() +{ + new PatchWin; +} + + +void +PatchApp::MessageReceived(BMessage* msg) +{ + BApplication::MessageReceived(msg); +} + + +int +main(void) +{ + PatchApp app; + app.Run(); + return 0; +} + diff --git a/src/apps/patchbay/PatchApp.h b/src/apps/patchbay/PatchApp.h new file mode 100644 index 0000000000..e45f32a931 --- /dev/null +++ b/src/apps/patchbay/PatchApp.h @@ -0,0 +1,27 @@ +/* PatchApp.h + * ---------- + * The PatchBay application class. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#ifndef _PatchApp_h +#define _PatchApp_h + +#include + +class PatchApp : public BApplication +{ +public: + PatchApp(); + void ReadyToRun(); + void MessageReceived(BMessage* msg); +}; + +#endif /* _PatchApp_h */ diff --git a/src/apps/patchbay/PatchBay.rdef b/src/apps/patchbay/PatchBay.rdef new file mode 100644 index 0000000000..47f170fdca --- /dev/null +++ b/src/apps/patchbay/PatchBay.rdef @@ -0,0 +1,75 @@ + +resource app_signature "application/x-vnd.Haiku.PatchBay"; + +resource app_name_catalog_entry "application/x-vnd.Haiku.PatchBay:System name:PatchBay"; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + + variety = 2, + internal = 0, + + short_info = "PatchBay", + + long_info = "PatchBay MIDI Port interconnection ©2013 Haiku, Inc." +}; + +resource app_flags B_SINGLE_LAUNCH; + + +resource vector_icon { + $"6E636966140401740500020006023C5783372F7CB8EFFB3E28D3482623479BB1" + $"00E1FCF3FF8DDAC0020006023B3049396B0ABA90833C646E4A101543299500E1" + $"FCF3FFB4EEDB02000603395E1E32DB49B6921A3D07D74A57904908D600646464" + $"0678948AFF78948A050102031604BEBE2BBEE9573EE957BEBE2B48B7784A2FD3" + $"0001C670D073FFFF020116033EB0000000000000003EB000470000486000BE4B" + $"0084FF32020316023C4E213D44DABD44DA3C4E214926894A428EA143FFFF0203" + $"1602BC6B27BD2F9C3D2F9CBC6B2748B0FD4A3D7CAB08FFFF0300FF0005010200" + $"1605BF2F31BF38ED3ED85CBECFC4499A0C4B50220001377000716D73FFFF0201" + $"16033EB0000000000000003EB000482000482000BE4B0084FF3202000604BE37" + $"C8B7C456379553BE1C1A4B24CF4C81BE0E0000008F040202FF685B5BFFFFFFFF" + $"02030603BCD4ABBC8A9D3DAD85BE0C574A5F474B05CB8A080808FFC9C4C4FFB2" + $"A7A702000603BA8802BC993B3DD226BBB8D249CA264BD1370008010100FFAA00" + $"FF08010102000603BA51E2B9CF15B97D653A20214B39494A12BA0008010100FF" + $"AA00FF08010102000603390B9BBB2FCAB9D8B1B7AD044A23004B7F9900080101" + $"00FFAA00FF08010102000603B847EDB76620BB18843C13D84A521C4A634F00F9" + $"EED70037290DFFF9EED7090A04455F4F5E5F4E4F460A04272B2750465E46350A" + $"044636465E564E562B0A04272B4636562B38230A06262B2650465F574E572B38" + $"2202043735BEB4BC7430322A3F2ABC962AC21D3551B8D3C56F3C54434743C54D" + $"433E020440304932BC50B89C303D30BB0830C2133F4FBC02C49C48524F444FC4" + $"DD4FBDD20A043A4A3A554459444D060AFEF107BF0048BF00C3A2BF00C3A2BF00" + $"C3A23DC4553DC3A23DC507BF00C507BF00C523BF00C4EB4FBF4DBF4DC507BF4D" + $"C50DBF4DC50140C45540C50740C3A2BF4DC39DBF4DC397BF4DC3A248290A0001" + $"002021210A0101041001178200040A020101000A030103000A040102000A0B01" + $"051001178400040A0F0105123FAFC50000000000003FB0194301D643017D0117" + $"8500040A0E0105123FA0000000000000003FA04841FFFB42FB8801178200040A" + $"0C0105023F77770000000000003F77774244444422220A130107123DB13B0000" + $"000000003E023E455D893B535E01178100040A100107023D60B1B053F32F5F01" + $"3E551D45E7E1C3AE060A11010830172101158000040A120108123F3E45BE5759" + $"3E57593F3E45C90928495A4C01158000040A110108123C90423FCA00BFCA003C" + $"90424AE74EC4752501158000040A120108123C7791BFCE173FCE173C7791C8BD" + $"2F4B800301158000040A110108123EE5493EC273BEC2733EE549490C6EC67EAD" + $"01158000040A0B000237D7012A6354AAA73E38221B486CD349FAFB0A0B010512" + $"BE04150000000000003FAF574BA0103ED0A801178400040A0F010512BDB74D00" + $"00000000003F65BC4B87D043790B01178500040A0E010512BDA7670000000000" + $"003F572A4B8FEF43738E01178200040A0C010502BD7E8C0000000000003F3190" + $"4B8DC94451320A13010712BBB8C50000000000003DB3794B69C93F94BC011781" + $"00040A10010702BB6797B02503AD65E43E26154B6112C2AFA90A11010812BE04" + $"150000000000003FAF574BE8A341400001158000040A12010812BD44E6BE2824" + $"BC5C223EFCE04C31F3492D3701158000040A11010812BA957F3F7D993DD1BE3C" + $"5C914A2972C3D30401158000040A12010812BA7C9BBF815DBDD5DD3C45D24C28" + $"614B44B201158000040A11010812BCEB333E8ACE3CC8163EAAE54ADB66C61F54" + $"01158000040A0B0002B5DED92A332D28ACAA37EE2F4B039E49C13E0A0B010512" + $"BFEE20BBF39CB90B913D07574B9193440B9D01178400040A0F010512BF9F4CBB" + $"A45AB8CEBC3CCAD74B5DB9443E3501178500040A0E010512BF8FCEBB94C6B8C2" + $"B23CBEDE4B5DA144656901178200040A0C010502BF67FABB6CBAB8A39F3C9FF6" + $"4B577B449B340A13010712BDA0BBB9A5CBB70EFB3B0ABC4B177B4292CB011781" + $"00040A10010702BD16C6BAF1F5B934283B45744B2953443BF50A11010812BFE3" + $"13BC4AC7B9885D3CFED34C04CD45CD7C01158000040A12010812BEE4A7BD9C97" + $"BEA2143A2C9E4C64D548B4E801158000040A11010812BD53E43C1A5C3F8A613D" + $"218E46D73DC69FE701158000040A12010812BB1D51BD8E67BFD570BA83684C38" + $"9B49FCC101158000040A11010812BF1E563742033E5CA93DBFED4A15DFC50930" + $"01158000040A0B0002B78654B54AE7B2B098350C6A4A20C547001D" +}; diff --git a/src/tests/kits/midi/patchbay/PatchRow.cpp b/src/apps/patchbay/PatchRow.cpp similarity index 54% rename from src/tests/kits/midi/patchbay/PatchRow.cpp rename to src/apps/patchbay/PatchRow.cpp index 5906a29aeb..6dfe3539d6 100644 --- a/src/tests/kits/midi/patchbay/PatchRow.cpp +++ b/src/apps/patchbay/PatchRow.cpp @@ -1,9 +1,16 @@ -// PatchRow.cpp -// ------------ -// Implements the PatchRow class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. +/* PatchRow.cpp + * ------------ + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#include "PatchRow.h" #include #include @@ -13,7 +20,6 @@ #include #include #include "MidiEventMeter.h" -#include "PatchRow.h" extern const float ROW_LEFT = 50.0f; extern const float ROW_TOP = 50.0f; @@ -22,7 +28,7 @@ extern const float COLUMN_WIDTH = 40.0f; extern const float METER_PADDING = 15.0f; extern const uint32 MSG_CONNECT_REQUEST = 'mCRQ'; -static const BPoint kBoxOffset(8,7); +static const BPoint kBoxOffset(8, 7); // PatchCheckBox is the check box that describes a connection // between a producer and a consumer. @@ -30,119 +36,145 @@ class PatchCheckBox : public BCheckBox { public: PatchCheckBox(BRect r, int32 producerID, int32 consumerID) - : BCheckBox(r, "", "", new BMessage(MSG_CONNECT_REQUEST)) - { - m_producerID = producerID; - m_consumerID = consumerID; - } + : + BCheckBox(r, "", "", new BMessage(MSG_CONNECT_REQUEST)), + fProducerID(producerID), + fConsumerID(consumerID) + {} - int32 ProducerID() const { return m_producerID; } - int32 ConsumerID() const { return m_consumerID; } + int32 ProducerID() const + { + return fProducerID; + } + int32 ConsumerID() const + { + return fConsumerID; + } void DoConnect(); private: - int32 m_producerID; - int32 m_consumerID; + int32 fProducerID; + int32 fConsumerID; }; + PatchRow::PatchRow(int32 producerID) - : BView(BRect(0,0,0,0), "PatchRow", B_FOLLOW_NONE, - B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED), - m_producerID(producerID), m_eventMeter(NULL) + : + BView(BRect(0, 0, 0, 0), "PatchRow", B_FOLLOW_NONE, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED), + fProducerID(producerID), + fEventMeter(NULL) { - m_eventMeter = new MidiEventMeter(m_producerID); + fEventMeter = new MidiEventMeter(fProducerID); } + PatchRow::~PatchRow() { - delete m_eventMeter; + delete fEventMeter; } -int32 PatchRow::ID() const + +int32 +PatchRow::ID() const { - return m_producerID; + return fProducerID; } -void PatchRow::Pulse() + +void +PatchRow::Pulse() { - if (m_eventMeter) m_eventMeter->Pulse(this); + if (fEventMeter) + fEventMeter->Pulse(this); } -void PatchRow::Draw(BRect) + +void +PatchRow::Draw(BRect) { - if (m_eventMeter) m_eventMeter->Draw(this); + if (fEventMeter) + fEventMeter->Draw(this); } -void PatchRow::AddColumn(int32 consumerID) + +void +PatchRow::AddColumn(int32 consumerID) { - BRect r; + BRect rect; int32 numColumns = CountChildren(); - r.left = numColumns*COLUMN_WIDTH + METER_PADDING + kBoxOffset.x; - r.top = kBoxOffset.y; - r.right = r.left + 20; - r.bottom = r.top + 20; + rect.left = numColumns * COLUMN_WIDTH + METER_PADDING + kBoxOffset.x; + rect.top = kBoxOffset.y; + rect.right = rect.left + 20; + rect.bottom = rect.top + 20; - PatchCheckBox* box = new PatchCheckBox(r, m_producerID, consumerID); + PatchCheckBox* box = new PatchCheckBox(rect, fProducerID, consumerID); AddChild(box); box->SetTarget(this); } -void PatchRow::RemoveColumn(int32 consumerID) + +void +PatchRow::RemoveColumn(int32 consumerID) { int32 numChildren = CountChildren(); - for (int32 i=0; i(ChildAt(i)); if (box && box->ConsumerID() == consumerID) { RemoveChild(box); delete box; while (i < numChildren) { box = dynamic_cast(ChildAt(i++)); - if (box) { + if (box) box->MoveBy(-COLUMN_WIDTH, 0); - } } break; } } } -void PatchRow::Connect(int32 consumerID) + +void +PatchRow::Connect(int32 consumerID) { int32 numChildren = CountChildren(); - for (int32 i=0; i(ChildAt(i)); - if (box && box->ConsumerID() == consumerID) { + if (box && box->ConsumerID() == consumerID) box->SetValue(1); - } } } -void PatchRow::Disconnect(int32 consumerID) + +void +PatchRow::Disconnect(int32 consumerID) { int32 numChildren = CountChildren(); - for (int32 i=0; i(ChildAt(i)); - if (box && box->ConsumerID() == consumerID) { + if (box && box->ConsumerID() == consumerID) box->SetValue(0); - } } } -void PatchRow::AttachedToWindow() + +void +PatchRow::AttachedToWindow() { Window()->SetPulseRate(200000); SetViewColor(Parent()->ViewColor()); int32 numChildren = CountChildren(); - for (int32 i=0; i(ChildAt(i)); - if (box) { + if (box) box->SetTarget(this); - } } } -void PatchRow::MessageReceived(BMessage* msg) + +void +PatchRow::MessageReceived(BMessage* msg) { switch (msg->what) { case MSG_CONNECT_REQUEST: @@ -150,9 +182,8 @@ void PatchRow::MessageReceived(BMessage* msg) BControl* ctrl; if (msg->FindPointer("source", (void**) &ctrl) == B_OK) { PatchCheckBox* box = dynamic_cast(ctrl); - if (box) { + if (box) box->DoConnect(); - } } } break; @@ -162,33 +193,34 @@ void PatchRow::MessageReceived(BMessage* msg) } } -void PatchCheckBox::DoConnect() + +void +PatchCheckBox::DoConnect() { int32 value = Value(); int32 inverseValue = (value + 1) % 2; BMidiRoster* roster = BMidiRoster::MidiRoster(); - if (! roster) { + if (roster == NULL) { SetValue(inverseValue); return; } - BMidiProducer* producer = roster->FindProducer(m_producerID); - BMidiConsumer* consumer = roster->FindConsumer(m_consumerID); + BMidiProducer* producer = roster->FindProducer(fProducerID); + BMidiConsumer* consumer = roster->FindConsumer(fConsumerID); if (producer && consumer) { status_t err; - if (value) { + if (value) err = producer->Connect(consumer); - } else { + else err = producer->Disconnect(consumer); - } if (err != B_OK) { SetValue(inverseValue); } - } else { + } else SetValue(inverseValue); - } + if (producer) producer->Release(); if (consumer) consumer->Release(); } diff --git a/src/tests/kits/midi/patchbay/PatchRow.h b/src/apps/patchbay/PatchRow.h similarity index 65% rename from src/tests/kits/midi/patchbay/PatchRow.h rename to src/apps/patchbay/PatchRow.h index a534313472..21977b6c59 100644 --- a/src/tests/kits/midi/patchbay/PatchRow.h +++ b/src/apps/patchbay/PatchRow.h @@ -1,3 +1,15 @@ +/* PatchRow.h + * ---------- + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + #ifndef _PatchRow_h #define _PatchRow_h @@ -31,8 +43,8 @@ public: void Disconnect(int32 consumerID); private: - int32 m_producerID; - MidiEventMeter* m_eventMeter; + int32 fProducerID; + MidiEventMeter* fEventMeter; }; #endif /* _PatchRow_h */ diff --git a/src/apps/patchbay/PatchView.cpp b/src/apps/patchbay/PatchView.cpp new file mode 100644 index 0000000000..dc0054e49a --- /dev/null +++ b/src/apps/patchbay/PatchView.cpp @@ -0,0 +1,484 @@ +/* PatchView.cpp + * ------------- + * Implements the main PatchBay view class. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#include "PatchView.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "EndpointInfo.h" +#include "PatchRow.h" +#include "UnknownDeviceIcons.h" + + +PatchView::PatchView(BRect rect) + : + BView(rect, "PatchView", B_FOLLOW_ALL, B_WILL_DRAW), + fUnknownDeviceIcon(NULL) +{ + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + BRect iconRect(0, 0, LARGE_ICON_SIZE - 1, LARGE_ICON_SIZE - 1); + fUnknownDeviceIcon = new BBitmap(iconRect, B_RGBA32); + if (BIconUtils::GetVectorIcon( + UnknownDevice::kVectorIcon, + sizeof(UnknownDevice::kVectorIcon), + fUnknownDeviceIcon) == B_OK) + return; + delete fUnknownDeviceIcon; +} + + +PatchView::~PatchView() +{ + delete fUnknownDeviceIcon; +} + + +void +PatchView::AttachedToWindow() +{ + BMidiRoster* roster = BMidiRoster::MidiRoster(); + if (roster == NULL) { + PRINT(("Couldn't get MIDI roster\n")); + be_app->PostMessage(B_QUIT_REQUESTED); + return; + } + + BMessenger msgr(this); + roster->StartWatching(&msgr); +} + + +void +PatchView::MessageReceived(BMessage* msg) +{ + switch (msg->what) { + case B_MIDI_EVENT: + HandleMidiEvent(msg); + break; + default: + BView::MessageReceived(msg); + break; + } +} + + +bool +PatchView::GetToolTipAt(BPoint point, BToolTip** tip) +{ + bool found = false; + int32 index = 0; + endpoint_itor begin, end; + int32 size = fConsumers.size(); + for (int32 i = 0; !found && i < size; i++) { + BRect r = ColumnIconFrameAt(i); + if (r.Contains(point)) { + begin = fConsumers.begin(); + end = fConsumers.end(); + found = true; + index = i; + } + } + size = fProducers.size(); + for (int32 i = 0; !found && i < size; i++) { + BRect r = RowIconFrameAt(i); + if (r.Contains(point)) { + begin = fProducers.begin(); + end = fProducers.end(); + found = true; + index = i; + } + } + + if (!found) + return false; + + endpoint_itor itor; + for (itor = begin; itor != end; itor++, index--) + if (index <= 0) break; + + if (itor == end) + return false; + + BMidiRoster* roster = BMidiRoster::MidiRoster(); + if (roster == NULL) + return false; + BMidiEndpoint* obj = roster->FindEndpoint(itor->ID()); + if (obj == NULL) + return false; + + BString str; + str << "<" << obj->ID() << ">: " << obj->Name(); + obj->Release(); + + SetToolTip(str.String()); + + *tip = ToolTip(); + + return true; +} + + +void +PatchView::Draw(BRect /* updateRect */) +{ + // draw producer icons + SetDrawingMode(B_OP_OVER); + int32 index = 0; + for (list::const_iterator i = fProducers.begin(); + i != fProducers.end(); i++) { + const BBitmap* bitmap = (i->Icon()) ? i->Icon() : fUnknownDeviceIcon; + DrawBitmapAsync(bitmap, RowIconFrameAt(index++).LeftTop()); + } + + // draw consumer icons + index = 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()); + } +} + + +BRect +PatchView::ColumnIconFrameAt(int32 index) const +{ + BRect rect; + rect.left = ROW_LEFT + METER_PADDING + index * COLUMN_WIDTH; + rect.top = 10; + rect.right = rect.left + 31; + rect.bottom = rect.top + 31; + return rect; +} + + +BRect +PatchView::RowIconFrameAt(int32 index) const +{ + BRect rect; + rect.left = 10; + rect.top = ROW_TOP + index * ROW_HEIGHT; + rect.right = rect.left + 31; + rect.bottom = rect.top + 31; + return rect; +} + + +void +PatchView::HandleMidiEvent(BMessage* msg) +{ + SET_DEBUG_ENABLED(true); + + int32 op; + if (msg->FindInt32("be:op", &op) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"op\" field not found\n")); + return; + } + + switch (op) { + case B_MIDI_REGISTERED: + { + int32 id; + if (msg->FindInt32("be:id", &id) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:id\"" + " field not found in B_MIDI_REGISTERED event\n")); + break; + } + + const char* type; + if (msg->FindString("be:type", &type) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:type\"" + " field not found in B_MIDI_REGISTERED event\n")); + break; + } + + PRINT(("MIDI Roster Event B_MIDI_REGISTERED: id=%ld, type=%s\n", + id, type)); + if (strcmp(type, "producer") == 0) + AddProducer(id); + else if (strcmp(type, "consumer") == 0) + AddConsumer(id); + } + break; + case B_MIDI_UNREGISTERED: + { + int32 id; + if (msg->FindInt32("be:id", &id) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:id\"" + " field not found in B_MIDI_UNREGISTERED\n")); + break; + } + + const char* type; + if (msg->FindString("be:type", &type) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:type\"" + " field not found in B_MIDI_UNREGISTERED\n")); + break; + } + + PRINT(("MIDI Roster Event B_MIDI_UNREGISTERED: id=%ld, type=%s\n", + id, type)); + if (strcmp(type, "producer") == 0) + RemoveProducer(id); + else if (strcmp(type, "consumer") == 0) + RemoveConsumer(id); + } + break; + case B_MIDI_CHANGED_PROPERTIES: + { + int32 id; + if (msg->FindInt32("be:id", &id) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:id\"" + " field not found in B_MIDI_CHANGED_PROPERTIES\n")); + break; + } + + const char* type; + if (msg->FindString("be:type", &type) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:type\"" + " field not found in B_MIDI_CHANGED_PROPERTIES\n")); + break; + } + + BMessage props; + if (msg->FindMessage("be:properties", &props) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:properties\"" + " field not found in B_MIDI_CHANGED_PROPERTIES\n")); + break; + } + + PRINT(("MIDI Roster Event B_MIDI_CHANGED_PROPERTIES: id=%ld, type=%s\n", + id, type)); + if (strcmp(type, "producer") == 0) + UpdateProducerProps(id, &props); + else if (strcmp(type, "consumer") == 0) + UpdateConsumerProps(id, &props); + + } + break; + case B_MIDI_CHANGED_NAME: + case B_MIDI_CHANGED_LATENCY: + // we don't care about these + break; + case B_MIDI_CONNECTED: + { + int32 prod; + if (msg->FindInt32("be:producer", &prod) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:producer\"" + " field not found in B_MIDI_CONNECTED\n")); + break; + } + + int32 cons; + if (msg->FindInt32("be:consumer", &cons) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:consumer\"" + " field not found in B_MIDI_CONNECTED\n")); + break; + } + PRINT(("MIDI Roster Event B_MIDI_CONNECTED: producer=%ld, consumer=%ld\n", + prod, cons)); + Connect(prod, cons); + } + break; + case B_MIDI_DISCONNECTED: + { + int32 prod; + if (msg->FindInt32("be:producer", &prod) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:producer\"" + " field not found in B_MIDI_DISCONNECTED\n")); + break; + } + + int32 cons; + if (msg->FindInt32("be:consumer", &cons) != B_OK) { + PRINT(("PatchView::HandleMidiEvent: \"be:consumer\"" + " field not found in B_MIDI_DISCONNECTED\n")); + break; + } + PRINT(("MIDI Roster Event B_MIDI_DISCONNECTED: producer=%ld, consumer=%ld\n", + prod, cons)); + Disconnect(prod, cons); + } + break; + default: + PRINT(("PatchView::HandleMidiEvent: unknown opcode %ld\n", op)); + break; + } +} + + +void +PatchView::AddProducer(int32 id) +{ + EndpointInfo info(id); + fProducers.push_back(info); + + Window()->BeginViewTransaction(); + PatchRow* row = new PatchRow(id); + fPatchRows.push_back(row); + BPoint p1 = CalcRowOrigin(fPatchRows.size() - 1); + BPoint p2 = CalcRowSize(); + row->MoveTo(p1); + row->ResizeTo(p2.x, p2.y); + for (list::const_iterator i = fConsumers.begin(); + i != fConsumers.end(); i++) + row->AddColumn(i->ID()); + AddChild(row); + Invalidate(); + Window()->EndViewTransaction(); +} + + +void +PatchView::AddConsumer(int32 id) +{ + EndpointInfo info(id); + fConsumers.push_back(info); + + Window()->BeginViewTransaction(); + BPoint newSize = CalcRowSize(); + for (row_itor i = fPatchRows.begin(); i != fPatchRows.end(); i++) { + (*i)->AddColumn(id); + (*i)->ResizeTo(newSize.x, newSize.y - 1); + } + Invalidate(); + Window()->EndViewTransaction(); +} + + +void +PatchView::RemoveProducer(int32 id) +{ + for (endpoint_itor i = fProducers.begin(); i != fProducers.end(); i++) { + if (i->ID() == id) { + fProducers.erase(i); + break; + } + } + + Window()->BeginViewTransaction(); + for (row_itor i = fPatchRows.begin(); i != fPatchRows.end(); i++) { + if ((*i)->ID() == id) { + PatchRow* row = *i; + i = fPatchRows.erase(i); + RemoveChild(row); + delete row; + float moveBy = -1 * CalcRowSize().y; + while (i != fPatchRows.end()) { + (*i++)->MoveBy(0, moveBy); + } + break; + } + } + Invalidate(); + Window()->EndViewTransaction(); +} + + +void +PatchView::RemoveConsumer(int32 id) +{ + Window()->BeginViewTransaction(); + for (endpoint_itor i = fConsumers.begin(); i != fConsumers.end(); i++) { + if (i->ID() == id) { + fConsumers.erase(i); + break; + } + } + + BPoint newSize = CalcRowSize(); + for (row_itor i = fPatchRows.begin(); i != fPatchRows.end(); i++) { + (*i)->RemoveColumn(id); + (*i)->ResizeTo(newSize.x, newSize.y - 1); + } + Invalidate(); + Window()->EndViewTransaction(); +} + + +void +PatchView::UpdateProducerProps(int32 id, const BMessage* props) +{ + for (endpoint_itor i = fProducers.begin(); i != fProducers.end(); i++) { + if (i->ID() == id) { + i->UpdateProperties(props); + Invalidate(); + break; + } + } +} + + +void +PatchView::UpdateConsumerProps(int32 id, const BMessage* props) +{ + for (endpoint_itor i = fConsumers.begin(); i != fConsumers.end(); i++) { + if (i->ID() == id) { + i->UpdateProperties(props); + Invalidate(); + break; + } + } +} + + +void +PatchView::Connect(int32 prod, int32 cons) +{ + for (row_itor i = fPatchRows.begin(); i != fPatchRows.end(); i++) { + if ((*i)->ID() == prod) { + (*i)->Connect(cons); + break; + } + } +} + + +void +PatchView::Disconnect(int32 prod, int32 cons) +{ + for (row_itor i = fPatchRows.begin(); i != fPatchRows.end(); i++) { + if ((*i)->ID() == prod) { + (*i)->Disconnect(cons); + break; + } + } +} + + +BPoint +PatchView::CalcRowOrigin(int32 rowIndex) const +{ + BPoint point; + point.x = ROW_LEFT; + point.y = ROW_TOP + rowIndex * ROW_HEIGHT; + return point; +} + + +BPoint +PatchView::CalcRowSize() const +{ + BPoint point; + point.x = METER_PADDING + fConsumers.size()*COLUMN_WIDTH; + point.y = ROW_HEIGHT - 1; + return point; +} diff --git a/src/tests/kits/midi/patchbay/PatchView.h b/src/apps/patchbay/PatchView.h similarity index 58% rename from src/tests/kits/midi/patchbay/PatchView.h rename to src/apps/patchbay/PatchView.h index 9b36d55ed9..3298c5bf3a 100644 --- a/src/tests/kits/midi/patchbay/PatchView.h +++ b/src/apps/patchbay/PatchView.h @@ -1,12 +1,18 @@ -// PatchView.h -// ----------- -// The main PatchBay view contains a row of icons along the top and -// left sides representing available consumers and producers, and -// a set of PatchRows which build the matrix of connections. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - +/* PatchView.h + * ----------- + * The main PatchBay view contains a row of icons along the top and + * left sides representing available consumers and producers, and + * a set of PatchRows which build the matrix of connections. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + #ifndef _PatchView_h #define _PatchView_h @@ -17,7 +23,6 @@ class PatchRow; class BBitmap; -class TToolTip; using namespace std; @@ -30,7 +35,6 @@ public: void AttachedToWindow(); void MessageReceived(BMessage* msg); void Draw(BRect updateRect); - void MouseMoved(BPoint point, uint32 transit, const BMessage* dragMsg); private: typedef enum { @@ -40,11 +44,8 @@ private: BRect ColumnIconFrameAt(int32 index) const; BRect RowIconFrameAt(int32 index) const; - void StartTipTracking(BPoint pt, BRect rect, int32 index, track_type type=TRACK_COLUMN); - void StopTipTracking(); - void StartTip(BPoint pt, BRect rect, const char* str); - void StopTip(); - + virtual bool GetToolTipAt(BPoint point, BToolTip** tip); + void AddProducer(int32 id); void AddConsumer(int32 id); void RemoveProducer(int32 id); @@ -63,13 +64,10 @@ private: typedef list::const_iterator const_endpoint_itor; typedef list::iterator row_itor; - list m_producers; - list m_consumers; - list m_patchRows; - BBitmap* m_unknownDeviceIcon; - int32 m_trackIndex; - track_type m_trackType; - TToolTip* m_toolTip; + list fProducers; + list fConsumers; + list fPatchRows; + BBitmap* fUnknownDeviceIcon; }; #endif /* _PatchView_h */ diff --git a/src/apps/patchbay/PatchWin.cpp b/src/apps/patchbay/PatchWin.cpp new file mode 100644 index 0000000000..8c45054758 --- /dev/null +++ b/src/apps/patchbay/PatchWin.cpp @@ -0,0 +1,36 @@ +/* PatchWin.cpp + * ------------ + * Implements the main PatchBay window class. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#include "PatchWin.h" + +#include +#include "PatchView.h" + + +PatchWin::PatchWin() + : + BWindow(BRect(50, 50, 450, 450), "Patch Bay", B_TITLED_WINDOW, 0) +{ + BRect r = Bounds(); + fPatchView = new PatchView(r); + AddChild(fPatchView); + Show(); +} + + +bool +PatchWin::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} diff --git a/src/apps/patchbay/PatchWin.h b/src/apps/patchbay/PatchWin.h new file mode 100644 index 0000000000..c5659ea915 --- /dev/null +++ b/src/apps/patchbay/PatchWin.h @@ -0,0 +1,30 @@ +/* PatchWin.h + * ---------- + * The main PatchBay window class. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#ifndef _PatchWin_h +#define _PatchWin_h + +#include + +class PatchView; + +class PatchWin : public BWindow +{ +public: + PatchWin(); + bool QuitRequested(); +private: + PatchView* fPatchView; +}; + +#endif /* _PatchWin_h */ diff --git a/src/apps/patchbay/UnknownDeviceIcons.h b/src/apps/patchbay/UnknownDeviceIcons.h new file mode 100644 index 0000000000..365d60792a --- /dev/null +++ b/src/apps/patchbay/UnknownDeviceIcons.h @@ -0,0 +1,105 @@ +/* UnknownDeviceIcons.h + * -------------------- + * The icons to be used in case a device doesn't supply its icons. + * + * Copyright 2013, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Revisions by Pete Goodeve + * + * Copyright 1999, Be Incorporated. All Rights Reserved. + * This file may be used under the terms of the Be Sample Code License. + */ + +#ifndef _UnknownDeviceIcons_h +#define _UnknownDeviceIcons_h + +namespace UnknownDevice { + +// For Haiku we only need the Vector Icon +const unsigned char kVectorIcon[] = { + 0x6e, 0x63, 0x69, 0x66, 0x0c, 0x05, 0x01, 0x02, 0x00, 0x16, 0x05, 0xbf, + 0x2f, 0x31, 0xbf, 0x38, 0xed, 0x3e, 0xd8, 0x5c, 0xbe, 0xcf, 0xc4, 0x49, + 0x9a, 0x0c, 0x4b, 0x50, 0x22, 0x00, 0x01, 0x37, 0x70, 0x00, 0x71, 0x6d, + 0x73, 0xff, 0xff, 0x02, 0x01, 0x16, 0x03, 0x3e, 0xb0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3e, 0xb0, 0x00, 0x48, 0x20, 0x00, 0x48, 0x20, + 0x00, 0xbe, 0x4b, 0x00, 0x84, 0xff, 0x32, 0x02, 0x00, 0x06, 0x04, 0xbe, + 0x37, 0xc8, 0xb7, 0xc4, 0x56, 0x37, 0x95, 0x53, 0xbe, 0x1c, 0x1a, 0x4b, + 0x24, 0xcf, 0x4c, 0x81, 0xbe, 0x0e, 0x00, 0x00, 0x00, 0x8f, 0x04, 0x02, + 0x02, 0xff, 0x68, 0x5b, 0x5b, 0xff, 0xff, 0xff, 0xff, 0x02, 0x03, 0x06, + 0x03, 0xbc, 0xd4, 0xab, 0xbc, 0x8a, 0x9d, 0x3d, 0xad, 0x85, 0xbe, 0x0c, + 0x57, 0x4a, 0x5f, 0x47, 0x4b, 0x05, 0xcb, 0x8a, 0x08, 0x08, 0x08, 0xff, + 0xc9, 0xc4, 0xc4, 0xff, 0xb2, 0xa7, 0xa7, 0x02, 0x00, 0x06, 0x03, 0xba, + 0x88, 0x02, 0xbc, 0x99, 0x3b, 0x3d, 0xd2, 0x26, 0xbb, 0xb8, 0xd2, 0x49, + 0xca, 0x26, 0x4b, 0xd1, 0x37, 0x00, 0x08, 0x01, 0x01, 0x00, 0xff, 0xaa, + 0x00, 0xff, 0x08, 0x01, 0x01, 0x02, 0x00, 0x06, 0x03, 0xba, 0x51, 0xe2, + 0xb9, 0xcf, 0x15, 0xb9, 0x7d, 0x65, 0x3a, 0x20, 0x21, 0x4b, 0x39, 0x49, + 0x4a, 0x12, 0xba, 0x00, 0x08, 0x01, 0x01, 0x00, 0xff, 0xaa, 0x00, 0xff, + 0x08, 0x01, 0x01, 0x02, 0x00, 0x06, 0x03, 0x39, 0x0b, 0x9b, 0xbb, 0x2f, + 0xca, 0xb9, 0xd8, 0xb1, 0xb7, 0xad, 0x04, 0x4a, 0x23, 0x00, 0x4b, 0x7f, + 0x99, 0x00, 0x08, 0x01, 0x01, 0x00, 0xff, 0xaa, 0x00, 0xff, 0x08, 0x01, + 0x01, 0x02, 0x00, 0x06, 0x03, 0x36, 0xa6, 0x66, 0x35, 0xf2, 0xe6, 0xbb, + 0x18, 0x84, 0x3c, 0x13, 0xd8, 0x4a, 0x92, 0x1c, 0x4a, 0xb3, 0x4f, 0x00, + 0xf9, 0xee, 0xd7, 0x00, 0x37, 0x29, 0x0d, 0xff, 0xf9, 0xee, 0xd7, 0x05, + 0x00, 0x02, 0x00, 0x06, 0x03, 0x3a, 0x89, 0x7d, 0xbc, 0xf6, 0x83, 0x3d, + 0x95, 0x65, 0x3b, 0x11, 0x89, 0xc0, 0xa4, 0x24, 0x4a, 0xaf, 0xae, 0x00, + 0xff, 0xb1, 0x1b, 0x69, 0xf6, 0xff, 0x1a, 0xff, 0xff, 0xf9, 0xc7, 0x02, + 0x00, 0x06, 0x03, 0xbc, 0xe8, 0xf1, 0x3d, 0xc1, 0x1a, 0xbf, 0x29, 0x59, + 0xbe, 0x73, 0x51, 0x4b, 0x4e, 0xe9, 0x4b, 0x19, 0x62, 0x00, 0xe3, 0xf0, + 0xeb, 0x81, 0x00, 0xff, 0xaa, 0xff, 0x00, 0x00, 0x00, 0x06, 0x02, 0x04, + 0x40, 0x22, 0xc6, 0x59, 0x22, 0xb9, 0x26, 0x22, 0x22, 0x40, 0x22, 0xb9, + 0x26, 0x22, 0xc6, 0x59, 0x40, 0x5e, 0xb9, 0x26, 0x5e, 0xc6, 0x59, 0x5e, + 0x5e, 0x40, 0x5e, 0xc6, 0x59, 0x5e, 0xb9, 0x26, 0x0a, 0x04, 0x3a, 0x4e, + 0x3a, 0x5a, 0x46, 0x5a, 0x46, 0x4e, 0x06, 0x0a, 0xfe, 0xf1, 0x07, 0xbf, + 0x73, 0x48, 0xbf, 0x73, 0xc4, 0x6e, 0xbf, 0x73, 0xc4, 0x6e, 0xbf, 0x73, + 0xc4, 0x6e, 0x3d, 0xc5, 0xed, 0x3d, 0xc4, 0x6e, 0x3d, 0xc7, 0x6b, 0xbf, + 0x73, 0xc7, 0x6b, 0xbf, 0x73, 0xc7, 0xa6, 0xbf, 0x73, 0xc7, 0x30, 0x57, + 0xc0, 0x0c, 0xc0, 0x0c, 0xc7, 0x6b, 0xc0, 0x0c, 0xc7, 0x77, 0xc0, 0x0c, + 0xc7, 0x5f, 0x43, 0xc5, 0xed, 0x43, 0xc7, 0x6b, 0x43, 0xc4, 0x6e, 0xc0, + 0x0c, 0xc4, 0x62, 0xc0, 0x0c, 0xc4, 0x57, 0xc0, 0x0c, 0xc4, 0x6e, 0x48, + 0x06, 0x10, 0xff, 0xaf, 0xfb, 0xef, 0x29, 0x43, 0xb5, 0x83, 0xc1, 0xeb, + 0xb7, 0x6e, 0xc0, 0x2d, 0x2e, 0x41, 0x2c, 0x41, 0x33, 0x41, 0x38, 0x44, + 0xbb, 0x8b, 0xc0, 0x53, 0x3a, 0x46, 0x38, 0x4e, 0x3a, 0x4a, 0xbc, 0x0e, + 0xc6, 0x56, 0x31, 0x52, 0x32, 0x51, 0x30, 0x53, 0x2f, 0x53, 0x2e, 0x55, + 0xb9, 0x27, 0xc6, 0xf6, 0x2e, 0x58, 0x2c, 0x57, 0x2c, 0x53, 0x2b, 0x56, + 0x2d, 0x50, 0x2f, 0x50, 0x35, 0x4b, 0xbb, 0x02, 0xc4, 0xd8, 0x37, 0x47, + 0x32, 0x45, 0x34, 0x46, 0xb9, 0xa6, 0xc1, 0x7b, 0xb7, 0xbf, 0xc1, 0xb1, + 0xb8, 0x82, 0xc1, 0x3e, 0x2a, 0x46, 0x29, 0x47, 0xb6, 0xdc, 0xc2, 0x1f, + 0x28, 0xc3, 0x21, 0x28, 0x4c, 0x26, 0x47, 0x25, 0x49, 0xb6, 0x59, 0xc0, + 0x9e, 0x02, 0x04, 0xb8, 0x61, 0x5a, 0xb8, 0xed, 0x5a, 0xb7, 0xd4, 0x5a, + 0x2b, 0xcb, 0x1b, 0x2b, 0xca, 0x8e, 0x2b, 0xcb, 0xa7, 0xb8, 0x61, 0x5f, + 0xb7, 0xd4, 0x5f, 0xb8, 0xed, 0x5f, 0x30, 0xcb, 0x1b, 0x30, 0xcb, 0xa7, + 0x30, 0xca, 0x8e, 0x02, 0x04, 0x30, 0x3c, 0xbc, 0x74, 0x3c, 0xb6, 0x4b, + 0x3c, 0x22, 0x4e, 0x22, 0x41, 0x22, 0x5c, 0x30, 0x60, 0xb6, 0x4b, 0x60, + 0xbc, 0x74, 0x60, 0x3e, 0x4e, 0x3e, 0x5a, 0x3e, 0x41, 0x0f, 0x0a, 0x00, + 0x01, 0x00, 0x10, 0x01, 0x17, 0x84, 0x00, 0x04, 0x0a, 0x04, 0x01, 0x00, + 0x12, 0x3f, 0xaf, 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xb0, + 0x19, 0x43, 0x01, 0xd6, 0x43, 0x01, 0x7d, 0x01, 0x17, 0x85, 0x00, 0x04, + 0x0a, 0x03, 0x01, 0x00, 0x12, 0x3f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3f, 0xa0, 0x48, 0x41, 0xff, 0xfb, 0x42, 0xfb, 0x88, 0x01, + 0x17, 0x82, 0x00, 0x04, 0x0a, 0x01, 0x01, 0x00, 0x02, 0x3f, 0x77, 0x77, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x77, 0x77, 0x44, 0x22, 0x22, + 0x44, 0x22, 0x22, 0x0a, 0x08, 0x01, 0x01, 0x12, 0x3f, 0x62, 0x76, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x62, 0x76, 0x44, 0x76, 0x27, 0xca, + 0x10, 0x00, 0x01, 0x17, 0x81, 0x00, 0x04, 0x0a, 0x05, 0x01, 0x01, 0x02, + 0x3f, 0x56, 0x9f, 0xb1, 0x54, 0xf4, 0x31, 0x54, 0xf4, 0x3f, 0x56, 0x9f, + 0x44, 0x7a, 0x31, 0xca, 0x03, 0x0c, 0x0a, 0x06, 0x01, 0x02, 0x30, 0x20, + 0x22, 0x01, 0x15, 0x80, 0x00, 0x04, 0x0a, 0x07, 0x01, 0x02, 0x12, 0x3f, + 0x3e, 0x45, 0xbe, 0x57, 0x59, 0x3e, 0x57, 0x59, 0x3f, 0x3e, 0x45, 0xc6, + 0xd2, 0x50, 0x49, 0x3a, 0x4c, 0x01, 0x15, 0x80, 0x00, 0x04, 0x0a, 0x06, + 0x01, 0x02, 0x12, 0x3e, 0xe5, 0x49, 0x3e, 0xc2, 0x73, 0xbe, 0xc2, 0x73, + 0x3e, 0xe5, 0x49, 0x49, 0xcc, 0x6e, 0xc6, 0xfe, 0xad, 0x01, 0x15, 0x80, + 0x00, 0x04, 0x0a, 0x06, 0x01, 0x02, 0x12, 0x3c, 0x90, 0x42, 0x3f, 0xca, + 0x00, 0xbf, 0xca, 0x00, 0x3c, 0x90, 0x42, 0x4b, 0x27, 0x4e, 0xc6, 0x7a, + 0x92, 0x01, 0x15, 0x80, 0x00, 0x04, 0x0a, 0x07, 0x01, 0x02, 0x12, 0x3c, + 0x77, 0x91, 0xbf, 0xce, 0x17, 0x3f, 0xce, 0x17, 0x3c, 0x77, 0x91, 0xc4, + 0xf4, 0xbd, 0x4b, 0x40, 0x03, 0x01, 0x15, 0x80, 0x00, 0x04, 0x0a, 0x0b, + 0x01, 0x05, 0x20, 0x30, 0x0d, 0x0a, 0x09, 0x02, 0x04, 0x03, 0x38, 0x30, + 0x0d, 0x15, 0xff, 0x01, 0x17, 0x83, 0x00, 0x04, 0x0a, 0x09, 0x02, 0x03, + 0x04, 0x38, 0x30, 0x0d, 0x00, 0x15, 0x01, 0x17, 0x86, 0x00, 0x04, 0x0a, + 0x0a, 0x02, 0x04, 0x03, 0x20, 0x30, 0x0d +}; + +} + +#endif /* _UnknownDeviceIcons_h */ diff --git a/src/tests/kits/midi/Jamfile b/src/tests/kits/midi/Jamfile index 485c5c8dad..88d119c20d 100644 --- a/src/tests/kits/midi/Jamfile +++ b/src/tests/kits/midi/Jamfile @@ -5,5 +5,5 @@ SubDir HAIKU_TOP src tests kits midi ; #SubInclude HAIKU_TOP src tests kits midi midi_player ; #SubInclude HAIKU_TOP src tests kits midi midi_player_replacement ; #SubInclude HAIKU_TOP src tests kits midi synth_file_reader ; -SubInclude HAIKU_TOP src tests kits midi patchbay ; +#SubInclude HAIKU_TOP src tests kits midi patchbay ; diff --git a/src/tests/kits/midi/patchbay/CountEventConsumer.h b/src/tests/kits/midi/patchbay/CountEventConsumer.h deleted file mode 100644 index 553c1e06f1..0000000000 --- a/src/tests/kits/midi/patchbay/CountEventConsumer.h +++ /dev/null @@ -1,30 +0,0 @@ -// CountEventConsumer.h -// -------------------- -// A simple MIDI consumer that counts incoming MIDI events. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#ifndef _CountEventConsumer_h -#define _CountEventConsumer_h - -#include -#include - -class CountEventConsumer : public BMidiLocalConsumer -{ -public: - CountEventConsumer(const char* name) - : BMidiLocalConsumer(name), m_eventCount(0) - {} - void Reset() { m_eventCount = 0; } - int32 CountEvents() { return m_eventCount; } - - void Data(uchar*, size_t, bool, bigtime_t) - { atomic_add(&m_eventCount, 1); } - -private: - int32 m_eventCount; -}; - -#endif /* _CountEventConsumer_h */ diff --git a/src/tests/kits/midi/patchbay/MidiEventMeter.h b/src/tests/kits/midi/patchbay/MidiEventMeter.h deleted file mode 100644 index b154d05c18..0000000000 --- a/src/tests/kits/midi/patchbay/MidiEventMeter.h +++ /dev/null @@ -1,36 +0,0 @@ -// MidiEventMeter.h -// ---------------- -// A UI widget that measures the amount of MIDI data generated by a -// consumer. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#ifndef _MidiEventMeter_h -#define _MidiEventMeter_h - -#include -#include - -class BMidiProducer; -class CountEventConsumer; -class BView; - -class MidiEventMeter -{ -public: - MidiEventMeter(int32 producerID); - ~MidiEventMeter(); - - void Pulse(BView* view); - BRect Bounds() const; - void Draw(BView* view); - -private: - int32 CalcMeterLevel(int32 eventCount) const; - - CountEventConsumer* m_counter; - int32 m_meterLevel; -}; - -#endif /* _MidiMeterWidget_h */ diff --git a/src/tests/kits/midi/patchbay/PatchApp.cpp b/src/tests/kits/midi/patchbay/PatchApp.cpp deleted file mode 100644 index ebe42eab2e..0000000000 --- a/src/tests/kits/midi/patchbay/PatchApp.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// PatchApp.cpp -// ------------ -// Implements the PatchBay application class and main(). -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#include -#include "PatchApp.h" -#include "PatchWin.h" -#include "TToolTip.h" - -PatchApp::PatchApp() - : BApplication("application/x-vnd.Be-DTS.PatchBay"), m_toolTip(NULL) -{ - m_toolTip = new TToolTip; -} - -void PatchApp::ReadyToRun() -{ - new PatchWin; -} - -void PatchApp::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case B_SOME_APP_ACTIVATED: - case eToolTipStart: - case eToolTipStop: - if (m_toolTip) m_toolTip->PostMessage(msg); - break; - default: - BApplication::MessageReceived(msg); - break; - } -} - -int main() -{ - PatchApp app; - app.Run(); - return 0; -} - diff --git a/src/tests/kits/midi/patchbay/PatchApp.h b/src/tests/kits/midi/patchbay/PatchApp.h deleted file mode 100644 index b4537a18c1..0000000000 --- a/src/tests/kits/midi/patchbay/PatchApp.h +++ /dev/null @@ -1,26 +0,0 @@ -// PatchApp.h -// ---------- -// The PatchBay application class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#ifndef _PatchApp_h -#define _PatchApp_h - -#include - -class TToolTip; - -class PatchApp : public BApplication -{ -public: - PatchApp(); - void ReadyToRun(); - void MessageReceived(BMessage* msg); - -private: - TToolTip* m_toolTip; -}; - -#endif /* _PatchApp_h */ diff --git a/src/tests/kits/midi/patchbay/PatchBay.rsrc b/src/tests/kits/midi/patchbay/PatchBay.rsrc deleted file mode 100644 index 1fecbbae19ad01d276b85a22a5cae941b62e6418..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2861 zcmeHJPfHs?9Q`>fEd+{x@Duc|(yO;D*(?EV7FPsMl3GEbSdk$1mZ;b?wJpSmCN-sE zDFp-SN!uQT-Rfn*&mi6kg?@zTd%J492^McVurKfJyx*J2@PnOUS429qsdoIN_&fmI zVX#(E``d^zrrILT*BXQG?}M)dTYe)FNo<7gQ<1Mj}%=iuK|Buen}zg~^|+#A=3 z^P`iF&mlgCxCi1Mhzw#VR)g=?0c5ZO8Ek=hd&mnmDQldlgLy~r1r17;1+Q=KJ$EQG#E#|jNK7m14kR6C z+|AhGRf_Fv+iqy#jjl7Yq%(uo_{f-Jx!0~y$4N4T_s*_X(5N-+X0lJOZRtxJ?}QyK QTY4~Qx3a3ca|4){e+oLnMgRZ+ diff --git a/src/tests/kits/midi/patchbay/PatchView.cpp b/src/tests/kits/midi/patchbay/PatchView.cpp deleted file mode 100644 index 8235577f89..0000000000 --- a/src/tests/kits/midi/patchbay/PatchView.cpp +++ /dev/null @@ -1,462 +0,0 @@ -// PatchView.cpp -// ------------- -// Implements the main PatchBay view class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#include -#include -#include -#include -#include -#include -#include -#include -#include "EndpointInfo.h" -#include "PatchView.h" -#include "PatchRow.h" -#include "TToolTip.h" -#include "UnknownDeviceIcons.h" - -PatchView::PatchView(BRect r) - : BView(r, "PatchView", B_FOLLOW_ALL, B_WILL_DRAW), - m_unknownDeviceIcon(NULL), m_trackIndex(-1), m_trackType(TRACK_COLUMN) -{ - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - uint8 iconSize; - const uint8* iconData; - - if (DISPLAY_ICON_SIZE == B_LARGE_ICON) { - iconSize = LARGE_ICON_SIZE; - iconData = UnknownDevice::kLargeIconBits; - } else { - iconSize = MINI_ICON_SIZE; - iconData = UnknownDevice::kMiniIconBits; - } - - BRect iconFrame(0, 0, iconSize-1, iconSize-1); - m_unknownDeviceIcon = new BBitmap(iconFrame, ICON_COLOR_SPACE); - memcpy(m_unknownDeviceIcon->Bits(), iconData, m_unknownDeviceIcon->BitsLength()); -} - -PatchView::~PatchView() -{ - delete m_unknownDeviceIcon; -} - -void PatchView::AttachedToWindow() -{ - BMidiRoster* roster = BMidiRoster::MidiRoster(); - if (! roster) { - PRINT(("Couldn't get MIDI roster\n")); - be_app->PostMessage(B_QUIT_REQUESTED); - return; - } - - BMessenger msgr(this); - roster->StartWatching(&msgr); -} - -void PatchView::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case B_MIDI_EVENT: - HandleMidiEvent(msg); - break; - default: - BView::MessageReceived(msg); - break; - } -} - -void PatchView::MouseMoved(BPoint pt, uint32 transit, const BMessage* /* dragMsg */) -{ - if (transit == B_EXITED_VIEW || transit == B_OUTSIDE_VIEW) { - StopTipTracking(); - return; - } - - bool found = false; - int32 size = m_consumers.size(); - for (int32 i=0; (! found) && iFindEndpoint(i->ID()); - if (! obj) - return; - - BString str; - str << "<" << obj->ID() << ">: " << obj->Name(); - obj->Release(); - StartTip(pt, rect, str.String()); -} - -void PatchView::StartTip(BPoint pt, BRect rect, const char* str) -{ - BMessage msg(eToolTipStart); - msg.AddPoint("start", ConvertToScreen(pt)); - msg.AddRect("bounds", ConvertToScreen(rect)); - msg.AddString("string", str); - be_app->PostMessage(&msg); -} - -void PatchView::StopTip() -{ - be_app->PostMessage(eToolTipStop); -} - -void PatchView::Draw(BRect /* updateRect */) -{ - // draw producer icons - SetDrawingMode(B_OP_OVER); - int32 index = 0; - for (list::const_iterator i = m_producers.begin(); i != m_producers.end(); i++) { - const BBitmap* bitmap = (i->Icon()) ? i->Icon() : m_unknownDeviceIcon; - DrawBitmapAsync(bitmap, RowIconFrameAt(index++).LeftTop()); - } - - // draw consumer icons - index = 0; - for (list::const_iterator i = m_consumers.begin(); i != m_consumers.end(); i++) { - const BBitmap* bitmap = (i->Icon()) ? i->Icon() : m_unknownDeviceIcon; - DrawBitmapAsync(bitmap, ColumnIconFrameAt(index++).LeftTop()); - } -} - -BRect PatchView::ColumnIconFrameAt(int32 index) const -{ - BRect r; - r.left = ROW_LEFT + METER_PADDING + index*COLUMN_WIDTH; - r.top = 10; - r.right = r.left + 31; - r.bottom = r.top + 31; - return r; -} - -BRect PatchView::RowIconFrameAt(int32 index) const -{ - BRect r; - r.left = 10; - r.top = ROW_TOP + index*ROW_HEIGHT; - r.right = r.left + 31; - r.bottom = r.top + 31; - return r; -} - -void PatchView::HandleMidiEvent(BMessage* msg) -{ - SET_DEBUG_ENABLED(true); - - int32 op; - if (msg->FindInt32("be:op", &op) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"op\" field not found\n")); - return; - } - - switch (op) { - case B_MIDI_REGISTERED: - { - int32 id; - if (msg->FindInt32("be:id", &id) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:id\" field not found in B_MIDI_REGISTERED event\n")); - break; - } - - const char* type; - if (msg->FindString("be:type", &type) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:type\" field not found in B_MIDI_REGISTERED event\n")); - break; - } - - PRINT(("MIDI Roster Event B_MIDI_REGISTERED: id=%ld, type=%s\n", id, type)); - if (! strcmp(type, "producer")) { - AddProducer(id); - } else if (! strcmp(type, "consumer")) { - AddConsumer(id); - } - } - break; - case B_MIDI_UNREGISTERED: - { - int32 id; - if (msg->FindInt32("be:id", &id) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:id\" field not found in B_MIDI_UNREGISTERED\n")); - break; - } - - const char* type; - if (msg->FindString("be:type", &type) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:type\" field not found in B_MIDI_UNREGISTERED\n")); - break; - } - - PRINT(("MIDI Roster Event B_MIDI_UNREGISTERED: id=%ld, type=%s\n", id, type)); - if (! strcmp(type, "producer")) { - RemoveProducer(id); - } else if (! strcmp(type, "consumer")) { - RemoveConsumer(id); - } - } - break; - case B_MIDI_CHANGED_PROPERTIES: - { - int32 id; - if (msg->FindInt32("be:id", &id) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:id\" field not found in B_MIDI_CHANGED_PROPERTIES\n")); - break; - } - - const char* type; - if (msg->FindString("be:type", &type) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:type\" field not found in B_MIDI_CHANGED_PROPERTIES\n")); - break; - } - - BMessage props; - if (msg->FindMessage("be:properties", &props) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:properties\" field not found in B_MIDI_CHANGED_PROPERTIES\n")); - break; - } - - PRINT(("MIDI Roster Event B_MIDI_CHANGED_PROPERTIES: id=%ld, type=%s\n", id, type)); - if (! strcmp(type, "producer")) { - UpdateProducerProps(id, &props); - } else if (! strcmp(type, "consumer")) { - UpdateConsumerProps(id, &props); - } - - } - break; - case B_MIDI_CHANGED_NAME: - case B_MIDI_CHANGED_LATENCY: - // we don't care about these - break; - case B_MIDI_CONNECTED: - { - int32 prod; - if (msg->FindInt32("be:producer", &prod) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:producer\" field not found in B_MIDI_CONNECTED\n")); - break; - } - - int32 cons; - if (msg->FindInt32("be:consumer", &cons) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:consumer\" field not found in B_MIDI_CONNECTED\n")); - break; - } - PRINT(("MIDI Roster Event B_MIDI_CONNECTED: producer=%ld, consumer=%ld\n", prod, cons)); - Connect(prod, cons); - } - break; - case B_MIDI_DISCONNECTED: - { - int32 prod; - if (msg->FindInt32("be:producer", &prod) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:producer\" field not found in B_MIDI_DISCONNECTED\n")); - break; - } - - int32 cons; - if (msg->FindInt32("be:consumer", &cons) != B_OK) { - PRINT(("PatchView::HandleMidiEvent: \"be:consumer\" field not found in B_MIDI_DISCONNECTED\n")); - break; - } - PRINT(("MIDI Roster Event B_MIDI_DISCONNECTED: producer=%ld, consumer=%ld\n", prod, cons)); - Disconnect(prod, cons); - } - break; - default: - PRINT(("PatchView::HandleMidiEvent: unknown opcode %ld\n", op)); - break; - } -} - -void PatchView::AddProducer(int32 id) -{ - EndpointInfo info(id); - m_producers.push_back(info); - - Window()->BeginViewTransaction(); - PatchRow* row = new PatchRow(id); - m_patchRows.push_back(row); - BPoint p1 = CalcRowOrigin(m_patchRows.size() - 1); - BPoint p2 = CalcRowSize(); - row->MoveTo(p1); - row->ResizeTo(p2.x, p2.y); - for (list::const_iterator i = m_consumers.begin(); i != m_consumers.end(); i++) { - row->AddColumn(i->ID()); - } - AddChild(row); - Invalidate(); - Window()->EndViewTransaction(); -} - -void PatchView::AddConsumer(int32 id) -{ - EndpointInfo info(id); - m_consumers.push_back(info); - - Window()->BeginViewTransaction(); - BPoint newSize = CalcRowSize(); - for (row_itor i = m_patchRows.begin(); i != m_patchRows.end(); i++) { - (*i)->AddColumn(id); - (*i)->ResizeTo(newSize.x, newSize.y - 1); - } - Invalidate(); - Window()->EndViewTransaction(); -} - -void PatchView::RemoveProducer(int32 id) -{ - for (endpoint_itor i = m_producers.begin(); i != m_producers.end(); i++) { - if (i->ID() == id) { - m_producers.erase(i); - break; - } - } - - Window()->BeginViewTransaction(); - for (row_itor i = m_patchRows.begin(); i != m_patchRows.end(); i++) { - if ((*i)->ID() == id) { - PatchRow* row = *i; - i = m_patchRows.erase(i); - RemoveChild(row); - delete row; - float moveBy = -1*CalcRowSize().y; - while (i != m_patchRows.end()) { - (*i++)->MoveBy(0, moveBy); - } - break; - } - } - Invalidate(); - Window()->EndViewTransaction(); -} - -void PatchView::RemoveConsumer(int32 id) -{ - Window()->BeginViewTransaction(); - for (endpoint_itor i = m_consumers.begin(); i != m_consumers.end(); i++) { - if (i->ID() == id) { - m_consumers.erase(i); - break; - } - } - - BPoint newSize = CalcRowSize(); - for (row_itor i = m_patchRows.begin(); i != m_patchRows.end(); i++) { - (*i)->RemoveColumn(id); - (*i)->ResizeTo(newSize.x, newSize.y - 1); - } - Invalidate(); - Window()->EndViewTransaction(); -} - -void PatchView::UpdateProducerProps(int32 id, const BMessage* props) -{ - for (endpoint_itor i = m_producers.begin(); i != m_producers.end(); i++) { - if (i->ID() == id) { - i->UpdateProperties(props); - Invalidate(); - break; - } - } -} - -void PatchView::UpdateConsumerProps(int32 id, const BMessage* props) -{ - for (endpoint_itor i = m_consumers.begin(); i != m_consumers.end(); i++) { - if (i->ID() == id) { - i->UpdateProperties(props); - Invalidate(); - break; - } - } -} - -void PatchView::Connect(int32 prod, int32 cons) -{ - for (row_itor i = m_patchRows.begin(); i != m_patchRows.end(); i++) { - if ((*i)->ID() == prod) { - (*i)->Connect(cons); - break; - } - } -} - -void PatchView::Disconnect(int32 prod, int32 cons) -{ - for (row_itor i = m_patchRows.begin(); i != m_patchRows.end(); i++) { - if ((*i)->ID() == prod) { - (*i)->Disconnect(cons); - break; - } - } -} - -BPoint PatchView::CalcRowOrigin(int32 rowIndex) const -{ - BPoint pt; - pt.x = ROW_LEFT; - pt.y = ROW_TOP + rowIndex*ROW_HEIGHT; - return pt; -} - -BPoint PatchView::CalcRowSize() const -{ - BPoint pt; - pt.x = METER_PADDING + m_consumers.size()*COLUMN_WIDTH; - pt.y = ROW_HEIGHT - 1; - return pt; -} diff --git a/src/tests/kits/midi/patchbay/PatchWin.cpp b/src/tests/kits/midi/patchbay/PatchWin.cpp deleted file mode 100644 index 2511b85ab8..0000000000 --- a/src/tests/kits/midi/patchbay/PatchWin.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// PatchWin.cpp -// ------------ -// Implements the main PatchBay window class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#include -#include "PatchWin.h" -#include "PatchView.h" - -PatchWin::PatchWin() - : BWindow(BRect(50,50,450,450), "Patch Bay", B_TITLED_WINDOW, 0) -{ - BRect r = Bounds(); - m_patchView = new PatchView(r); - AddChild(m_patchView); - Show(); -} - -bool PatchWin::QuitRequested() -{ - be_app->PostMessage(B_QUIT_REQUESTED); - return true; -} - diff --git a/src/tests/kits/midi/patchbay/PatchWin.h b/src/tests/kits/midi/patchbay/PatchWin.h deleted file mode 100644 index a7ab58ed63..0000000000 --- a/src/tests/kits/midi/patchbay/PatchWin.h +++ /dev/null @@ -1,24 +0,0 @@ -// PatchWin.h -// ---------- -// The main PatchBay window class. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#ifndef _PatchWin_h -#define _PatchWin_h - -#include - -class PatchView; - -class PatchWin : public BWindow -{ -public: - PatchWin(); - bool QuitRequested(); -private: - PatchView* m_patchView; -}; - -#endif /* _PatchWin_h */ diff --git a/src/tests/kits/midi/patchbay/TToolTip.cpp b/src/tests/kits/midi/patchbay/TToolTip.cpp deleted file mode 100644 index 17ee1ca82c..0000000000 --- a/src/tests/kits/midi/patchbay/TToolTip.cpp +++ /dev/null @@ -1,357 +0,0 @@ -//-------------------------------------------------------------------- -// -// TToolTip.cpp -// -// Written by: Robert Polic -// -//-------------------------------------------------------------------- - -#include -#include -#include -#include - -#include -#include - -#include "TToolTip.h" - -#define kHOR_MARGIN 4 // hor. gap between frame and tip -#define kVER_MARGIN 3 // ver. gap between frame and tip -#define kTIP_HOR_OFFSET 10 // tip position right of cursor -#define kTIP_VER_OFFSET 16 // tip position below cursor -#define kSLOP 4 // mouse slop before tip hides - -#define kTOOL_TIP_DELAY_TIME 500000 // default delay time before tip shows (.5 secs.) -#define kTOOL_TIP_HOLD_TIME 3000000 // default hold time of time (3 secs.) - -#define kDRAW_WINDOW_FRAME - -const rgb_color kVIEW_COLOR = {255, 203, 0, 255}; // view background color (light yellow) -const rgb_color kLIGHT_VIEW_COLOR = {255, 255, 80, 255}; // top left frame highlight -const rgb_color kDARK_VIEW_COLOR = {175, 123, 0, 255}; // bottom right frame highlight -const rgb_color kTEXT_COLOR = {0, 0, 0, 255}; // text color (black) - - -//==================================================================== - -TToolTip::TToolTip(tool_tip_settings *settings) - :BWindow(BRect(0, 0, 10, 10), "tool_tip", B_NO_BORDER_WINDOW_LOOK, - B_FLOATING_ALL_WINDOW_FEEL, B_AVOID_FRONT) -{ - // setup the tooltip view - AddChild(fView = new TToolTipView(settings)); - // start the message loop thread - Run(); -} - -//-------------------------------------------------------------------- - -void TToolTip::MessageReceived(BMessage *msg) -{ - switch (msg->what) { - // forward interesting messages to the view - case B_SOME_APP_ACTIVATED: - case eToolTipStart: - case eToolTipStop: - PostMessage(msg, fView); - break; - default: - BWindow::MessageReceived(msg); - } -} - -//-------------------------------------------------------------------- - -void TToolTip::GetSettings(tool_tip_settings *settings) -{ - fView->GetSettings(settings); -} - -//-------------------------------------------------------------------- - -void TToolTip::SetSettings(tool_tip_settings *settings) -{ - fView->SetSettings(settings); -} - - -//==================================================================== - -TToolTipView::TToolTipView(tool_tip_settings *settings) - :BView(BRect(0, 0, 10, 10), "tool_tip", B_FOLLOW_ALL, B_WILL_DRAW) -{ - // initialize tooltip settings - if (settings) - // we should probably sanity-check user defined settings (but we won't) - fTip.settings = *settings; - else { - // use defaults if no settings are passed - fTip.settings.enabled = true; - fTip.settings.one_time_only = false; - fTip.settings.delay = kTOOL_TIP_DELAY_TIME; - fTip.settings.hold = kTOOL_TIP_HOLD_TIME; - fTip.settings.font = be_plain_font; - } - - // initialize the tip - fString = (char *)malloc(1); - fString[0] = 0; - - // initialize the view - SetFont(&fTip.settings.font); - SetViewColor(kVIEW_COLOR); -} - -//-------------------------------------------------------------------- - -TToolTipView::~TToolTipView() -{ - status_t status; - - // kill tool_tip thread - fTip.quit = true; - wait_for_thread(fThread, &status); - - // free tip - free(fString); -} - -//-------------------------------------------------------------------- - -void TToolTipView::AllAttached() -{ - // initialize internal settings - fTip.app_active = true; - fTip.quit = false; - fTip.stopped = true; - - fTip.tool_tip_view = this; - fTip.tool_tip_window = Window(); - - // start tool_tip thread - resume_thread(fThread = spawn_thread((status_t (*)(void *)) ToolTipThread, - "tip_thread", B_DISPLAY_PRIORITY, &fTip)); -} - -//-------------------------------------------------------------------- - -void TToolTipView::Draw(BRect /* where */) -{ - char *src_strings[1]; - char *tmp_string; - char *truncated_strings[1]; - BFont font; - BRect r = Bounds(); - font_height finfo; - - // draw border around window -#ifdef kDRAW_WINDOW_FRAME - SetHighColor(0, 0, 0, 255); - StrokeRect(r); - r.InsetBy(1, 1); -#endif - SetHighColor(kLIGHT_VIEW_COLOR); - StrokeLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top)); - StrokeLine(BPoint(r.left + 1, r.top), BPoint(r.right - 1, r.top)); - SetHighColor(kDARK_VIEW_COLOR); - StrokeLine(BPoint(r.right, r.top), BPoint(r.right, r.bottom)); - StrokeLine(BPoint(r.right - 1, r.bottom), BPoint(r.left + 1, r.bottom)); - - // set pen position - GetFont(&font); - font.GetHeight(&finfo); - MovePenTo(kHOR_MARGIN + 1, kVER_MARGIN + finfo.ascent); - - // truncate string if needed - src_strings[0] = fString; - tmp_string = (char *)malloc(strlen(fString) + 16); - truncated_strings[0] = tmp_string; - font.GetTruncatedStrings((const char **)src_strings, 1, B_TRUNCATE_END, - Bounds().Width() - (2 * kHOR_MARGIN) + 1, truncated_strings); - - // draw string - SetLowColor(kVIEW_COLOR); - SetHighColor(kTEXT_COLOR); - DrawString(tmp_string); - free(tmp_string); -} - -//-------------------------------------------------------------------- - -void TToolTipView::MessageReceived(BMessage *msg) -{ - switch (msg->what) { - case B_SOME_APP_ACTIVATED: - msg->FindBool("active", &fTip.app_active); - break; - - case eToolTipStart: - { - const char *str; - - // extract parameters - msg->FindPoint("start", &fTip.start); - msg->FindRect("bounds", &fTip.bounds); - msg->FindString("string", &str); - free(fString); - fString = (char *)malloc(strlen(str) + 1); - strcpy(fString, str); - - // force window to fit new parameters - AdjustWindow(); - - // flag thread to reset - fTip.reset = true; - } - break; - - case eToolTipStop: - // flag thread to stop - fTip.stop = true; - break; - } -} - -//-------------------------------------------------------------------- - -void TToolTipView::GetSettings(tool_tip_settings *settings) -{ - // return current settings - *settings = fTip.settings; -} - -//-------------------------------------------------------------------- - -void TToolTipView::SetSettings(tool_tip_settings *settings) -{ - bool invalidate = fTip.settings.font != settings->font; - - // we should probably sanity-check user defined settings (but we won't) - fTip.settings = *settings; - - // if the font changed, adjust window to fit - if (invalidate) { - Window()->Lock(); - SetFont(&fTip.settings.font); - AdjustWindow(); - Window()->Unlock(); - } -} - -//-------------------------------------------------------------------- - -void TToolTipView::AdjustWindow() -{ - float width; - float height; - float x; - float y; - BScreen s(B_MAIN_SCREEN_ID); - BRect screen = s.Frame(); - BWindow *wind = Window(); - font_height finfo; - - screen.InsetBy(2, 2); // we want a 2-pixel clearance - fTip.settings.font.GetHeight(&finfo); - width = fTip.settings.font.StringWidth(fString) + (kHOR_MARGIN * 2); // string width - height = (finfo.ascent + finfo.descent + finfo.leading) + (kVER_MARGIN * 2); // string height - - // calculate new position and size of window - x = fTip.start.x + kTIP_HOR_OFFSET; - if ((x + width) > screen.right) - x = screen.right - width; - y = fTip.start.y + kTIP_VER_OFFSET; - if ((y + height) > screen.bottom) { - y = screen.bottom - height; - if ((fTip.start.y >= (y - kSLOP)) && (fTip.start.y <= (y + height))) - y = fTip.start.y - kTIP_VER_OFFSET - height; - } - if (x < screen.left) { - width -= screen.left - x; - x = screen.left; - } - if (y < screen.top) { - height -= screen.top - y; - y = screen.top; - } - - wind->MoveTo((int)x, (int)y); - wind->ResizeTo((int)width, (int)height); - - // force an update - Invalidate(Bounds()); -} - -//-------------------------------------------------------------------- - -status_t TToolTipView::ToolTipThread(tool_tip *tip) -{ - uint32 buttons; - BPoint where; - BScreen s(B_MAIN_SCREEN_ID); - BRect screen = s.Frame(); - - screen.InsetBy(2, 2); - while (!tip->quit) { - if (tip->tool_tip_window->LockWithTimeout(0) == B_NO_ERROR) { - tip->tool_tip_view->GetMouse(&where, &buttons); - tip->tool_tip_view->ConvertToScreen(&where); - - tip->stopped = tip->stop; - if (tip->reset) { - if (tip->showing) - tip->tool_tip_window->Hide(); - tip->stop = false; - tip->stopped = false; - tip->reset = false; - tip->shown = false; - tip->showing = false; - tip->start_time = system_time() + tip->settings.delay; - } - else if (tip->showing) { - if ((tip->stop) || - (!tip->settings.enabled) || - (!tip->app_active) || - (!tip->bounds.Contains(where)) || - (tip->expire_time < system_time()) || - (abs((int)tip->start.x - (int)where.x) > kSLOP) || - (abs((int)tip->start.y - (int)where.y) > kSLOP) || - (buttons)) { - tip->tool_tip_window->Hide(); - tip->shown = tip->settings.one_time_only; - tip->showing = false; - tip->tip_timed_out = (tip->expire_time < system_time()); - tip->start_time = system_time() + tip->settings.delay; - } - } - else if ((tip->settings.enabled) && - (!tip->stopped) && - (tip->app_active) && - (!tip->shown) && - (!tip->tip_timed_out) && - (!buttons) && - (tip->bounds.Contains(where)) && - (tip->start_time < system_time())) { - tip->start = where; - tip->tool_tip_view->AdjustWindow(); - tip->tool_tip_window->Show(); - tip->tool_tip_window->Activate(false); - tip->showing = true; - tip->expire_time = system_time() + tip->settings.hold; - tip->start = where; - } - else if ((abs((int)tip->start.x - (int)where.x) > kSLOP) || - (abs((int)tip->start.y - (int)where.y) > kSLOP)) { - tip->start = where; - tip->start_time = system_time() + tip->settings.delay; - tip->tip_timed_out = false; - } - if (buttons) - tip->start_time = system_time() + tip->settings.delay; - tip->tool_tip_window->Unlock(); - } - snooze(50000); - } - return B_NO_ERROR; -} \ No newline at end of file diff --git a/src/tests/kits/midi/patchbay/TToolTip.h b/src/tests/kits/midi/patchbay/TToolTip.h deleted file mode 100644 index 1288d55455..0000000000 --- a/src/tests/kits/midi/patchbay/TToolTip.h +++ /dev/null @@ -1,86 +0,0 @@ -//-------------------------------------------------------------------- -// -// TToolTip.h -// -// Written by: Robert Polic -// -//-------------------------------------------------------------------- - -#ifndef T_TOOL_TIPS_H -#define T_TOOL_TIPS_H - -#include -#include -#include - -enum TOOL_TIP_MESSAGES {eToolTipStart = 'ttGo', - eToolTipStop = 'ttSp'}; - -// ui settings -struct tool_tip_settings { - bool enabled; // flag whether tips are enables or not - bool one_time_only; // flag to only display the tip once per time in view - bigtime_t delay; // delay before tip is shown in microseconds - bigtime_t hold; // amount of time tip is displayed in microseconds - BFont font; // font tip is drawn in -}; - -// internal settings -struct tool_tip { - bool app_active; - bool quit; - bool stop; - bool stopped; - bool reset; - bool shown; - bool showing; - bool tip_timed_out; - BPoint start; - BRect bounds; - class TToolTipView *tool_tip_view; - BWindow *tool_tip_window; - bigtime_t start_time; - bigtime_t expire_time; - tool_tip_settings settings; -}; - - -//==================================================================== - -class TToolTip : public BWindow { - -public: - TToolTip(tool_tip_settings *settings = NULL); - virtual void MessageReceived(BMessage*); - - void GetSettings(tool_tip_settings*); - void SetSettings(tool_tip_settings*); - -private: - class TToolTipView *fView; -}; - - -//==================================================================== - -class TToolTipView : public BView { - -public: - TToolTipView(tool_tip_settings *settings = NULL); - ~TToolTipView(); - virtual void AllAttached(); - virtual void Draw(BRect); - virtual void MessageReceived(BMessage*); - - void GetSettings(tool_tip_settings*); - void SetSettings(tool_tip_settings*); - -private: - void AdjustWindow(); - static status_t ToolTipThread(tool_tip*); - - char *fString; - thread_id fThread; - tool_tip fTip; -}; -#endif diff --git a/src/tests/kits/midi/patchbay/UnknownDeviceIcons.h b/src/tests/kits/midi/patchbay/UnknownDeviceIcons.h deleted file mode 100644 index 27efec70eb..0000000000 --- a/src/tests/kits/midi/patchbay/UnknownDeviceIcons.h +++ /dev/null @@ -1,106 +0,0 @@ -// UnknownDeviceIcons.h -// -------------------- -// The icons to be used in case a device doesn't supply its icons. -// In the future, this could be better selected if the device supported -// other descriptive property fields. -// -// Large and mini versions are available. PatchBay currently uses the -// large version. -// -// Copyright 1999, Be Incorporated. All Rights Reserved. -// This file may be used under the terms of the Be Sample Code License. - -#ifndef _UnknownDeviceIcons_h -#define _UnknownDeviceIcons_h - -namespace UnknownDevice { - -const unsigned char kLargeIconBits [] = { - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, - 0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0xff, - 0xff,0xff,0xff,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08, - 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0c,0x0c, - 0xff,0xff,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04, - 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x08,0x08,0x0c, - 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0d,0x04,0x00,0x00,0x04, - 0x0d,0x1b,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x16,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x12,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x16,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0d,0x00,0x00,0x00,0x0d,0x1b,0x3f,0x16, - 0x04,0x00,0x00,0x09,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x04,0x00,0x00,0x0d,0x3f,0x3f,0x3f,0x3f, - 0x16,0x00,0x00,0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x1b,0x3f,0x3f,0x3f,0x3f, - 0x1b,0x00,0x00,0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x1b, - 0x04,0x00,0x00,0x04,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0d,0x00, - 0x00,0x00,0x00,0x16,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x1b,0x00,0x00,0x00, - 0x00,0x0d,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x04,0x00,0x00,0x09, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x3f, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x00, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x00, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x00, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0x08,0xff, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0x00,0x00, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x04,0xff,0xff, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, - 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff, - 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff -}; - -const unsigned char kMiniIconBits [] = { - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0xff, - 0xff,0xff,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0c,0x0c, - 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x16,0x00,0x00,0x00,0x1b,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x00,0x16,0x3f,0x1b,0x00,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x1b,0x00,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x09,0x00,0x1b,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x1b,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0x0c, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0x08,0xff, - 0x00,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff, - 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff -}; - -} - -#endif /* _UnknownDeviceIcons_h */