From e392b271d5e7b86a8dd41b5ffda99813537d50f9 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 8 Jun 2012 19:12:06 +0000 Subject: [PATCH] get soundgrid initialization running in its own thread, with a hand-holding GUI pulsing progress bar, and make first call into mixer core to get LAN id's git-svn-id: svn://localhost/ardour2/branches/3.0-SG@12615 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.h | 5 - gtk2_ardour/ardour_ui2.cc | 5 - gtk2_ardour/ardour_ui_sg.mm | 52 ------- gtk2_ardour/engine_dialog.cc | 10 ++ gtk2_ardour/soundgrid.mm | 157 +++++++++++++++++++++ gtk2_ardour/wscript | 2 +- libs/ardour/ardour/soundgrid.h | 11 +- libs/ardour/{soundgrid.cc => soundgrid.mm} | 65 +++++++-- libs/ardour/wscript | 2 +- 9 files changed, 234 insertions(+), 75 deletions(-) delete mode 100644 gtk2_ardour/ardour_ui_sg.mm create mode 100644 gtk2_ardour/soundgrid.mm rename libs/ardour/{soundgrid.cc => soundgrid.mm} (72%) diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index a1c6260ccf..6e867292dc 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -713,11 +713,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr bool _feedback_exists; void resize_text_widgets (); - -#ifdef USE_SOUNDGRID - void soundgrid_init (); -#endif - }; #endif /* __ardour_gui_h__ */ diff --git a/gtk2_ardour/ardour_ui2.cc b/gtk2_ardour/ardour_ui2.cc index 32880a2f0b..b9deb1289e 100644 --- a/gtk2_ardour/ardour_ui2.cc +++ b/gtk2_ardour/ardour_ui2.cc @@ -601,11 +601,6 @@ ARDOUR_UI::editor_realized () { boost::function pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1)); Config->map_parameters (pc); - -#ifdef USE_SOUNDGRID - soundgrid_init (); -#endif - reset_dpi (); } diff --git a/gtk2_ardour/ardour_ui_sg.mm b/gtk2_ardour/ardour_ui_sg.mm deleted file mode 100644 index fbe409cca4..0000000000 --- a/gtk2_ardour/ardour_ui_sg.mm +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2012 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "ardour/soundgrid.h" - -#include "ardour_ui.h" -#include "public_editor.h" - -#ifdef __APPLE__ -#define Marker MarkerStupidApple -#include -#undef Marker - -#ifdef check -#undef check -#endif -#ifdef NO -#undef NO -#endif -#ifdef YES -#undef YES -#endif -#endif - -#ifdef USE_SOUNDGRID - -void -ARDOUR_UI::soundgrid_init () -{ -#ifdef __APPLE__ - NSView* nsview = gdk_quartz_window_get_nsview (editor->get_window()->gobj()); - ARDOUR::SoundGrid::instance().initialize (nsview); -#endif -} - -#endif diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index 0420751abf..c1f0211530 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -59,6 +59,8 @@ #endif #include "engine_dialog.h" +#include "soundgrid.h" + #include "i18n.h" using namespace std; @@ -694,6 +696,11 @@ EngineControl::enumerate_devices (const string& driver) } else if (driver == "CoreAudio") { devices[driver] = enumerate_coreaudio_devices (); } else if (driver == "SoundGrid") { + + cerr << "calling soundgrid_init()\n"; + soundgrid_init (); + cerr << "done with soundgrid_init()\n"; + devices[driver] = SoundGrid::lan_port_names (); #else @@ -913,6 +920,8 @@ EngineControl::driver_changed () string::size_type maxlen = 0; int n = 0; + cerr << "Driver has changed, now set to " << driver << endl; + enumerate_devices (driver); vector& strings = devices[driver]; @@ -928,6 +937,7 @@ EngineControl::driver_changed () } if (driver == _("SoundGrid")) { + device_label.set_text (_("LAN Port")); if (soundgrid_vbox.children().empty()) { diff --git a/gtk2_ardour/soundgrid.mm b/gtk2_ardour/soundgrid.mm new file mode 100644 index 0000000000..fb21a71d88 --- /dev/null +++ b/gtk2_ardour/soundgrid.mm @@ -0,0 +1,157 @@ +/* + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include + +#include "ardour/soundgrid.h" + +#include "ardour_ui.h" +#include "public_editor.h" + +#ifdef __APPLE__ +#define Marker MarkerStupidApple +#include +#undef Marker + +#ifdef check +#undef check +#endif +#ifdef NO +#undef NO +#endif +#ifdef YES +#undef YES +#endif +#endif + +#ifdef USE_SOUNDGRID + +#include +#include + +#include "pbd/compose.h" + +#include "ardour/debug.h" + +#include "ardour_window.h" +#include "soundgrid.h" + +using namespace PBD; +using std::cerr; + +static int sg_status = -1; + +static void sg_init () +{ + DEBUG_TRACE (PBD::DEBUG::SoundGrid, "thread starting SG init\n"); + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSWindow* window = [[NSWindow alloc] initWithContentRect:NSZeroRect + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:1]; + + ARDOUR::SoundGrid::instance().set_pool (pool); + + if (ARDOUR::SoundGrid::instance().initialize ([window contentView]) == 0) { + sg_status = 1; + } else { + sg_status = -1; + } + + cerr << "initialization done, status === " << sg_status << std::endl; +} + +#ifdef __APPLE__ + +@interface DummyThread : NSThread +{ +} +@end + +@implementation DummyThread +- (void) main +{ + printf ("dummy thread running\n"); +} +@end + +#endif + +static bool hack (sigc::slot theSlot) +{ + theSlot(); + return true; +} + +int +soundgrid_init () +{ +#ifdef __APPLE__ + /* need to ensure that Cocoa is multithreaded */ + if (![NSThread isMultiThreaded]) { + cerr << "Starting dummy thread\n"; + NSThread* dummy = [[DummyThread alloc] init]; + [dummy start]; + } else { + cerr << "Already multithreaded\n"; + } +#endif + + ArdourWindow win (_("Initializing SoundGrid")); + Gtk::Label label (_("Please wait while SoundGrid initializes")); + Gtk::VBox packer; + Gtk::ProgressBar progress; + + label.show (); + progress.show(); + packer.show (); + packer.pack_start (label); + packer.pack_start (progress); + + win.set_position (Gtk::WIN_POS_MOUSE); + win.add (packer); + win.present (); + + DEBUG_TRACE (DEBUG::SoundGrid, "Initializing SoundGrid instance\n"); + + sg_status = 0; + + Glib::Thread* thr = Glib::Thread::create (sigc::ptr_fun (sg_init)); + + Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (hack), sigc::mem_fun (progress, &Gtk::ProgressBar::pulse)), 500); + + while (sg_status == 0) { + gtk_main_iteration (); + } + + win.hide (); + + while (gtk_events_pending ()) { + gtk_main_iteration (); + } + + thr->join (); + + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("SG initialization returned %1\n", sg_status)); + return sg_status; +} + +#endif diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index a028540406..9fd1b81db8 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -39,7 +39,6 @@ gtk2_ardour_sources = [ 'ardour_ui_dialogs.cc', 'ardour_ui_ed.cc', 'ardour_ui_mixer.cc', - 'ardour_ui_sg.mm', 'ardour_ui_options.cc', 'ardour_window.cc', 'audio_clock.cc', @@ -213,6 +212,7 @@ gtk2_ardour_sources = [ 'shuttle_control.cc', 'simpleline.cc', 'simplerect.cc', + 'soundgrid.mm', 'splash.cc', 'speaker_dialog.cc', 'startup.cc', diff --git a/libs/ardour/ardour/soundgrid.h b/libs/ardour/ardour/soundgrid.h index 241e80b406..2acafd236a 100644 --- a/libs/ardour/ardour/soundgrid.h +++ b/libs/ardour/ardour/soundgrid.h @@ -69,21 +69,26 @@ class SoundGrid : public boost::noncopyable static void driver_register (const WSDCoreHandle, const WSCoreCallbackTable*, const WSMixerConfig*); + static void set_pool (void* pool); + private: SoundGrid (); static SoundGrid* _instance; void* dl_handle; void* _sg; // handle managed by SoundGrid library - WSDCoreHandle _host_handle; - const WSCoreCallbackTable* _callback_table; - const WSMixerConfig* _mixer_config; + WSDCoreHandle _host_handle; + WSCoreCallbackTable _callback_table; + WSMixerConfig _mixer_config; + void* _pool; void display_update (); static void _display_update (); static WTErr _sg_callback (const WSControlID* pControlID); static WTErr sg_callback (const WSControlID* pControlID); + + WTErr get (WSControlID*, WSControlInfo*); }; } // namespace ARDOUR diff --git a/libs/ardour/soundgrid.cc b/libs/ardour/soundgrid.mm similarity index 72% rename from libs/ardour/soundgrid.cc rename to libs/ardour/soundgrid.mm index 7a83c63a36..0839aa3cba 100644 --- a/libs/ardour/soundgrid.cc +++ b/libs/ardour/soundgrid.mm @@ -25,11 +25,15 @@ #include #include "pbd/compose.h" +#include "pbd/stacktrace.h" #include "ardour/debug.h" #include "ardour/soundgrid.h" #ifdef __APPLE__ + +#include + const char* sndgrid_dll_name = "mixerapplicationcoresg.dylib"; #else const char* sndgrid_dll_name = "mixerapplicationcoresg.so"; @@ -48,8 +52,7 @@ SoundGrid::SoundGrid () : dl_handle (0) , _sg (0) , _host_handle (0) - , _callback_table (0) - , _mixer_config (0) + , _pool (0) { const char *s; string path; @@ -86,15 +89,37 @@ SoundGrid::~SoundGrid() if (dl_handle) { dlclose (dl_handle); } + +#ifdef __APPLE__ + if (_pool) { + NSAutoreleasePool* p = (NSAutoreleasePool*) _pool; + [p release]; + _pool = 0; + } +#endif +} + +void +SoundGrid::set_pool (void* pool) +{ + instance()._pool = pool; } int SoundGrid::initialize (void* window_handle) { - WTErr ret; - DEBUG_TRACE (DEBUG::SoundGrid, "Initializing SG core...\n"); - ret = InitializeMixerCoreDLL (window_handle, sg_callback, &_sg); - DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initialized SG core, ret = %1 core handle %2\n", ret, _sg)); + if (!_sg) { + WTErr ret; + DEBUG_TRACE (DEBUG::SoundGrid, "Initializing SG core...\n"); + if ((ret = InitializeMixerCoreDLL (window_handle, sg_callback, &_sg)) != eNoErr) { + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initialized SG core, ret = %1 core handle %2\n", ret, _sg)); + return -1; + } + DEBUG_TRACE (DEBUG::SoundGrid, string_compose ("Initialized SG core, core handle %2\n", _sg)); + } else { + DEBUG_TRACE (DEBUG::SoundGrid, "SG core already initialized...\n"); + } + return 0; } @@ -127,10 +152,34 @@ SoundGrid::available () return instance().dl_handle != 0; } +int +SoundGrid::get (WSControlID* id, WSControlInfo* info) +{ + if (!_host_handle) { + return -1; + } + + if (_callback_table.getControlInfoProc (_host_handle, this, id, info) != eNoErr) { + return -1; + } + + return 0; +} + vector SoundGrid::lan_port_names () { + WTErr eRetVal; std::vector names; + + WSAudioDevicesControlInfo audioDevices; + Init_WSAudioDevicesControlInfo(&audioDevices); + eRetVal = instance().get (&audioDevices.m_controlInfo.m_controlID, (WSControlInfo*)&audioDevices); + + for (uint32_t n = 0; n < audioDevices.m_audioDevices.numberOfDevices; ++n) { + cerr << "Discovered audio device [" << audioDevices.m_audioDevices.deviceNames[n] << "]\n"; + } + names.push_back ("00:00:00:1e:af - builtin ethernet controller"); return names; } @@ -228,7 +277,7 @@ SoundGrid::driver_register (const WSDCoreHandle ch, const WSCoreCallbackTable* c { if (_instance) { _instance->_host_handle = ch; - _instance->_callback_table = ct; - _instance->_mixer_config = mc; + _instance->_callback_table = *ct; + _instance->_mixer_config = *mc; } } diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 38e1fe81ef..6ab2bffc73 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -201,7 +201,7 @@ libardour_sources = [ 'sndfile_helpers.cc', 'sndfileimportable.cc', 'sndfilesource.cc', - 'soundgrid.cc', + 'soundgrid.mm', 'source.cc', 'source_factory.cc', 'speakers.cc',