Fix midnam warning messages.
[ardour.git] / libs / midi++2 / midnam_patch.cc
1 /*
2     Copyright (C) 2008 Hans Baier
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <algorithm>
22 #include <iostream>
23
24 #include "midi++/midnam_patch.h"
25 #include "pbd/compose.h"
26 #include "pbd/convert.h"
27 #include "pbd/error.h"
28 #include "pbd/failed_constructor.h"
29
30 using namespace std;
31 using PBD::error;
32
33 namespace MIDI
34 {
35
36 namespace Name
37 {
38         
39 Patch::Patch (std::string name, uint8_t p_number, uint16_t b_number)
40         : _name (name)
41         , _id (p_number, b_number)
42 {
43 }
44
45 int initialize_primary_key_from_commands (PatchPrimaryKey& id, const XMLNode* node)
46 {
47         id.bank_number = 0;
48
49         const XMLNodeList events = node->children();
50         for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
51
52                 XMLNode* node = *i;
53                 if (node->name() == "ControlChange") {
54                         string control = node->property("Control")->value();
55                         assert(control != "");
56                         string value = node->property("Value")->value();
57                         assert(value != "");
58
59                         if (control == "0") {
60                                 id.bank_number |= (PBD::atoi (value)) << 7;
61                         } else if (control == "32") {
62                                 id.bank_number |= PBD::atoi (value);
63                         }
64
65                 } else if (node->name() == "ProgramChange") {
66                         string number = node->property("Number")->value();
67                         assert(number != "");
68                         id.program_number = PBD::atoi(number);
69                 }
70         }
71
72         return 0;
73 }
74
75 XMLNode&
76 Patch::get_state (void)
77 {
78         XMLNode* node = new XMLNode("Patch");
79
80         /* XXX this is totally wrong */
81
82         node->add_property("Number", string_compose ("%1", _id.program_number));
83         node->add_property("Name",   _name);
84
85         /*
86         typedef std::list< boost::shared_ptr< Evoral::MIDIEvent<double> > > PatchMidiCommands;
87         XMLNode* commands = node->add_child("PatchMIDICommands");
88         for (PatchMidiCommands::const_iterator event = _patch_midi_commands.begin();
89             event != _patch_midi_commands.end();
90             ++event) {
91                 commands->add_child_copy(*((((Evoral::MIDIEvent&)*event)).to_xml()));
92         }
93         */
94
95         return *node;
96 }
97
98 int
99 Patch::set_state (const XMLTree&, const XMLNode& node)
100 {
101         if (node.name() != "Patch") {
102                 cerr << "Incorrect node " << node.name() << " handed to Patch" << endl;
103                 return -1;
104         }
105
106         const XMLProperty* prop = node.property ("Number");
107
108         if (!prop) {
109                 return -1;
110         }
111         _id.program_number = PBD::atoi (prop->value());
112
113         prop = node.property ("Name");
114
115         if (!prop) {
116                 return -1;
117         }
118         _name   = prop->value();
119
120         XMLNode* commands = node.child("PatchMIDICommands");
121
122         if (commands) {
123                 if (initialize_primary_key_from_commands(_id, commands)) {
124                         return -1;
125                 }
126         } else {
127                 string program_change = node.property("ProgramChange")->value();
128                 assert(program_change.length());
129                 _id.program_number = PBD::atoi(program_change);
130         }
131         
132         XMLNode* use_note_name_list = node.child("UsesNoteNameList");
133         if (use_note_name_list) {
134                 _note_list_name = use_note_name_list->property ("Name")->value();
135         }
136
137         return 0;
138 }
139
140 XMLNode&
141 Note::get_state (void)
142 {
143         XMLNode* node = new XMLNode("Note");
144         node->add_property("Number", _number);
145         node->add_property("Name",   _name);
146
147         return *node;
148 }
149
150 int
151 Note::set_state (const XMLTree&, const XMLNode& node)
152 {
153         assert(node.name() == "Note");
154
155         /* If the note number is junk, this will pull a number from the start, or
156            return zero if there isn't one.  Better error detection would be a good
157            idea, but the duplicate check in NoteNameList::set_state() will probably
158            catch really broken files anyway. */
159         _number = atoi(node.property("Number")->value().c_str());
160         _name   = node.property("Name")->value();
161
162         return 0;
163 }
164
165 XMLNode&
166 NoteNameList::get_state (void)
167 {
168         XMLNode* node = new XMLNode("NoteNameList");
169         node->add_property("Name", _name);
170
171         return *node;
172 }
173
174 int
175 NoteNameList::set_state (const XMLTree& tree, const XMLNode& node)
176 {
177         assert(node.name() == "NoteNameList");
178         _name = node.property("Name")->value();
179         _notes.clear();
180         _notes.resize(128);
181
182         for (XMLNodeList::const_iterator i = node.children().begin();
183              i != node.children().end(); ++i) {
184                 if ((*i)->name() != "Note") {
185                         continue;
186                 }
187                 boost::shared_ptr<Note> note(new Note());
188                 note->set_state (tree, *(*i));
189                 if (note->number() > 127) {
190                         PBD::warning << string_compose("%1: Note number %2 (%3) out of range",
191                                                        tree.filename(), (int)note->number(), note->name())
192                                      << endmsg;
193                 } else if (_notes[note->number()]) {
194                         PBD::warning <<
195                                 string_compose("%1: Duplicate note number %2 (%3) ignored",
196                                                tree.filename(), (int)note->number(), note->name())
197                                      << endmsg;
198                 } else {
199                         _notes[note->number()] = note;
200                 }
201         }
202
203         return 0;
204 }
205
206 XMLNode&
207 Control::get_state (void)
208 {
209         XMLNode* node = new XMLNode("Control");
210         node->add_property("Type",   _type);
211         node->add_property("Number", _number);
212         node->add_property("Name",   _name);
213
214         return *node;
215 }
216
217 int
218 Control::set_state (const XMLTree&, const XMLNode& node)
219 {
220         assert(node.name() == "Control");
221         _type   = node.property("Type")->value();
222         _number = node.property("Number")->value();
223         _name   = node.property("Name")->value();
224
225         return 0;
226 }
227
228 XMLNode&
229 ControlNameList::get_state (void)
230 {
231         XMLNode* node = new XMLNode("ControlNameList");
232         node->add_property("Name", _name);
233
234         return *node;
235 }
236
237 int
238 ControlNameList::set_state (const XMLTree& tree, const XMLNode& node)
239 {
240         assert(node.name() == "ControlNameList");
241         _name = node.property("Name")->value();
242
243         for (XMLNodeList::const_iterator i = node.children().begin();
244              i != node.children().end(); ++i) {
245                 if ((*i)->name() != "comment") {
246                         boost::shared_ptr<Control> control(new Control());
247                         control->set_state (tree, *(*i));
248                         _controls.push_back(control);
249                 }
250         }
251
252         return 0;
253 }
254
255 XMLNode&
256 PatchBank::get_state (void)
257 {
258         XMLNode* node = new XMLNode("PatchBank");
259         node->add_property("Name",   _name);
260         XMLNode* patch_name_list = node->add_child("PatchNameList");
261         for (PatchNameList::iterator patch = _patch_name_list.begin();
262             patch != _patch_name_list.end();
263             ++patch) {
264                 patch_name_list->add_child_nocopy((*patch)->get_state());
265         }
266
267         return *node;
268 }
269
270 int
271 PatchBank::set_state (const XMLTree& tree, const XMLNode& node)
272 {
273         assert(node.name() == "PatchBank");
274         _name   = node.property("Name")->value();
275
276         XMLNode* commands = node.child("MIDICommands");
277         if (commands) {
278                 PatchPrimaryKey id (0, 0);
279                 if (initialize_primary_key_from_commands (id, commands)) {
280                         return -1;
281                 }
282                 _number = id.bank_number;
283         }
284
285         XMLNode* patch_name_list = node.child("PatchNameList");
286
287         if (patch_name_list) {
288                 const XMLNodeList patches = patch_name_list->children();
289                 for (XMLNodeList::const_iterator i = patches.begin(); i != patches.end(); ++i) {
290                         boost::shared_ptr<Patch> patch (new Patch (string(), 0, _number));
291                         patch->set_state(tree, *(*i));
292                         _patch_name_list.push_back(patch);
293                 }
294         } else {
295                 XMLNode* use_patch_name_list = node.child ("UsesPatchNameList");
296                 if (use_patch_name_list) {
297                         _patch_list_name = use_patch_name_list->property ("Name")->value();
298                 } else {
299                         error << "Patch without patch name list - patchfile will be ignored" << endmsg;
300                         return -1;
301                 }
302         }
303
304         return 0;
305 }
306
307 int
308 PatchBank::set_patch_name_list (const PatchNameList& pnl)
309 {
310         _patch_name_list = pnl;
311         _patch_list_name = "";
312
313         for (PatchNameList::iterator p = _patch_name_list.begin(); p != _patch_name_list.end(); p++) {
314                 (*p)->set_bank_number (_number);
315         }
316
317         return 0;
318 }
319
320 std::ostream&
321 operator<< (std::ostream& os, const ChannelNameSet& cns)
322 {
323         os << "Channel Name Set: name = " << cns._name << endl
324            << "Map size " << cns._patch_map.size () << endl
325            << "List size " << cns._patch_list.size() << endl
326            << "Patch list name = [" << cns._patch_list_name << ']' << endl
327            << "Available channels : ";
328         for (set<uint8_t>::iterator x = cns._available_for_channels.begin(); x != cns._available_for_channels.end(); ++x) {
329                 os << (int) (*x) << ' ';
330         }
331         os << endl;
332         
333         for (ChannelNameSet::PatchBanks::const_iterator pbi = cns._patch_banks.begin(); pbi != cns._patch_banks.end(); ++pbi) {
334                 os << "\tPatch Bank " << (*pbi)->name() << " with " << (*pbi)->patch_name_list().size() << " patches\n";
335                 for (PatchBank::PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
336                         os << "\t\tPatch name " << (*pni)->name() << " prog " << (int) (*pni)->program_number() << " bank " << (*pni)->bank_number() << endl;
337                 }
338         }
339
340         return os;
341 }
342
343 void
344 ChannelNameSet::set_patch_banks (const ChannelNameSet::PatchBanks& pb)
345 {
346         _patch_banks = pb;
347         
348         _patch_map.clear ();
349         _patch_list.clear ();
350         _patch_list_name = "";
351         _available_for_channels.clear ();
352         
353         for (PatchBanks::const_iterator pbi = _patch_banks.begin(); pbi != _patch_banks.end(); ++pbi) {
354                 for (PatchBank::PatchNameList::const_iterator pni = (*pbi)->patch_name_list().begin(); pni != (*pbi)->patch_name_list().end(); ++pni) {
355                         _patch_map[(*pni)->patch_primary_key()] = (*pni);
356                         _patch_list.push_back ((*pni)->patch_primary_key());
357                 }
358         }
359
360         for (uint8_t n = 0; n < 16; ++n) {
361                 _available_for_channels.insert (n);
362         }
363 }
364
365 void
366 ChannelNameSet::use_patch_name_list (const PatchBank::PatchNameList& pnl)
367 {
368         for (PatchBank::PatchNameList::const_iterator p = pnl.begin(); p != pnl.end(); ++p) {
369                 _patch_map[(*p)->patch_primary_key()] = (*p);
370                 _patch_list.push_back ((*p)->patch_primary_key());
371         }
372 }
373
374 XMLNode&
375 ChannelNameSet::get_state (void)
376 {
377         XMLNode* node = new XMLNode("ChannelNameSet");
378         node->add_property("Name",   _name);
379
380         XMLNode* available_for_channels = node->add_child("AvailableForChannels");
381         assert(available_for_channels);
382
383         for (uint8_t channel = 0; channel < 16; ++channel) {
384                 XMLNode* available_channel = available_for_channels->add_child("AvailableChannel");
385                 assert(available_channel);
386
387                 available_channel->add_property("Channel", (long) channel);
388
389                 if (_available_for_channels.find(channel) != _available_for_channels.end()) {
390                         available_channel->add_property("Available", "true");
391                 } else {
392                         available_channel->add_property("Available", "false");
393                 }
394         }
395
396         for (PatchBanks::iterator patch_bank = _patch_banks.begin();
397             patch_bank != _patch_banks.end();
398             ++patch_bank) {
399                 node->add_child_nocopy((*patch_bank)->get_state());
400         }
401
402         return *node;
403 }
404
405 int
406 ChannelNameSet::set_state (const XMLTree& tree, const XMLNode& node)
407 {
408         assert(node.name() == "ChannelNameSet");
409         _name   = node.property("Name")->value();
410
411         const XMLNodeList children = node.children();
412         for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
413                 XMLNode* node = *i;
414                 assert(node);
415                 if (node->name() == "AvailableForChannels") {
416                         boost::shared_ptr<XMLSharedNodeList> channels =
417                                 tree.find("//AvailableChannel[@Available = 'true']/@Channel", node);
418                         for(XMLSharedNodeList::const_iterator i = channels->begin();
419                             i != channels->end();
420                             ++i) {
421                                 _available_for_channels.insert(atoi((*i)->attribute_value().c_str()));
422                         }
423                 }
424
425                 if (node->name() == "PatchBank") {
426                         boost::shared_ptr<PatchBank> bank (new PatchBank ());
427                         bank->set_state(tree, *node);
428                         _patch_banks.push_back(bank);
429                         const PatchBank::PatchNameList& patches = bank->patch_name_list();
430                         for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
431                              patch != patches.end();
432                              ++patch) {
433                                 _patch_map[(*patch)->patch_primary_key()] = *patch;
434                                 _patch_list.push_back((*patch)->patch_primary_key());
435                         }
436                 }
437         }
438
439         return 0;
440 }
441
442 int
443 CustomDeviceMode::set_state(const XMLTree& tree, const XMLNode& a_node)
444 {
445         assert(a_node.name() == "CustomDeviceMode");
446
447         _name = a_node.property("Name")->value();
448
449         boost::shared_ptr<XMLSharedNodeList> channel_name_set_assignments =
450                 tree.find("//ChannelNameSetAssign", const_cast<XMLNode *>(&a_node));
451         for(XMLSharedNodeList::const_iterator i = channel_name_set_assignments->begin();
452             i != channel_name_set_assignments->end();
453             ++i) {
454                 int channel = atoi((*i)->property("Channel")->value().c_str());
455                 string name_set = (*i)->property("NameSet")->value();
456                 assert( 1 <= channel && channel <= 16 );
457                 _channel_name_set_assignments[channel - 1] = name_set;
458         }
459         return 0;
460 }
461
462 XMLNode&
463 CustomDeviceMode::get_state(void)
464 {
465         XMLNode* custom_device_mode = new XMLNode("CustomDeviceMode");
466         custom_device_mode->add_property("Name",   _name);
467         XMLNode* channel_name_set_assignments =
468                 custom_device_mode->add_child("ChannelNameSetAssignments");
469         for (int i = 0; i < 15 && !_channel_name_set_assignments[i].empty(); i++) {
470                 XMLNode* channel_name_set_assign =
471                         channel_name_set_assignments->add_child("ChannelNameSetAssign");
472                 channel_name_set_assign->add_property("Channel", i + 1);
473                 channel_name_set_assign->add_property("NameSet", _channel_name_set_assignments[i]);
474         }
475
476         return *custom_device_mode;
477 }
478
479 boost::shared_ptr<CustomDeviceMode> 
480 MasterDeviceNames::custom_device_mode_by_name(std::string mode_name)
481 {
482         return _custom_device_modes[mode_name];
483 }
484
485 boost::shared_ptr<ChannelNameSet> 
486 MasterDeviceNames::channel_name_set_by_device_mode_and_channel(std::string mode, uint8_t channel)
487 {
488         boost::shared_ptr<CustomDeviceMode> cdm = custom_device_mode_by_name(mode);
489         boost::shared_ptr<ChannelNameSet> cns =  _channel_name_sets[cdm->channel_name_set_name_by_channel(channel)];
490         return cns;
491 }
492
493 boost::shared_ptr<Patch> 
494 MasterDeviceNames::find_patch(std::string mode, uint8_t channel, const PatchPrimaryKey& key) 
495 {
496         return channel_name_set_by_device_mode_and_channel(mode, channel)->find_patch(key);
497 }
498
499 boost::shared_ptr<ChannelNameSet>
500 MasterDeviceNames::channel_name_set(const std::string& name)
501 {
502         ChannelNameSets::const_iterator i = _channel_name_sets.find(name);
503         if (i != _channel_name_sets.end()) {
504                 return i->second;
505         }
506         return boost::shared_ptr<ChannelNameSet>();
507 }
508
509 boost::shared_ptr<NoteNameList>
510 MasterDeviceNames::note_name_list(const std::string& name)
511 {
512         NoteNameLists::const_iterator i = _note_name_lists.find(name);
513         if (i != _note_name_lists.end()) {
514                 return i->second;
515         }
516         return boost::shared_ptr<NoteNameList>();
517 }
518
519 std::string
520 MasterDeviceNames::note_name(const std::string& mode_name,
521                              uint8_t            channel,
522                              uint16_t           bank,
523                              uint8_t            program,
524                              uint8_t            number)
525 {
526         if (number > 127) {
527                 return "";
528         }
529
530         boost::shared_ptr<const Patch> patch(
531                 find_patch(mode_name, channel, PatchPrimaryKey(program, bank)));
532         if (!patch) {
533                 return "";
534         }
535
536         boost::shared_ptr<const NoteNameList> note_names(
537                 note_name_list(patch->note_list_name()));
538         if (!note_names) {
539                 return "";
540         }
541
542         boost::shared_ptr<const Note> note(note_names->notes()[number]);
543         return note ? note->name() : "";
544 }
545
546 int
547 MasterDeviceNames::set_state(const XMLTree& tree, const XMLNode&)
548 {
549         // Manufacturer
550         boost::shared_ptr<XMLSharedNodeList> manufacturer = tree.find("//Manufacturer");
551         assert(manufacturer->size() == 1);
552         _manufacturer = manufacturer->front()->children().front()->content();
553
554         // Models
555         boost::shared_ptr<XMLSharedNodeList> models = tree.find("//Model");
556         assert(models->size() >= 1);
557         for (XMLSharedNodeList::iterator i = models->begin();
558              i != models->end();
559              ++i) {
560                 const XMLNodeList& contents = (*i)->children();
561                 assert(contents.size() == 1);
562                 XMLNode * content = *(contents.begin());
563                 assert(content->is_content());
564                 _models.insert(content->content());
565         }
566
567         // CustomDeviceModes
568         boost::shared_ptr<XMLSharedNodeList> custom_device_modes = tree.find("//CustomDeviceMode");
569         for (XMLSharedNodeList::iterator i = custom_device_modes->begin();
570              i != custom_device_modes->end();
571              ++i) {
572                 boost::shared_ptr<CustomDeviceMode> custom_device_mode(new CustomDeviceMode());
573                 custom_device_mode->set_state(tree, *(*i));
574
575                 _custom_device_modes[custom_device_mode->name()] = custom_device_mode;
576                 _custom_device_mode_names.push_back(custom_device_mode->name());
577         }
578
579         // ChannelNameSets
580         boost::shared_ptr<XMLSharedNodeList> channel_name_sets = tree.find("//ChannelNameSet");
581         for (XMLSharedNodeList::iterator i = channel_name_sets->begin();
582              i != channel_name_sets->end();
583              ++i) {
584                 boost::shared_ptr<ChannelNameSet> channel_name_set(new ChannelNameSet());
585                 channel_name_set->set_state(tree, *(*i));
586                 _channel_name_sets[channel_name_set->name()] = channel_name_set;
587         }
588
589         // NoteNameLists
590         boost::shared_ptr<XMLSharedNodeList> note_name_lists = tree.find("//NoteNameList");
591         for (XMLSharedNodeList::iterator i = note_name_lists->begin();
592              i != note_name_lists->end();
593              ++i) {
594                 boost::shared_ptr<NoteNameList> note_name_list(new NoteNameList());
595                 note_name_list->set_state (tree, *(*i));
596                 _note_name_lists[(*i)->property ("Name")->value()] = note_name_list;
597         }
598
599         // ControlNameLists
600         boost::shared_ptr<XMLSharedNodeList> control_name_lists = tree.find("//ControlNameList");
601         for (XMLSharedNodeList::iterator i = control_name_lists->begin();
602              i != control_name_lists->end();
603              ++i) {
604                 boost::shared_ptr<ControlNameList> control_name_list(new ControlNameList());
605                 control_name_list->set_state (tree, *(*i));
606                 _control_name_lists.push_back(control_name_list);
607         }
608
609         // global/post-facto PatchNameLists
610         boost::shared_ptr<XMLSharedNodeList> patch_name_lists = tree.find("/child::MIDINameDocument/child::MasterDeviceNames/child::PatchNameList");
611         for (XMLSharedNodeList::iterator i = patch_name_lists->begin();
612              i != patch_name_lists->end();
613              ++i) {
614
615                 PatchBank::PatchNameList patch_name_list;
616                 const XMLNodeList patches = (*i)->children();
617
618                 for (XMLNodeList::const_iterator p = patches.begin(); p != patches.end(); ++p) {
619                         boost::shared_ptr<Patch> patch (new Patch ());
620                         patch->set_state(tree, *(*p));
621                         patch_name_list.push_back(patch);
622                 }
623
624                 if (!patch_name_list.empty()) {
625                         _patch_name_lists[(*i)->property ("Name")->value()] = patch_name_list;
626                 }
627         }
628
629         /* now traverse patches and hook up anything that used UsePatchNameList
630          * to the right patch list
631          */
632
633         for (ChannelNameSets::iterator cns = _channel_name_sets.begin(); cns != _channel_name_sets.end(); ++cns) {
634                 ChannelNameSet::PatchBanks pbs = cns->second->patch_banks();
635                 PatchNameLists::iterator p;
636
637                 for (ChannelNameSet::PatchBanks::iterator pb = pbs.begin(); pb != pbs.end(); ++pb) {
638                         std::string pln = (*pb)->patch_list_name();
639                         if (!pln.empty()) {
640                                 if ((p = _patch_name_lists.find (pln)) != _patch_name_lists.end()) {
641                                         if ((*pb)->set_patch_name_list (p->second)) {
642                                                 return -1;
643                                         }
644                                         cns->second->use_patch_name_list (p->second);
645                                 } else {
646                                         error << string_compose ("Patch list name %1 was not found - patch file ignored", pln) << endmsg;
647                                         return -1;
648                                 }
649                         }
650                 }
651
652         }
653
654         return 0;
655 }
656
657 XMLNode&
658 MasterDeviceNames::get_state(void)
659 {
660         static XMLNode nothing("<nothing>");
661         return nothing;
662 }
663
664 MIDINameDocument::MIDINameDocument (const string& filename)
665 {
666         if (!_document.read (filename)) {
667                 throw failed_constructor ();
668         }
669
670         _document.set_filename (filename);
671         set_state (_document, *_document.root());
672 }
673
674 int
675 MIDINameDocument::set_state (const XMLTree& tree, const XMLNode&)
676 {
677         // Author
678
679         boost::shared_ptr<XMLSharedNodeList> author = tree.find("//Author");
680         if (author->size() < 1) {
681                 error << "No author information in MIDNAM file" << endmsg;
682                 return -1;
683         }
684         
685         if (author->front()->children().size() > 0) {
686                 _author = author->front()->children().front()->content();
687         }
688
689         // MasterDeviceNames
690
691         boost::shared_ptr<XMLSharedNodeList> master_device_names_list = tree.find ("//MasterDeviceNames");
692
693         for (XMLSharedNodeList::iterator i = master_device_names_list->begin();
694              i != master_device_names_list->end();
695              ++i) {
696                 boost::shared_ptr<MasterDeviceNames> master_device_names(new MasterDeviceNames());
697
698                 if (master_device_names->set_state(tree, *(*i))) {
699                         return -1;
700                 }
701
702                 for (MasterDeviceNames::Models::const_iterator model = master_device_names->models().begin();
703                      model != master_device_names->models().end();
704                      ++model) {
705                         _master_device_names_list.insert(
706                                 std::pair<std::string, boost::shared_ptr<MasterDeviceNames> >
707                                 (*model,      master_device_names));
708                         
709                         _all_models.insert(*model);
710                 }
711         }
712
713         return 0;
714 }
715
716 XMLNode&
717 MIDINameDocument::get_state(void)
718 {
719         static XMLNode nothing("<nothing>");
720         return nothing;
721 }
722
723 boost::shared_ptr<MasterDeviceNames>
724 MIDINameDocument::master_device_names(const std::string& model)
725 {
726         MasterDeviceNamesList::const_iterator m = _master_device_names_list.find(model);
727         if (m != _master_device_names_list.end()) {
728                 return boost::shared_ptr<MasterDeviceNames>(m->second);
729         }
730         return boost::shared_ptr<MasterDeviceNames>();
731 }
732
733 const char* general_midi_program_names[128] = {
734         "Acoustic Grand Piano",
735         "Bright Acoustic Piano",
736         "Electric Grand Piano",
737         "Honky-tonk Piano",
738         "Rhodes Piano",
739         "Chorused Piano",
740         "Harpsichord",
741         "Clavinet",
742         "Celesta",
743         "Glockenspiel",
744         "Music Box",
745         "Vibraphone",
746         "Marimba",
747         "Xylophone",
748         "Tubular Bells",
749         "Dulcimer",
750         "Hammond Organ",
751         "Percussive Organ",
752         "Rock Organ",
753         "Church Organ",
754         "Reed Organ",
755         "Accordion",
756         "Harmonica",
757         "Tango Accordion",
758         "Acoustic Guitar (nylon)",
759         "Acoustic Guitar (steel)",
760         "Electric Guitar (jazz)",
761         "Electric Guitar (clean)",
762         "Electric Guitar (muted)",
763         "Overdriven Guitar",
764         "Distortion Guitar",
765         "Guitar Harmonics",
766         "Acoustic Bass",
767         "Electric Bass (finger)",
768         "Electric Bass (pick)",
769         "Fretless Bass",
770         "Slap Bass 1",
771         "Slap Bass 2",
772         "Synth Bass 1",
773         "Synth Bass 2",
774         "Violin",
775         "Viola",
776         "Cello",
777         "Contrabass",
778         "Tremolo Strings",
779         "Pizzicato Strings",
780         "Orchestral Harp",
781         "Timpani",
782         "String Ensemble 1",
783         "String Ensemble 2",
784         "SynthStrings 1",
785         "SynthStrings 2",
786         "Choir Aahs",
787         "Voice Oohs",
788         "Synth Voice",
789         "Orchestra Hit",
790         "Trumpet",
791         "Trombone",
792         "Tuba",
793         "Muted Trumpet",
794         "French Horn",
795         "Brass Section",
796         "Synth Brass 1",
797         "Synth Brass 2",
798         "Soprano Sax",
799         "Alto Sax",
800         "Tenor Sax",
801         "Baritone Sax",
802         "Oboe",
803         "English Horn",
804         "Bassoon",
805         "Clarinet",
806         "Piccolo",
807         "Flute",
808         "Recorder",
809         "Pan Flute",
810         "Bottle Blow",
811         "Shakuhachi",
812         "Whistle",
813         "Ocarina",
814         "Lead 1 (square)",
815         "Lead 2 (sawtooth)",
816         "Lead 3 (calliope lead)",
817         "Lead 4 (chiff lead)",
818         "Lead 5 (charang)",
819         "Lead 6 (voice)",
820         "Lead 7 (fifths)",
821         "Lead 8 (bass + lead)",
822         "Pad 1 (new age)",
823         "Pad 2 (warm)",
824         "Pad 3 (polysynth)",
825         "Pad 4 (choir)",
826         "Pad 5 (bowed)",
827         "Pad 6 (metallic)",
828         "Pad 7 (halo)",
829         "Pad 8 (sweep)",
830         "FX 1 (rain)",
831         "FX 2 (soundtrack)",
832         "FX 3 (crystal)",
833         "FX 4 (atmosphere)",
834         "FX 5 (brightness)",
835         "FX 6 (goblins)",
836         "FX 7 (echoes)",
837         "FX 8 (sci-fi)",
838         "Sitar",
839         "Banjo",
840         "Shamisen",
841         "Koto",
842         "Kalimba",
843         "Bagpipe",
844         "Fiddle",
845         "Shanai",
846         "Tinkle Bell",
847         "Agogo",
848         "Steel Drums",
849         "Woodblock",
850         "Taiko Drum",
851         "Melodic Tom",
852         "Synth Drum",
853         "Reverse Cymbal",
854         "Guitar Fret Noise",
855         "Breath Noise",
856         "Seashore",
857         "Bird Tweet",
858         "Telephone Ring",
859         "Helicopter",
860         "Applause",
861         "Gunshot",
862 };
863
864 } //namespace Name
865
866 } //namespace MIDI
867