2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 1998-99 Paul Barton-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.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/error.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/types.h"
|
|
|
|
#include "midi++/manager.h"
|
|
|
|
#include "midi++/channel.h"
|
2010-07-05 20:16:36 -04:00
|
|
|
#include "midi++/port.h"
|
2012-04-23 22:28:51 -04:00
|
|
|
#include "midi++/jack_midi_port.h"
|
2010-07-08 18:55:20 -04:00
|
|
|
#include "midi++/mmc.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace MIDI;
|
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
Manager *Manager::theManager = 0;
|
|
|
|
|
2011-09-26 16:35:09 -04:00
|
|
|
Manager::Manager (jack_client_t* jack)
|
|
|
|
: _ports (new PortList)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-08 18:55:20 -04:00
|
|
|
_mmc = new MachineControl (this, jack);
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
_mtc_input_port = add_port (new MIDI::JackMIDIPort ("MTC in", Port::IsInput, jack));
|
|
|
|
_mtc_output_port = add_port (new MIDI::JackMIDIPort ("MTC out", Port::IsOutput, jack));
|
|
|
|
_midi_input_port = add_port (new MIDI::JackMIDIPort ("MIDI control in", Port::IsInput, jack));
|
|
|
|
_midi_output_port = add_port (new MIDI::JackMIDIPort ("MIDI control out", Port::IsOutput, jack));
|
|
|
|
_midi_clock_input_port = add_port (new MIDI::JackMIDIPort ("MIDI clock in", Port::IsInput, jack));
|
|
|
|
_midi_clock_output_port = add_port (new MIDI::JackMIDIPort ("MIDI clock out", Port::IsOutput, jack));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Manager::~Manager ()
|
|
|
|
{
|
2010-07-08 18:55:20 -04:00
|
|
|
delete _mmc;
|
|
|
|
|
|
|
|
/* This will delete our MTC etc. ports */
|
2011-09-26 16:35:09 -04:00
|
|
|
|
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
|
2009-11-13 14:50:39 -05:00
|
|
|
delete *p;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (theManager == this) {
|
|
|
|
theManager = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Port *
|
2010-07-06 20:40:58 -04:00
|
|
|
Manager::add_port (Port* p)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-09-26 17:03:11 -04:00
|
|
|
{
|
|
|
|
RCUWriter<PortList> writer (_ports);
|
|
|
|
boost::shared_ptr<PortList> pw = writer.get_copy ();
|
|
|
|
pw->push_back (p);
|
|
|
|
}
|
2009-12-08 22:05:14 -05:00
|
|
|
|
|
|
|
PortsChanged (); /* EMIT SIGNAL */
|
|
|
|
|
2010-07-06 20:40:58 -04:00
|
|
|
return p;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-09-26 16:35:16 -04:00
|
|
|
void
|
|
|
|
Manager::remove_port (Port* p)
|
|
|
|
{
|
2011-09-26 17:03:11 -04:00
|
|
|
{
|
|
|
|
RCUWriter<PortList> writer (_ports);
|
|
|
|
boost::shared_ptr<PortList> pw = writer.get_copy ();
|
|
|
|
pw->remove (p);
|
|
|
|
}
|
2011-09-26 16:35:16 -04:00
|
|
|
|
|
|
|
PortsChanged (); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2010-12-03 17:26:29 -05:00
|
|
|
Manager::cycle_start (pframes_t nframes)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
|
|
|
for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
|
2009-11-13 14:50:39 -05:00
|
|
|
(*p)->cycle_start (nframes);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Manager::cycle_end()
|
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
|
|
|
for (PortList::iterator p = pr->begin(); p != pr->end(); ++p) {
|
2009-11-13 14:50:39 -05:00
|
|
|
(*p)->cycle_end ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 11:41:05 -04:00
|
|
|
/** Re-register ports that disappear on JACK shutdown */
|
|
|
|
void
|
2010-07-08 18:55:20 -04:00
|
|
|
Manager::reestablish (jack_client_t* jack)
|
2010-07-05 11:41:05 -04:00
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
|
|
|
for (PortList::const_iterator p = pr->begin(); p != pr->end(); ++p) {
|
2012-04-23 22:28:51 -04:00
|
|
|
JackMIDIPort* pp = dynamic_cast<JackMIDIPort*> (*p);
|
|
|
|
if (pp) {
|
|
|
|
pp->reestablish (jack);
|
|
|
|
}
|
2010-07-05 11:41:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Re-connect ports after a reestablish () */
|
|
|
|
void
|
|
|
|
Manager::reconnect ()
|
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
|
|
|
for (PortList::const_iterator p = pr->begin(); p != pr->end(); ++p) {
|
2012-04-23 22:28:51 -04:00
|
|
|
JackMIDIPort* pp = dynamic_cast<JackMIDIPort*> (*p);
|
|
|
|
if (pp) {
|
|
|
|
pp->reconnect ();
|
|
|
|
}
|
2010-07-05 11:41:05 -04:00
|
|
|
}
|
|
|
|
}
|
2010-07-06 20:40:58 -04:00
|
|
|
|
|
|
|
Port*
|
|
|
|
Manager::port (string const & n)
|
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
|
|
|
PortList::const_iterator p = pr->begin();
|
|
|
|
while (p != pr->end() && (*p)->name() != n) {
|
2010-07-06 20:40:58 -04:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
2011-09-26 16:35:09 -04:00
|
|
|
if (p == pr->end()) {
|
2010-07-06 20:40:58 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *p;
|
|
|
|
}
|
2010-07-08 18:55:20 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Manager::create (jack_client_t* jack)
|
|
|
|
{
|
|
|
|
assert (theManager == 0);
|
|
|
|
theManager = new Manager (jack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Manager::set_port_states (list<XMLNode*> s)
|
|
|
|
{
|
2011-09-26 16:35:09 -04:00
|
|
|
boost::shared_ptr<PortList> pr = _ports.reader ();
|
|
|
|
|
2010-07-08 18:55:20 -04:00
|
|
|
for (list<XMLNode*>::iterator i = s.begin(); i != s.end(); ++i) {
|
2011-09-26 16:35:09 -04:00
|
|
|
for (PortList::const_iterator j = pr->begin(); j != pr->end(); ++j) {
|
2010-07-08 18:55:20 -04:00
|
|
|
(*j)->set_state (**i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-15 09:33:20 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Manager::destroy ()
|
|
|
|
{
|
|
|
|
delete theManager;
|
|
|
|
theManager = 0;
|
|
|
|
}
|