* fixed memory management bugs for midi patchname handling

git-svn-id: svn://localhost/ardour2/branches/3.0@4310 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Hans Baier 2008-12-12 05:17:53 +00:00
parent ddbd296698
commit 2c017baa4a
7 changed files with 47 additions and 39 deletions

View file

@ -7,10 +7,11 @@ using namespace std;
void void
CanvasFlag::set_text(string a_text) CanvasFlag::set_text(string& a_text)
{ {
if (_text) { if (_text) {
delete _text; delete _text;
_text = 0;
} }
_text = new Text(*this, 0.0, 0.0, a_text); _text = new Text(*this, 0.0, 0.0, a_text);

View file

@ -38,7 +38,7 @@ public:
virtual ~CanvasFlag(); virtual ~CanvasFlag();
void set_text(string a_text); void set_text(string& a_text);
protected: protected:
Text* _text; Text* _text;

View file

@ -8,7 +8,7 @@ using namespace std;
CanvasProgramChange::CanvasProgramChange( CanvasProgramChange::CanvasProgramChange(
MidiRegionView& region, MidiRegionView& region,
Group& parent, Group& parent,
string text, string& text,
double height, double height,
double x, double x,
double y) double y)

View file

@ -14,7 +14,7 @@ public:
CanvasProgramChange( CanvasProgramChange(
MidiRegionView& region, MidiRegionView& region,
Group& parent, Group& parent,
string text, string& text,
double height, double height,
double x = 0.0, double x = 0.0,
double y = 0.0 double y = 0.0

View file

@ -645,7 +645,7 @@ MidiRegionView::find_and_insert_program_change_flags()
boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device
= MIDI::Name::MidiPatchManager::instance().master_device_by_model(_model_name); = MIDI::Name::MidiPatchManager::instance().master_device_by_model(_model_name);
MIDI::Name::Patch patch; boost::shared_ptr<MIDI::Name::Patch> patch;
if (master_device != 0 && _custom_device_mode != "") { if (master_device != 0 && _custom_device_mode != "") {
uint8_t msb = 0; uint8_t msb = 0;
@ -670,8 +670,8 @@ MidiRegionView::find_and_insert_program_change_flags()
//cerr << " got patch with name " << patch.name() << " number " << patch.number() << endl; //cerr << " got patch with name " << patch.name() << " number " << patch.number() << endl;
} }
if (patch.name() != "") { if (patch != 0) {
add_pgm_change(event_time, patch.name()); add_pgm_change(event_time, patch->name());
} else { } else {
char buf[4]; char buf[4];
snprintf(buf, 4, "%d", int(program_number)); snprintf(buf, 4, "%d", int(program_number));

View file

@ -56,6 +56,13 @@ public:
0 <= program_number <= 127; 0 <= program_number <= 127;
} }
inline PatchPrimaryKey& operator=(const PatchPrimaryKey& id) {
msb = id.msb;
lsb = id.lsb;
program_number = id.program_number;
return *this;
}
inline bool operator==(const PatchPrimaryKey& id) const { inline bool operator==(const PatchPrimaryKey& id) const {
return (msb == id.msb && lsb == id.lsb && program_number == id.program_number); return (msb == id.msb && lsb == id.lsb && program_number == id.program_number);
} }
@ -79,7 +86,7 @@ public:
class Patch : public PBD::Stateful class Patch : public PBD::Stateful
{ {
public: public:
typedef std::list<Evoral::Event> PatchMidiCommands; typedef std::list<boost::shared_ptr<Evoral::MIDIEvent> > PatchMidiCommands;
Patch() {}; Patch() {};
Patch(string a_number, string a_name) : _number(a_number), _name(a_name) {}; Patch(string a_number, string a_name) : _number(a_number), _name(a_name) {};
@ -108,7 +115,7 @@ private:
class PatchBank : public PBD::Stateful class PatchBank : public PBD::Stateful
{ {
public: public:
typedef std::list<Patch> PatchNameList; typedef std::list<boost::shared_ptr<Patch> > PatchNameList;
PatchBank() {}; PatchBank() {};
virtual ~PatchBank() {}; virtual ~PatchBank() {};
@ -130,9 +137,9 @@ private:
class ChannelNameSet : public PBD::Stateful class ChannelNameSet : public PBD::Stateful
{ {
public: public:
typedef std::set<uint8_t> AvailableForChannels; typedef std::set<uint8_t> AvailableForChannels;
typedef std::list<PatchBank> PatchBanks; typedef std::list<boost::shared_ptr<PatchBank> > PatchBanks;
typedef std::map<PatchPrimaryKey, Patch> PatchMap; typedef std::map<PatchPrimaryKey, boost::shared_ptr<Patch> > PatchMap;
ChannelNameSet() {}; ChannelNameSet() {};
virtual ~ChannelNameSet() {}; virtual ~ChannelNameSet() {};
@ -145,7 +152,7 @@ public:
return _available_for_channels.find(channel) != _available_for_channels.end(); return _available_for_channels.find(channel) != _available_for_channels.end();
} }
Patch& find_patch(uint8_t msb, uint8_t lsb, uint8_t program_number) { boost::shared_ptr<Patch> find_patch(uint8_t msb, uint8_t lsb, uint8_t program_number) {
PatchPrimaryKey key(msb, lsb, program_number); PatchPrimaryKey key(msb, lsb, program_number);
assert(key.is_sane()); assert(key.is_sane());
return _patch_map[key]; return _patch_map[key];
@ -185,7 +192,7 @@ private:
class NoteNameList : public PBD::Stateful class NoteNameList : public PBD::Stateful
{ {
public: public:
typedef std::list<Note> Notes; typedef std::list<boost::shared_ptr<Note> > Notes;
NoteNameList() {}; NoteNameList() {};
NoteNameList(string a_name) : _name(a_name) {}; NoteNameList(string a_name) : _name(a_name) {};
~NoteNameList() {}; ~NoteNameList() {};
@ -233,11 +240,11 @@ class MasterDeviceNames : public PBD::Stateful
public: public:
typedef std::list<std::string> Models; typedef std::list<std::string> Models;
/// maps name to CustomDeviceMode /// maps name to CustomDeviceMode
typedef std::map<std::string, CustomDeviceMode> CustomDeviceModes; typedef std::map<std::string, boost::shared_ptr<CustomDeviceMode> > CustomDeviceModes;
typedef std::list<std::string> CustomDeviceModeNames; typedef std::list<std::string> CustomDeviceModeNames;
/// maps name to ChannelNameSet /// maps name to ChannelNameSet
typedef std::map<std::string, ChannelNameSet> ChannelNameSets; typedef std::map<std::string, boost::shared_ptr<ChannelNameSet> > ChannelNameSets;
typedef std::list<NoteNameList> NoteNameLists; typedef std::list<boost::shared_ptr<NoteNameList> > NoteNameLists;
MasterDeviceNames() {}; MasterDeviceNames() {};
@ -251,17 +258,17 @@ public:
const CustomDeviceModeNames& custom_device_mode_names() const { return _custom_device_mode_names; } const CustomDeviceModeNames& custom_device_mode_names() const { return _custom_device_mode_names; }
CustomDeviceMode& custom_device_mode_by_name(string& mode_name) { boost::shared_ptr<CustomDeviceMode> custom_device_mode_by_name(string mode_name) {
assert(mode_name != ""); assert(mode_name != "");
return _custom_device_modes[mode_name]; return _custom_device_modes[mode_name];
} }
ChannelNameSet& channel_name_set_by_device_mode_and_channel(string mode, uint8_t channel) { boost::shared_ptr<ChannelNameSet> channel_name_set_by_device_mode_and_channel(string mode, uint8_t channel) {
return _channel_name_sets[custom_device_mode_by_name(mode).channel_name_set_name_by_channel(channel)]; return _channel_name_sets[custom_device_mode_by_name(mode)->channel_name_set_name_by_channel(channel)];
} }
Patch& find_patch(string mode, uint8_t channel, uint8_t msb, uint8_t lsb, uint8_t program_number) { boost::shared_ptr<Patch> find_patch(string mode, uint8_t channel, uint8_t msb, uint8_t lsb, uint8_t program_number) {
return channel_name_set_by_device_mode_and_channel(mode, channel).find_patch(msb, lsb, program_number); return channel_name_set_by_device_mode_and_channel(mode, channel)->find_patch(msb, lsb, program_number);
} }
XMLNode& get_state (void); XMLNode& get_state (void);

View file

@ -58,7 +58,7 @@ Patch::set_state (const XMLNode& node)
assert(commands); assert(commands);
const XMLNodeList events = commands->children(); const XMLNodeList events = commands->children();
for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) { for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) {
_patch_midi_commands.push_back(*(new Evoral::MIDIEvent(*(*i)))); _patch_midi_commands.push_back(boost::shared_ptr<Evoral::MIDIEvent> (new Evoral::MIDIEvent(*(*i))));
XMLNode* node = *i; XMLNode* node = *i;
if (node->name() == "ControlChange") { if (node->name() == "ControlChange") {
string control = node->property("Control")->value(); string control = node->property("Control")->value();
@ -121,9 +121,9 @@ NoteNameList::set_state (const XMLNode& node)
boost::shared_ptr<XMLSharedNodeList> notes = boost::shared_ptr<XMLSharedNodeList> notes =
node.find("//Note"); node.find("//Note");
for (XMLSharedNodeList::const_iterator i = notes->begin(); i != notes->end(); ++i) { for (XMLSharedNodeList::const_iterator i = notes->begin(); i != notes->end(); ++i) {
Note* note = new Note(); boost::shared_ptr<Note> note(new Note());
note->set_state(*(*i)); note->set_state(*(*i));
_notes.push_back(*note); _notes.push_back(note);
} }
return 0; return 0;
@ -139,7 +139,7 @@ PatchBank::get_state (void)
for (PatchNameList::iterator patch = _patch_name_list.begin(); for (PatchNameList::iterator patch = _patch_name_list.begin();
patch != _patch_name_list.end(); patch != _patch_name_list.end();
++patch) { ++patch) {
patch_name_list->add_child_nocopy(patch->get_state()); patch_name_list->add_child_nocopy((*patch)->get_state());
} }
return *node; return *node;
@ -154,9 +154,9 @@ PatchBank::set_state (const XMLNode& node)
assert(patch_name_list); assert(patch_name_list);
const XMLNodeList patches = patch_name_list->children(); const XMLNodeList patches = patch_name_list->children();
for (XMLNodeList::const_iterator i = patches.begin(); i != patches.end(); ++i) { for (XMLNodeList::const_iterator i = patches.begin(); i != patches.end(); ++i) {
Patch* patch = new Patch(); boost::shared_ptr<Patch> patch(new Patch());
patch->set_state(*(*i)); patch->set_state(*(*i));
_patch_name_list.push_back(*patch); _patch_name_list.push_back(patch);
} }
return 0; return 0;
@ -187,7 +187,7 @@ ChannelNameSet::get_state (void)
for (PatchBanks::iterator patch_bank = _patch_banks.begin(); for (PatchBanks::iterator patch_bank = _patch_banks.begin();
patch_bank != _patch_banks.end(); patch_bank != _patch_banks.end();
++patch_bank) { ++patch_bank) {
node->add_child_nocopy(patch_bank->get_state()); node->add_child_nocopy((*patch_bank)->get_state());
} }
return *node; return *node;
@ -221,14 +221,14 @@ ChannelNameSet::set_state (const XMLNode& node)
if (node->name() == "PatchBank") { if (node->name() == "PatchBank") {
// cerr << "got PatchBank" << endl; // cerr << "got PatchBank" << endl;
PatchBank* bank = new PatchBank(); boost::shared_ptr<PatchBank> bank(new PatchBank());
bank->set_state(*node); bank->set_state(*node);
_patch_banks.push_back(*bank); _patch_banks.push_back(bank);
const PatchBank::PatchNameList& patches = bank->patch_name_list(); const PatchBank::PatchNameList& patches = bank->patch_name_list();
for (PatchBank::PatchNameList::const_iterator patch = patches.begin(); for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
patch != patches.end(); patch != patches.end();
++patch) { ++patch) {
_patch_map[patch->patch_primary_key()] = *patch; _patch_map[(*patch)->patch_primary_key()] = *patch;
} }
// cerr << "after PatchBank pushback" << endl; // cerr << "after PatchBank pushback" << endl;
} }
@ -254,7 +254,7 @@ CustomDeviceMode::set_state(const XMLNode& a_node)
int channel = atoi((*i)->property("Channel")->value().c_str()); int channel = atoi((*i)->property("Channel")->value().c_str());
string name_set = (*i)->property("NameSet")->value(); string name_set = (*i)->property("NameSet")->value();
assert( 1 <= channel && channel <= 16 ); assert( 1 <= channel && channel <= 16 );
_channel_name_set_assignments[channel -1] = name_set; _channel_name_set_assignments[channel - 1] = name_set;
} }
return 0; return 0;
} }
@ -305,10 +305,10 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
for (XMLSharedNodeList::iterator i = custom_device_modes->begin(); for (XMLSharedNodeList::iterator i = custom_device_modes->begin();
i != custom_device_modes->end(); i != custom_device_modes->end();
++i) { ++i) {
CustomDeviceMode* custom_device_mode = new CustomDeviceMode(); boost::shared_ptr<CustomDeviceMode> custom_device_mode(new CustomDeviceMode());
custom_device_mode->set_state(*(*i)); custom_device_mode->set_state(*(*i));
_custom_device_modes[custom_device_mode->name()] = *custom_device_mode; _custom_device_modes[custom_device_mode->name()] = custom_device_mode;
_custom_device_mode_names.push_back(custom_device_mode->name()); _custom_device_mode_names.push_back(custom_device_mode->name());
} }
@ -318,10 +318,10 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
for (XMLSharedNodeList::iterator i = channel_name_sets->begin(); for (XMLSharedNodeList::iterator i = channel_name_sets->begin();
i != channel_name_sets->end(); i != channel_name_sets->end();
++i) { ++i) {
ChannelNameSet* channel_name_set = new ChannelNameSet(); boost::shared_ptr<ChannelNameSet> channel_name_set(new ChannelNameSet());
// cerr << "MasterDeviceNames::set_state ChannelNameSet before set_state" << endl; // cerr << "MasterDeviceNames::set_state ChannelNameSet before set_state" << endl;
channel_name_set->set_state(*(*i)); channel_name_set->set_state(*(*i));
_channel_name_sets[channel_name_set->name()] = *channel_name_set; _channel_name_sets[channel_name_set->name()] = channel_name_set;
} }
// cerr << "MasterDeviceNames::set_state NoteNameLists" << endl; // cerr << "MasterDeviceNames::set_state NoteNameLists" << endl;
@ -330,9 +330,9 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
for (XMLSharedNodeList::iterator i = note_name_lists->begin(); for (XMLSharedNodeList::iterator i = note_name_lists->begin();
i != note_name_lists->end(); i != note_name_lists->end();
++i) { ++i) {
NoteNameList* note_name_list = new NoteNameList(); boost::shared_ptr<NoteNameList> note_name_list(new NoteNameList());
note_name_list->set_state(*(*i)); note_name_list->set_state(*(*i));
_note_name_lists.push_back(*note_name_list); _note_name_lists.push_back(note_name_list);
} }
return 0; return 0;