use glibmm threads for the midnam load thread, instead of raw pthreads (for portability)
This commit is contained in:
parent
5ff8e260ff
commit
ece18d3083
|
@ -53,7 +53,7 @@ public:
|
||||||
typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
|
typedef std::map<std::string, boost::shared_ptr<MIDINameDocument> > MidiNameDocuments;
|
||||||
typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
|
typedef std::map<std::string, MIDINameDocument::MasterDeviceNamesList> DeviceNamesByMaker;
|
||||||
|
|
||||||
virtual ~MidiPatchManager() { _manager = 0; }
|
~MidiPatchManager();
|
||||||
|
|
||||||
static MidiPatchManager& instance() {
|
static MidiPatchManager& instance() {
|
||||||
if (_manager == 0) {
|
if (_manager == 0) {
|
||||||
|
@ -172,8 +172,8 @@ private:
|
||||||
|
|
||||||
Glib::Threads::Mutex _lock;
|
Glib::Threads::Mutex _lock;
|
||||||
bool no_patch_changed_messages;
|
bool no_patch_changed_messages;
|
||||||
pthread_t _midnam_load_thread;
|
bool stop_thread;
|
||||||
static void* _midnam_load (void *);
|
Glib::Threads::Thread* _midnam_load_thread;
|
||||||
void load_midnams ();
|
void load_midnams ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,19 @@ MidiPatchManager* MidiPatchManager::_manager = 0;
|
||||||
|
|
||||||
MidiPatchManager::MidiPatchManager ()
|
MidiPatchManager::MidiPatchManager ()
|
||||||
: no_patch_changed_messages (false)
|
: no_patch_changed_messages (false)
|
||||||
|
, stop_thread (false)
|
||||||
{
|
{
|
||||||
add_search_path (midi_patch_search_path ());
|
add_search_path (midi_patch_search_path ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MidiPatchManager::~MidiPatchManager ()
|
||||||
|
{
|
||||||
|
_manager = 0;
|
||||||
|
|
||||||
|
stop_thread = true;
|
||||||
|
_midnam_load_thread->join ();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiPatchManager::add_search_path (const Searchpath& search_path)
|
MidiPatchManager::add_search_path (const Searchpath& search_path)
|
||||||
{
|
{
|
||||||
|
@ -116,6 +125,9 @@ MidiPatchManager::add_midnam_files_from_directory(const std::string& directory_p
|
||||||
info << string_compose (P_("Loading %1 MIDI patch from %2", "Loading %1 MIDI patches from %2", result.size()), result.size(), directory_path) << endmsg;
|
info << string_compose (P_("Loading %1 MIDI patch from %2", "Loading %1 MIDI patches from %2", result.size()), result.size(), directory_path) << endmsg;
|
||||||
|
|
||||||
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
||||||
|
if (stop_thread) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
load_midi_name_document (*i);
|
load_midi_name_document (*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,8 +154,8 @@ MidiPatchManager::remove_midnam_files_from_directory(const std::string& director
|
||||||
find_files_matching_pattern (result, directory_path, "*.midnam");
|
find_files_matching_pattern (result, directory_path, "*.midnam");
|
||||||
|
|
||||||
info << string_compose(
|
info << string_compose(
|
||||||
P_("Unloading %1 MIDI patch from %2", "Unloading %1 MIDI patches from %2", result.size()),
|
P_("Unloading %1 MIDI patch from %2", "Unloading %1 MIDI patches from %2", result.size()),
|
||||||
result.size(), directory_path)
|
result.size(), directory_path)
|
||||||
<< endmsg;
|
<< endmsg;
|
||||||
|
|
||||||
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
for (vector<std::string>::const_iterator i = result.begin(); i != result.end(); ++i) {
|
||||||
|
@ -181,7 +193,7 @@ MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> do
|
||||||
{
|
{
|
||||||
bool added = false;
|
bool added = false;
|
||||||
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
||||||
document->master_device_names_by_model().begin();
|
document->master_device_names_by_model().begin();
|
||||||
device != document->master_device_names_by_model().end();
|
device != document->master_device_names_by_model().end();
|
||||||
++device) {
|
++device) {
|
||||||
if (_documents.find(device->first) != _documents.end()) {
|
if (_documents.find(device->first) != _documents.end()) {
|
||||||
|
@ -202,7 +214,7 @@ MidiPatchManager::add_midi_name_document (boost::shared_ptr<MIDINameDocument> do
|
||||||
_devices_by_manufacturer.insert(std::make_pair(manufacturer, empty));
|
_devices_by_manufacturer.insert(std::make_pair(manufacturer, empty));
|
||||||
}
|
}
|
||||||
_devices_by_manufacturer[manufacturer].insert(
|
_devices_by_manufacturer[manufacturer].insert(
|
||||||
std::make_pair(device->first, device->second));
|
std::make_pair(device->first, device->second));
|
||||||
|
|
||||||
added = true;
|
added = true;
|
||||||
// TODO: handle this gracefully.
|
// TODO: handle this gracefully.
|
||||||
|
@ -231,7 +243,7 @@ MidiPatchManager::remove_midi_name_document (const std::string& file_path, bool
|
||||||
_documents.erase(i++);
|
_documents.erase(i++);
|
||||||
|
|
||||||
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
for (MIDINameDocument::MasterDeviceNamesList::const_iterator device =
|
||||||
document->master_device_names_by_model().begin();
|
document->master_device_names_by_model().begin();
|
||||||
device != document->master_device_names_by_model().end();
|
device != document->master_device_names_by_model().end();
|
||||||
++device) {
|
++device) {
|
||||||
|
|
||||||
|
@ -254,14 +266,6 @@ MidiPatchManager::remove_midi_name_document (const std::string& file_path, bool
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
|
||||||
MidiPatchManager::_midnam_load (void* arg)
|
|
||||||
{
|
|
||||||
MidiPatchManager* mpm = (MidiPatchManager *) arg;
|
|
||||||
mpm->load_midnams ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiPatchManager::load_midnams ()
|
MidiPatchManager::load_midnams ()
|
||||||
{
|
{
|
||||||
|
@ -278,14 +282,14 @@ MidiPatchManager::load_midnams ()
|
||||||
add_midnam_files_from_directory (*i);
|
add_midnam_files_from_directory (*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatchesChanged (); /* EMIT SIGNAL */
|
PatchesChanged (); /* EMIT SIGNAL */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiPatchManager::load_midnams_in_thread ()
|
MidiPatchManager::load_midnams_in_thread ()
|
||||||
{
|
{
|
||||||
pthread_create_and_store (X_("midnam"), &_midnam_load_thread, _midnam_load, this);
|
_midnam_load_thread = Glib::Threads::Thread::create (sigc::mem_fun (*this, &MidiPatchManager::load_midnams));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue
Block a user