mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
* 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:
parent
ddbd296698
commit
2c017baa4a
7 changed files with 47 additions and 39 deletions
|
|
@ -7,10 +7,11 @@ using namespace std;
|
|||
|
||||
|
||||
void
|
||||
CanvasFlag::set_text(string a_text)
|
||||
CanvasFlag::set_text(string& a_text)
|
||||
{
|
||||
if (_text) {
|
||||
delete _text;
|
||||
_text = 0;
|
||||
}
|
||||
|
||||
_text = new Text(*this, 0.0, 0.0, a_text);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
virtual ~CanvasFlag();
|
||||
|
||||
void set_text(string a_text);
|
||||
void set_text(string& a_text);
|
||||
|
||||
protected:
|
||||
Text* _text;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using namespace std;
|
|||
CanvasProgramChange::CanvasProgramChange(
|
||||
MidiRegionView& region,
|
||||
Group& parent,
|
||||
string text,
|
||||
string& text,
|
||||
double height,
|
||||
double x,
|
||||
double y)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public:
|
|||
CanvasProgramChange(
|
||||
MidiRegionView& region,
|
||||
Group& parent,
|
||||
string text,
|
||||
string& text,
|
||||
double height,
|
||||
double x = 0.0,
|
||||
double y = 0.0
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ MidiRegionView::find_and_insert_program_change_flags()
|
|||
boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device
|
||||
= 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 != "") {
|
||||
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;
|
||||
}
|
||||
if (patch.name() != "") {
|
||||
add_pgm_change(event_time, patch.name());
|
||||
if (patch != 0) {
|
||||
add_pgm_change(event_time, patch->name());
|
||||
} else {
|
||||
char buf[4];
|
||||
snprintf(buf, 4, "%d", int(program_number));
|
||||
|
|
|
|||
|
|
@ -56,6 +56,13 @@ public:
|
|||
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 {
|
||||
return (msb == id.msb && lsb == id.lsb && program_number == id.program_number);
|
||||
}
|
||||
|
|
@ -79,7 +86,7 @@ public:
|
|||
class Patch : public PBD::Stateful
|
||||
{
|
||||
public:
|
||||
typedef std::list<Evoral::Event> PatchMidiCommands;
|
||||
typedef std::list<boost::shared_ptr<Evoral::MIDIEvent> > PatchMidiCommands;
|
||||
|
||||
Patch() {};
|
||||
Patch(string a_number, string a_name) : _number(a_number), _name(a_name) {};
|
||||
|
|
@ -108,7 +115,7 @@ private:
|
|||
class PatchBank : public PBD::Stateful
|
||||
{
|
||||
public:
|
||||
typedef std::list<Patch> PatchNameList;
|
||||
typedef std::list<boost::shared_ptr<Patch> > PatchNameList;
|
||||
|
||||
PatchBank() {};
|
||||
virtual ~PatchBank() {};
|
||||
|
|
@ -131,8 +138,8 @@ class ChannelNameSet : public PBD::Stateful
|
|||
{
|
||||
public:
|
||||
typedef std::set<uint8_t> AvailableForChannels;
|
||||
typedef std::list<PatchBank> PatchBanks;
|
||||
typedef std::map<PatchPrimaryKey, Patch> PatchMap;
|
||||
typedef std::list<boost::shared_ptr<PatchBank> > PatchBanks;
|
||||
typedef std::map<PatchPrimaryKey, boost::shared_ptr<Patch> > PatchMap;
|
||||
|
||||
ChannelNameSet() {};
|
||||
virtual ~ChannelNameSet() {};
|
||||
|
|
@ -145,7 +152,7 @@ public:
|
|||
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);
|
||||
assert(key.is_sane());
|
||||
return _patch_map[key];
|
||||
|
|
@ -185,7 +192,7 @@ private:
|
|||
class NoteNameList : public PBD::Stateful
|
||||
{
|
||||
public:
|
||||
typedef std::list<Note> Notes;
|
||||
typedef std::list<boost::shared_ptr<Note> > Notes;
|
||||
NoteNameList() {};
|
||||
NoteNameList(string a_name) : _name(a_name) {};
|
||||
~NoteNameList() {};
|
||||
|
|
@ -233,11 +240,11 @@ class MasterDeviceNames : public PBD::Stateful
|
|||
public:
|
||||
typedef std::list<std::string> Models;
|
||||
/// 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;
|
||||
/// maps name to ChannelNameSet
|
||||
typedef std::map<std::string, ChannelNameSet> ChannelNameSets;
|
||||
typedef std::list<NoteNameList> NoteNameLists;
|
||||
typedef std::map<std::string, boost::shared_ptr<ChannelNameSet> > ChannelNameSets;
|
||||
typedef std::list<boost::shared_ptr<NoteNameList> > NoteNameLists;
|
||||
|
||||
|
||||
MasterDeviceNames() {};
|
||||
|
|
@ -251,17 +258,17 @@ public:
|
|||
|
||||
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 != "");
|
||||
return _custom_device_modes[mode_name];
|
||||
}
|
||||
|
||||
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)];
|
||||
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)];
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
XMLNode& get_state (void);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ Patch::set_state (const XMLNode& node)
|
|||
assert(commands);
|
||||
const XMLNodeList events = commands->children();
|
||||
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;
|
||||
if (node->name() == "ControlChange") {
|
||||
string control = node->property("Control")->value();
|
||||
|
|
@ -121,9 +121,9 @@ NoteNameList::set_state (const XMLNode& node)
|
|||
boost::shared_ptr<XMLSharedNodeList> notes =
|
||||
node.find("//Note");
|
||||
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));
|
||||
_notes.push_back(*note);
|
||||
_notes.push_back(note);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -139,7 +139,7 @@ PatchBank::get_state (void)
|
|||
for (PatchNameList::iterator patch = _patch_name_list.begin();
|
||||
patch != _patch_name_list.end();
|
||||
++patch) {
|
||||
patch_name_list->add_child_nocopy(patch->get_state());
|
||||
patch_name_list->add_child_nocopy((*patch)->get_state());
|
||||
}
|
||||
|
||||
return *node;
|
||||
|
|
@ -154,9 +154,9 @@ PatchBank::set_state (const XMLNode& node)
|
|||
assert(patch_name_list);
|
||||
const XMLNodeList patches = patch_name_list->children();
|
||||
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_name_list.push_back(*patch);
|
||||
_patch_name_list.push_back(patch);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -187,7 +187,7 @@ ChannelNameSet::get_state (void)
|
|||
for (PatchBanks::iterator patch_bank = _patch_banks.begin();
|
||||
patch_bank != _patch_banks.end();
|
||||
++patch_bank) {
|
||||
node->add_child_nocopy(patch_bank->get_state());
|
||||
node->add_child_nocopy((*patch_bank)->get_state());
|
||||
}
|
||||
|
||||
return *node;
|
||||
|
|
@ -221,14 +221,14 @@ ChannelNameSet::set_state (const XMLNode& node)
|
|||
|
||||
if (node->name() == "PatchBank") {
|
||||
// cerr << "got PatchBank" << endl;
|
||||
PatchBank* bank = new PatchBank();
|
||||
boost::shared_ptr<PatchBank> bank(new PatchBank());
|
||||
bank->set_state(*node);
|
||||
_patch_banks.push_back(*bank);
|
||||
_patch_banks.push_back(bank);
|
||||
const PatchBank::PatchNameList& patches = bank->patch_name_list();
|
||||
for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
|
||||
patch != patches.end();
|
||||
++patch) {
|
||||
_patch_map[patch->patch_primary_key()] = *patch;
|
||||
_patch_map[(*patch)->patch_primary_key()] = *patch;
|
||||
}
|
||||
// cerr << "after PatchBank pushback" << endl;
|
||||
}
|
||||
|
|
@ -305,10 +305,10 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
|
|||
for (XMLSharedNodeList::iterator i = custom_device_modes->begin();
|
||||
i != custom_device_modes->end();
|
||||
++i) {
|
||||
CustomDeviceMode* custom_device_mode = new CustomDeviceMode();
|
||||
boost::shared_ptr<CustomDeviceMode> custom_device_mode(new CustomDeviceMode());
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
@ -318,10 +318,10 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
|
|||
for (XMLSharedNodeList::iterator i = channel_name_sets->begin();
|
||||
i != channel_name_sets->end();
|
||||
++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;
|
||||
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;
|
||||
|
|
@ -330,9 +330,9 @@ MasterDeviceNames::set_state(const XMLNode& a_node)
|
|||
for (XMLSharedNodeList::iterator i = note_name_lists->begin();
|
||||
i != note_name_lists->end();
|
||||
++i) {
|
||||
NoteNameList* note_name_list = new NoteNameList();
|
||||
boost::shared_ptr<NoteNameList> note_name_list(new NoteNameList());
|
||||
note_name_list->set_state(*(*i));
|
||||
_note_name_lists.push_back(*note_name_list);
|
||||
_note_name_lists.push_back(note_name_list);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue