Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / midi_patch_manager.cc
blob2c2f36daa67e389e2278d243cf49924ce1dd4359
1 /*
2 Copyright (C) 2008 Hans Baier
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.
18 $Id$
21 #include <boost/shared_ptr.hpp>
23 #include "pbd/compose.h"
24 #include "pbd/file_utils.h"
25 #include "pbd/error.h"
27 #include "ardour/session.h"
28 #include "ardour/session_directory.h"
29 #include "ardour/midi_patch_manager.h"
31 #include "i18n.h"
33 using namespace std;
34 using namespace ARDOUR;
35 using namespace MIDI;
36 using namespace MIDI::Name;
37 using namespace PBD;
38 using namespace PBD::sys;
40 MidiPatchManager* MidiPatchManager::_manager = 0;
42 void
43 MidiPatchManager::set_session (Session* s)
45 SessionHandlePtr::set_session (s);
46 refresh();
49 void
50 MidiPatchManager::refresh()
52 _documents.clear();
53 _master_devices_by_model.clear();
54 _all_models.clear();
56 if (!_session) {
57 return;
60 path path_to_patches = _session->session_directory().midi_patch_path();
62 if (!exists(path_to_patches)) {
63 return;
66 assert(is_directory(path_to_patches));
68 Glib::PatternSpec pattern(string("*.midnam"));
69 vector<path> result;
71 find_matching_files_in_directory(path_to_patches, pattern, result);
73 info << "Loading " << result.size() << " MIDI patches from " << path_to_patches.to_string() << endl;
75 for (vector<path>::iterator i = result.begin(); i != result.end(); ++i) {
76 boost::shared_ptr<MIDINameDocument> document(new MIDINameDocument(i->to_string()));
77 for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
78 document->master_device_names_by_model().begin();
79 device != document->master_device_names_by_model().end();
80 ++device) {
81 //cerr << "got model " << device->first << endl;
82 // have access to the documents by model name
83 _documents[device->first] = document;
84 // build a list of all master devices from all documents
85 _master_devices_by_model[device->first] = device->second;
86 _all_models.push_back(device->first);
88 // make sure there are no double model names
89 // TODO: handle this gracefully.
90 assert(_documents.count(device->first) == 1);
91 assert(_master_devices_by_model.count(device->first) == 1);
96 void
97 MidiPatchManager::session_going_away ()
99 SessionHandlePtr::session_going_away ();
100 refresh ();