2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <sigc++/signal.h>
23 #include "pbd/pthread_utils.h"
25 #include "ardour/async_midi_port.h"
26 #include "ardour/debug.h"
27 #include "ardour/audioengine.h"
28 #include "ardour/midi_port.h"
29 #include "ardour/midiport_manager.h"
30 #include "ardour/midi_ui.h"
31 #include "ardour/session.h"
32 #include "ardour/session_event.h"
33 #include "ardour/types.h"
36 using namespace ARDOUR;
42 MidiControlUI* MidiControlUI::_instance = 0;
44 #include "pbd/abstract_ui.cc" /* instantiate the template */
46 MidiControlUI::MidiControlUI (Session& s)
47 : AbstractUI<MidiUIRequest> (X_("midiUI"))
53 MidiControlUI::~MidiControlUI ()
57 /* drop all ports as GIO::Sources */
59 /* we no longer exist */
64 MidiControlUI::request_factory (uint32_t num_requests)
66 /* AbstractUI<T>::request_buffer_factory() is a template method only
67 instantiated in this source module. To provide something visible for
68 use when registering the factory, we have this static method that is
71 return request_buffer_factory (num_requests);
75 MidiControlUI::do_request (MidiUIRequest* req)
77 if (req->type == Quit) {
79 } else if (req->type == CallSlot) {
85 MidiControlUI::midi_input_handler (IOCondition ioc, boost::weak_ptr<AsyncMIDIPort> wport)
87 boost::shared_ptr<AsyncMIDIPort> port = wport.lock ();
92 DEBUG_TRACE (DEBUG::MidiIO, string_compose ("something happend on %1\n", boost::shared_ptr<ARDOUR::Port> (port)->name()));
101 DEBUG_TRACE (DEBUG::MidiIO, string_compose ("data available on %1\n", boost::shared_ptr<ARDOUR::Port>(port)->name()));
102 framepos_t now = _session.engine().sample_time();
110 MidiControlUI::clear_ports ()
115 MidiControlUI::reset_ports ()
117 vector<boost::shared_ptr<AsyncMIDIPort> > ports;
118 boost::shared_ptr<AsyncMIDIPort> p;
120 if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_session.midi_input_port()))) {
125 if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_session.mmc_input_port()))) {
129 if ((p = boost::dynamic_pointer_cast<AsyncMIDIPort> (_session.scene_input_port()))) {
137 for (vector<boost::shared_ptr<AsyncMIDIPort> >::const_iterator pi = ports.begin(); pi != ports.end(); ++pi) {
138 (*pi)->xthread().set_receive_handler (sigc::bind (
139 sigc::mem_fun (this, &MidiControlUI::midi_input_handler), boost::weak_ptr<AsyncMIDIPort>(*pi)));
140 (*pi)->xthread().attach (_main_loop->get_context());
145 MidiControlUI::thread_init ()
147 struct sched_param rtparam;
149 pthread_set_name (X_("midiUI"));
151 PBD::notify_event_loops_about_thread_creation (pthread_self(), X_("midiUI"), 2048);
152 SessionEvent::create_per_thread_pool (X_("midiUI"), 128);
154 memset (&rtparam, 0, sizeof (rtparam));
155 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
157 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
158 // do we care? not particularly.