summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-09-24 11:16:02 +0200
committerJohn Glover <j@johnglover.net>2012-09-24 11:16:02 +0200
commit542b19a0b4a48fab3b1f773caa889e52ce417e85 (patch)
tree4176525988a0ff55c442f12ad3c686e1360b5c9f /src
parentda54d866baf09046d3142386f049e14e1955f921 (diff)
downloadsimpl-542b19a0b4a48fab3b1f773caa889e52ce417e85.tar.gz
simpl-542b19a0b4a48fab3b1f773caa889e52ce417e85.tar.bz2
simpl-542b19a0b4a48fab3b1f773caa889e52ce417e85.zip
[base] Bug fix: set peak and partial vectors to
NULL when clearing rather than emptying the vectors. Check that current number of peaks/partials does not excede the max when adding new peaks/partials.
Diffstat (limited to 'src')
-rw-r--r--src/simpl/base.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp
index c97e8bc..75e0697 100644
--- a/src/simpl/base.cpp
+++ b/src/simpl/base.cpp
@@ -98,12 +98,12 @@ void Frame::clear() {
}
void Frame::clear_peaks() {
- _peaks.clear();
+ _peaks.assign(_max_peaks, NULL);
_num_peaks = 0;
}
void Frame::clear_partials() {
- _partials.clear();
+ _partials.assign(_max_peaks, NULL);
_num_partials = 0;
}
@@ -144,6 +144,13 @@ void Frame::max_peaks(int new_max_peaks) {
}
void Frame::add_peak(Peak* peak) {
+ if(_num_peaks >= _max_peaks) {
+ printf("Warning: attempted to add more than the specified"
+ " maximum number of peaks (%d) to a frame, ignoring.\n",
+ _max_peaks);
+ return;
+ }
+
_peaks[_num_peaks] = peak;
_num_peaks++;
}
@@ -184,6 +191,13 @@ void Frame::max_partials(int new_max_partials) {
}
void Frame::add_partial(Peak* peak) {
+ if(_num_partials >= _max_partials) {
+ printf("Warning: attempted to add more than the specified"
+ " maximum number of partials (%d) to a frame, ignoring.\n",
+ _max_partials);
+ return;
+ }
+
_partials[_num_partials] = peak;
_num_partials++;
}