diff --git a/include/MidiEventList.h b/include/MidiEventList.h index d7a5c3cc..b84cb48f 100644 --- a/include/MidiEventList.h +++ b/include/MidiEventList.h @@ -45,6 +45,9 @@ class MidiEventList { int push_back (MidiEvent& event); int append (MidiEvent& event); + int remove (int index); + int insert (int index, MidiEvent& event); + // careful when using these, intended for internal use in MidiFile class: void detach (void); int push_back_no_copy (MidiEvent* event); @@ -58,6 +61,3 @@ class MidiEventList { #endif /* _MIDIEVENTLIST_H_INCLUDED */ - - - diff --git a/src-library/MidiEventList.cpp b/src-library/MidiEventList.cpp index e6b4e6c9..b5b30478 100644 --- a/src-library/MidiEventList.cpp +++ b/src-library/MidiEventList.cpp @@ -197,6 +197,39 @@ int MidiEventList::push_back(MidiEvent& event) { return append(event); } +////////////////////////////// +// +// MidiEventList::remove -- deletes a MidiEvent at the specified index. If +// the index is invalid then the request is ignored and -1 is returned. +// If the index is valid then the new size of the list is returned. +// +int MidiEventList::remove(int index) { + if ( ( index >=0 ) && ( index < (int)list.size() ) ) { + delete list[ index ]; + list.erase(list.begin() + index); + return (int)list.size()-1; + } else { + return -1; + } +} + + +////////////////////////////// +// +// MidiEventList::add -- inserts a MidiEvent at the specified index. If +// the index is invalid then the request is ignored and -1 is returned. +// If the index is valid then the new size of the list is returned. +// +int MidiEventList::insert(int index, MidiEvent& event) { + if ( ( index >=0 ) && ( index < (int)list.size() ) ) { + MidiEvent* ptr = new MidiEvent(event); + list.insert(list.begin()+index, ptr); + return (int)list.size()-1; + } else { + return -1; + } +} + ////////////////////////////// // @@ -404,5 +437,3 @@ MidiEventList& MidiEventList::operator=(MidiEventList other) { list.swap(other.list); return *this; } - -