281 lines
6.2 KiB
C++
281 lines
6.2 KiB
C++
|
/*
|
||
|
* Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.com>
|
||
|
* Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
|
||
|
*
|
||
|
* 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.,
|
||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||
|
*/
|
||
|
|
||
|
#include <algorithm>
|
||
|
#include <bitset>
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <pthread.h>
|
||
|
|
||
|
#include "pbd/compose.h"
|
||
|
#include "pbd/convert.h"
|
||
|
#include "pbd/debug.h"
|
||
|
#include "pbd/failed_constructor.h"
|
||
|
#include "pbd/file_utils.h"
|
||
|
#include "pbd/search_path.h"
|
||
|
#include "pbd/enumwriter.h"
|
||
|
|
||
|
#include "midi++/parser.h"
|
||
|
|
||
|
#include "temporal/time.h"
|
||
|
#include "temporal/bbt_time.h"
|
||
|
|
||
|
#include "ardour/amp.h"
|
||
|
#include "ardour/async_midi_port.h"
|
||
|
#include "ardour/audioengine.h"
|
||
|
#include "ardour/debug.h"
|
||
|
#include "ardour/midiport_manager.h"
|
||
|
#include "ardour/midi_track.h"
|
||
|
#include "ardour/midi_port.h"
|
||
|
#include "ardour/session.h"
|
||
|
#include "ardour/tempo.h"
|
||
|
#include "ardour/types_convert.h"
|
||
|
|
||
|
#include "gtkmm2ext/gui_thread.h"
|
||
|
#include "gtkmm2ext/rgb_macros.h"
|
||
|
|
||
|
#include "gtkmm2ext/colors.h"
|
||
|
|
||
|
#include "gui.h"
|
||
|
#include "lppro.h"
|
||
|
|
||
|
#include "pbd/i18n.h"
|
||
|
|
||
|
#ifdef PLATFORM_WINDOWS
|
||
|
#define random() rand()
|
||
|
#endif
|
||
|
|
||
|
using namespace ARDOUR;
|
||
|
using namespace PBD;
|
||
|
using namespace Glib;
|
||
|
using namespace ArdourSurface;
|
||
|
using namespace Gtkmm2ext;
|
||
|
|
||
|
#include "pbd/abstract_ui.cc" // instantiate template
|
||
|
|
||
|
#define NOVATION 0x1235
|
||
|
#define LAUNCHPADPROMK3 0x0123
|
||
|
|
||
|
bool
|
||
|
LaunchPadPro::available ()
|
||
|
{
|
||
|
bool rv = LIBUSB_SUCCESS == libusb_init (0);
|
||
|
if (rv) {
|
||
|
libusb_exit (0);
|
||
|
}
|
||
|
return rv;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
LaunchPadPro::match_usb (uint16_t vendor, uint16_t device)
|
||
|
{
|
||
|
return vendor == NOVATION && device == LAUNCHPADPROMK3;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
LaunchPadPro::probe (std::string& i, std::string& o)
|
||
|
{
|
||
|
vector<string> midi_inputs;
|
||
|
vector<string> midi_outputs;
|
||
|
AudioEngine::instance()->get_ports ("", DataType::MIDI, PortFlags (IsOutput|IsTerminal), midi_inputs);
|
||
|
AudioEngine::instance()->get_ports ("", DataType::MIDI, PortFlags (IsInput|IsTerminal), midi_outputs);
|
||
|
|
||
|
auto has_lppro = [](string const& s) {
|
||
|
std::string pn = AudioEngine::instance()->get_hardware_port_name_by_name (s);
|
||
|
return pn.find ("Launchpad Pro MK3 MIDI 1") != string::npos;
|
||
|
};
|
||
|
|
||
|
auto pi = std::find_if (midi_inputs.begin (), midi_inputs.end (), has_lppro);
|
||
|
auto po = std::find_if (midi_outputs.begin (), midi_outputs.end (), has_lppro);
|
||
|
|
||
|
if (pi == midi_inputs.end () || po == midi_outputs.end ()) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
i = *pi;
|
||
|
o = *po;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
LaunchPadPro::LaunchPadPro (ARDOUR::Session& s)
|
||
|
: MIDISurface (s, X_("Novation Launchpad Pro"), X_("Launchpad Pro"), true)
|
||
|
{
|
||
|
run_event_loop ();
|
||
|
port_setup ();
|
||
|
|
||
|
std::string pn_in, pn_out;
|
||
|
if (probe (pn_in, pn_out)) {
|
||
|
_async_in->connect (pn_in);
|
||
|
_async_out->connect (pn_out);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
LaunchPadPro::~LaunchPadPro ()
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "push2 control surface object being destroyed\n");
|
||
|
|
||
|
stop_event_loop ();
|
||
|
|
||
|
MIDISurface::drop ();
|
||
|
}
|
||
|
|
||
|
int
|
||
|
LaunchPadPro::set_active (bool yn)
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, string_compose("Launchpad Pro::set_active init with yn: '%1'\n", yn));
|
||
|
|
||
|
if (yn == active()) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (yn) {
|
||
|
|
||
|
if (device_acquire ()) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if ((_connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) {
|
||
|
begin_using_device ();
|
||
|
} else {
|
||
|
/* begin_using_device () will get called once we're connected */
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
/* Control Protocol Manager never calls us with false, but
|
||
|
* insteads destroys us.
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
ControlProtocol::set_active (yn);
|
||
|
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, string_compose("Launchpad Pro::set_active done with yn: '%1'\n", yn));
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
LaunchPadPro::run_event_loop ()
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "start event loop\n");
|
||
|
BaseUI::run ();
|
||
|
}
|
||
|
|
||
|
void
|
||
|
LaunchPadPro::stop_event_loop ()
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "stop event loop\n");
|
||
|
BaseUI::quit ();
|
||
|
}
|
||
|
|
||
|
int
|
||
|
LaunchPadPro::begin_using_device ()
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "begin using device\n");
|
||
|
|
||
|
#if 0
|
||
|
init_buttons (true);
|
||
|
init_touch_strip (false);
|
||
|
reset_pad_colors ();
|
||
|
splash ();
|
||
|
|
||
|
/* catch current selection, if any so that we can wire up the pads if appropriate */
|
||
|
stripable_selection_changed ();
|
||
|
|
||
|
request_pressure_mode ();
|
||
|
#endif
|
||
|
|
||
|
return MIDISurface::begin_using_device ();
|
||
|
}
|
||
|
|
||
|
int
|
||
|
LaunchPadPro::stop_using_device ()
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "stop using device\n");
|
||
|
|
||
|
if (!_in_use) {
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, "nothing to do, device not in use\n");
|
||
|
return 0;
|
||
|
}
|
||
|
#if 0
|
||
|
init_buttons (false);
|
||
|
strip_buttons_off ();
|
||
|
|
||
|
for (auto & pad : _xy_pad_map) {
|
||
|
pad->set_color (LED::Black);
|
||
|
pad->set_state (LED::NoTransition);
|
||
|
write (pad->state_msg());
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
return MIDISurface::stop_using_device ();
|
||
|
}
|
||
|
|
||
|
XMLNode&
|
||
|
LaunchPadPro::get_state() const
|
||
|
{
|
||
|
XMLNode& node (MIDISurface::get_state());
|
||
|
|
||
|
return node;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
LaunchPadPro::set_state (const XMLNode & node, int version)
|
||
|
{
|
||
|
DEBUG_TRACE (DEBUG::Launchpad, string_compose ("LaunchPadPro::set_state: active %1\n", active()));
|
||
|
|
||
|
int retval = 0;
|
||
|
|
||
|
if (MIDISurface::set_state (node, version)) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
std::string
|
||
|
LaunchPadPro::input_port_name () const
|
||
|
{
|
||
|
#ifdef __APPLE__
|
||
|
/* the origin of the numeric magic identifiers is known only to Novation
|
||
|
and may change in time. This is part of how CoreMIDI works.
|
||
|
*/
|
||
|
return X_("system:midi_capture_1319078870");
|
||
|
#else
|
||
|
return X_("Launchpad Pro MK3 MIDI 1 in");
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
std::string
|
||
|
LaunchPadPro::output_port_name () const
|
||
|
{
|
||
|
#ifdef __APPLE__
|
||
|
/* the origin of the numeric magic identifiers is known only to Novation
|
||
|
and may change in time. This is part of how CoreMIDI works.
|
||
|
*/
|
||
|
return X_("system:midi_playback_3409210341");
|
||
|
#else
|
||
|
return X_("Launchpad Pro MK3 MIDI 1 out");
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void
|
||
|
LaunchPadPro::stripable_selection_changed ()
|
||
|
{
|
||
|
}
|