Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"add/remove" events options added to midi event list class #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/MidiEventList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -58,6 +61,3 @@ class MidiEventList {


#endif /* _MIDIEVENTLIST_H_INCLUDED */



35 changes: 33 additions & 2 deletions src-library/MidiEventList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


//////////////////////////////
//
Expand Down Expand Up @@ -404,5 +437,3 @@ MidiEventList& MidiEventList::operator=(MidiEventList other) {
list.swap(other.list);
return *this;
}