2008-12-08 09:50:19 +00:00
|
|
|
/*
|
2019-08-03 04:01:25 +02:00
|
|
|
* Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
|
* Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
|
|
|
|
|
* Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
|
* Copyright (C) 2012-2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
|
* Copyright (C) 2014-2016 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.
|
|
|
|
|
*/
|
2008-12-08 09:50:19 +00:00
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
2012-06-23 05:06:54 +00:00
|
|
|
#include <glibmm/fileutils.h>
|
|
|
|
|
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 06:30:50 +00:00
|
|
|
#include "pbd/error.h"
|
2019-12-19 13:30:18 -07:00
|
|
|
#include "pbd/file_utils.h"
|
|
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
|
#include "pbd/unwind.h"
|
2008-12-09 08:35:02 +00:00
|
|
|
|
|
|
|
|
#include "ardour/midi_patch_manager.h"
|
2013-07-11 15:24:36 -04:00
|
|
|
|
2014-03-10 14:54:29 +00:00
|
|
|
#include "ardour/search_paths.h"
|
2008-12-08 09:50:19 +00:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-01-19 21:31:21 +00:00
|
|
|
|
2008-12-08 09:50:19 +00:00
|
|
|
using namespace std;
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
using namespace MIDI;
|
|
|
|
|
using namespace MIDI::Name;
|
|
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
|
|
MidiPatchManager* MidiPatchManager::_manager = 0;
|
|
|
|
|
|
2012-03-20 18:03:46 +00:00
|
|
|
MidiPatchManager::MidiPatchManager ()
|
2019-12-19 13:30:18 -07:00
|
|
|
: no_patch_changed_messages (false)
|
2020-01-05 17:51:18 -07:00
|
|
|
, stop_thread (false)
|
2012-03-20 18:03:46 +00:00
|
|
|
{
|
2019-12-19 13:30:18 -07:00
|
|
|
add_search_path (midi_patch_search_path ());
|
2012-03-20 18:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 17:51:18 -07:00
|
|
|
MidiPatchManager::~MidiPatchManager ()
|
|
|
|
|
{
|
|
|
|
|
_manager = 0;
|
|
|
|
|
|
|
|
|
|
stop_thread = true;
|
|
|
|
|
_midnam_load_thread->join ();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-08 09:50:19 +00:00
|
|
|
void
|
2015-10-19 14:52:48 +10:00
|
|
|
MidiPatchManager::add_search_path (const Searchpath& search_path)
|
2008-12-08 09:50:19 +00:00
|
|
|
{
|
2015-10-19 14:52:48 +10:00
|
|
|
for (Searchpath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) {
|
|
|
|
|
|
|
|
|
|
if (_search_path.contains(*i)) {
|
|
|
|
|
// already processed files from this path
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Glib::file_test (*i, Glib::FILE_TEST_EXISTS)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Glib::file_test (*i, Glib::FILE_TEST_IS_DIR)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_search_path.add_directory (*i);
|
|
|
|
|
}
|
2015-10-19 20:23:33 +10:00
|
|
|
}
|
|
|
|
|
|
2016-10-29 19:01:16 +02:00
|
|
|
bool
|
2020-04-23 02:25:38 +02:00
|
|
|
MidiPatchManager::add_custom_midnam (const std::string& id, char const* midnam)
|
2016-10-29 19:01:16 +02:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<MIDINameDocument> document;
|
|
|
|
|
document = boost::shared_ptr<MIDINameDocument>(new MIDINameDocument());
|
|
|
|
|
XMLTree mxml;
|
|
|
|
|
if (mxml.read_buffer (midnam, true)) {
|
|
|
|
|
if (0 == document->set_state (mxml, *mxml.root())) {
|
|
|
|
|
document->set_file_path ("custom:" + id);
|
|
|
|
|
add_midi_name_document (document);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MidiPatchManager::remove_custom_midnam (const std::string& id)
|
|
|
|
|
{
|
|
|
|
|
return remove_midi_name_document ("custom:" + id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-30 21:24:26 +01:00
|
|
|
bool
|
2020-04-23 02:25:38 +02:00
|
|
|
MidiPatchManager::update_custom_midnam (const std::string& id, char const* midnam)
|
2016-10-30 21:24:26 +01:00
|
|
|
{
|
2020-04-22 05:02:31 +02:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2016-10-30 21:24:26 +01:00
|
|
|
remove_midi_name_document ("custom:" + id, false);
|
|
|
|
|
return add_custom_midnam (id, midnam);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 06:28:02 +01:00
|
|
|
bool
|
|
|
|
|
MidiPatchManager::is_custom_model (const std::string& model) const
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<MIDINameDocument> midnam = document_by_model (model);
|
|
|
|
|
return (midnam && midnam->file_path().substr(0, 7) == "custom:");
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
void
|
|
|
|
|
MidiPatchManager::add_midnam_files_from_directory(const std::string& directory_path)
|
|
|
|
|
{
|
|
|
|
|
vector<std::string> result;
|
|
|
|
|
find_files_matching_pattern (result, directory_path, "*.midnam");
|
2015-10-19 14:52:48 +10:00
|
|
|
|
2019-12-19 13:30:18 -07:00
|
|
|
info << string_compose (P_("Loading %1 MIDI patch from %2", "Loading %1 MIDI patches from %2", result.size()), result.size(), directory_path) << endmsg;
|
2015-10-19 20:23:33 +10:00
|
|
|
|
|
|
|
|
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
2020-01-05 17:51:18 -07:00
|
|
|
if (stop_thread) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-29 19:01:16 +02:00
|
|
|
load_midi_name_document (*i);
|
2015-10-19 14:52:48 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MidiPatchManager::remove_search_path (const Searchpath& search_path)
|
|
|
|
|
{
|
|
|
|
|
for (Searchpath::const_iterator i = search_path.begin(); i != search_path.end(); ++i) {
|
|
|
|
|
|
|
|
|
|
if (!_search_path.contains(*i)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
remove_midnam_files_from_directory(*i);
|
|
|
|
|
|
2015-10-19 14:52:48 +10:00
|
|
|
_search_path.remove_directory (*i);
|
|
|
|
|
}
|
2015-10-19 20:23:33 +10:00
|
|
|
}
|
2015-10-19 14:52:48 +10:00
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
void
|
|
|
|
|
MidiPatchManager::remove_midnam_files_from_directory(const std::string& directory_path)
|
|
|
|
|
{
|
|
|
|
|
vector<std::string> result;
|
|
|
|
|
find_files_matching_pattern (result, directory_path, "*.midnam");
|
|
|
|
|
|
2015-10-25 17:46:39 +01:00
|
|
|
info << string_compose(
|
2020-01-05 17:51:18 -07:00
|
|
|
P_("Unloading %1 MIDI patch from %2", "Unloading %1 MIDI patches from %2", result.size()),
|
|
|
|
|
result.size(), directory_path)
|
2015-10-25 17:46:39 +01:00
|
|
|
<< endmsg;
|
2015-10-19 20:23:33 +10:00
|
|
|
|
|
|
|
|
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
|
|
|
|
remove_midi_name_document (*i);
|
2015-10-19 14:52:48 +10:00
|
|
|
}
|
2008-12-08 09:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-19 10:08:47 +10:00
|
|
|
bool
|
2016-10-29 19:01:16 +02:00
|
|
|
MidiPatchManager::load_midi_name_document (const std::string& file_path)
|
2015-10-19 10:08:47 +10:00
|
|
|
{
|
|
|
|
|
boost::shared_ptr<MIDINameDocument> document;
|
|
|
|
|
try {
|
|
|
|
|
document = boost::shared_ptr<MIDINameDocument>(new MIDINameDocument(file_path));
|
|
|
|
|
}
|
|
|
|
|
catch (...) {
|
2015-10-19 20:51:01 +10:00
|
|
|
error << string_compose(_("Error parsing MIDI patch file %1"), file_path)
|
|
|
|
|
<< endmsg;
|
2015-10-19 10:08:47 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-10-29 19:01:16 +02:00
|
|
|
return add_midi_name_document (document);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<MIDINameDocument>
|
|
|
|
|
MidiPatchManager::document_by_model(std::string model_name) const
|
|
|
|
|
{
|
|
|
|
|
MidiNameDocuments::const_iterator i = _documents.find (model_name);
|
|
|
|
|
if (i != _documents.end ()) {
|
|
|
|
|
return i->second;
|
|
|
|
|
}
|
|
|
|
|
return boost::shared_ptr<MIDINameDocument> ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> document)
|
|
|
|
|
{
|
2016-10-30 21:24:26 +01:00
|
|
|
bool added = false;
|
2015-10-19 10:08:47 +10:00
|
|
|
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
2020-01-05 17:51:18 -07:00
|
|
|
document->master_device_names_by_model().begin();
|
2015-10-19 10:08:47 +10:00
|
|
|
device != document->master_device_names_by_model().end();
|
|
|
|
|
++device) {
|
|
|
|
|
if (_documents.find(device->first) != _documents.end()) {
|
|
|
|
|
warning << string_compose(_("Duplicate MIDI device `%1' in `%2' ignored"),
|
|
|
|
|
device->first,
|
2016-10-29 19:01:16 +02:00
|
|
|
document->file_path()) << endmsg;
|
2015-10-19 10:08:47 +10:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_documents[device->first] = document;
|
|
|
|
|
_master_devices_by_model[device->first] = device->second;
|
|
|
|
|
|
|
|
|
|
_all_models.insert(device->first);
|
|
|
|
|
const std::string& manufacturer = device->second->manufacturer();
|
|
|
|
|
if (_devices_by_manufacturer.find(manufacturer) ==
|
|
|
|
|
_devices_by_manufacturer.end()) {
|
|
|
|
|
MIDINameDocument::MasterDeviceNamesList empty;
|
|
|
|
|
_devices_by_manufacturer.insert(std::make_pair(manufacturer, empty));
|
|
|
|
|
}
|
|
|
|
|
_devices_by_manufacturer[manufacturer].insert(
|
2020-01-05 17:51:18 -07:00
|
|
|
std::make_pair(device->first, device->second));
|
2015-10-19 10:08:47 +10:00
|
|
|
|
2016-10-30 21:24:26 +01:00
|
|
|
added = true;
|
2015-10-19 10:08:47 +10:00
|
|
|
// TODO: handle this gracefully.
|
|
|
|
|
assert(_documents.count(device->first) == 1);
|
|
|
|
|
assert(_master_devices_by_model.count(device->first) == 1);
|
|
|
|
|
}
|
2016-10-29 19:01:16 +02:00
|
|
|
|
2019-12-19 13:30:18 -07:00
|
|
|
if (added && !no_patch_changed_messages) {
|
2016-10-30 21:24:26 +01:00
|
|
|
PatchesChanged(); /* EMIT SIGNAL */
|
|
|
|
|
}
|
2019-12-19 13:30:18 -07:00
|
|
|
|
2016-10-30 21:24:26 +01:00
|
|
|
return added;
|
2015-10-19 10:08:47 +10:00
|
|
|
}
|
|
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
bool
|
2016-10-30 21:24:26 +01:00
|
|
|
MidiPatchManager::remove_midi_name_document (const std::string& file_path, bool emit_signal)
|
2012-03-20 18:03:46 +00:00
|
|
|
{
|
2015-10-19 20:23:33 +10:00
|
|
|
bool removed = false;
|
|
|
|
|
for (MidiNameDocuments::iterator i = _documents.begin(); i != _documents.end();) {
|
|
|
|
|
if (i->second->file_path() == file_path) {
|
2012-03-20 18:03:46 +00:00
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
boost::shared_ptr<MIDINameDocument> document = i->second;
|
2012-03-20 18:03:46 +00:00
|
|
|
|
2015-10-19 20:51:01 +10:00
|
|
|
info << string_compose(_("Removing MIDI patch file %1"), file_path) << endmsg;
|
|
|
|
|
|
2016-10-30 04:51:31 +01:00
|
|
|
_documents.erase(i++);
|
2008-12-09 07:42:19 +00:00
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
2020-01-05 17:51:18 -07:00
|
|
|
document->master_device_names_by_model().begin();
|
2015-10-19 20:23:33 +10:00
|
|
|
device != document->master_device_names_by_model().end();
|
|
|
|
|
++device) {
|
2009-10-14 16:10:01 +00:00
|
|
|
|
2015-10-19 20:23:33 +10:00
|
|
|
_master_devices_by_model.erase(device->first);
|
|
|
|
|
|
|
|
|
|
_all_models.erase(device->first);
|
|
|
|
|
|
|
|
|
|
const std::string& manufacturer = device->second->manufacturer();
|
|
|
|
|
|
|
|
|
|
_devices_by_manufacturer[manufacturer].erase(device->first);
|
|
|
|
|
}
|
|
|
|
|
removed = true;
|
|
|
|
|
} else {
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2008-12-08 09:50:19 +00:00
|
|
|
}
|
2016-10-30 21:24:26 +01:00
|
|
|
if (removed && emit_signal) {
|
2016-10-29 19:01:16 +02:00
|
|
|
PatchesChanged(); /* EMIT SIGNAL */
|
|
|
|
|
}
|
2015-10-19 20:23:33 +10:00
|
|
|
return removed;
|
2008-12-08 09:50:19 +00:00
|
|
|
}
|
2019-12-19 13:30:18 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MidiPatchManager::load_midnams ()
|
|
|
|
|
{
|
2019-12-23 10:26:05 -07:00
|
|
|
/* really there's only going to be one x-thread request/signal before
|
|
|
|
|
this thread exits but we'll say 8 just to be sure.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
PBD::notify_event_loops_about_thread_creation (pthread_self(), "midi-patch-manager", 8);
|
2020-03-29 14:56:22 +02:00
|
|
|
pthread_set_name ("MIDNAMLoader");
|
2019-12-23 10:26:05 -07:00
|
|
|
|
2019-12-19 13:30:18 -07:00
|
|
|
{
|
|
|
|
|
PBD::Unwinder<bool> npc (no_patch_changed_messages, true);
|
|
|
|
|
for (Searchpath::const_iterator i = _search_path.begin(); i != _search_path.end(); ++i) {
|
2020-04-26 04:55:59 +02:00
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
2019-12-19 13:30:18 -07:00
|
|
|
add_midnam_files_from_directory (*i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-05 17:51:18 -07:00
|
|
|
|
2019-12-19 13:30:18 -07:00
|
|
|
PatchesChanged (); /* EMIT SIGNAL */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MidiPatchManager::load_midnams_in_thread ()
|
|
|
|
|
{
|
2020-01-05 17:51:18 -07:00
|
|
|
_midnam_load_thread = Glib::Threads::Thread::create (sigc::mem_fun (*this, &MidiPatchManager::load_midnams));
|
2019-12-19 13:30:18 -07:00
|
|
|
}
|
2019-12-23 10:26:05 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MidiPatchManager::maybe_use (PBD::ScopedConnectionList& cl,
|
|
|
|
|
PBD::EventLoop::InvalidationRecord* ir,
|
|
|
|
|
const boost::function<void()> & midnam_info_method,
|
|
|
|
|
PBD::EventLoop* event_loop)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
Glib::Threads::Mutex::Lock lm (_lock);
|
|
|
|
|
|
|
|
|
|
if (!_documents.empty()) {
|
|
|
|
|
/* already have documents loaded, so call closure to use them */
|
|
|
|
|
midnam_info_method ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if/when they ever change, call the closure (maybe multiple times) */
|
|
|
|
|
|
|
|
|
|
PatchesChanged.connect (cl, ir, midnam_info_method, event_loop);
|
|
|
|
|
}
|
|
|
|
|
}
|