Skip to content

Commit

Permalink
Replace containers by outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviliz committed Jul 2, 2024
1 parent 5594eb6 commit 0d28456
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
22 changes: 9 additions & 13 deletions src/algorithms/tonal/pitch2midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void Pitch2Midi::setOutputs(Real midiNoteNumberValue, float onsetTimeCompensatio
vector<Real>& timeCompensation = _timeCompensation.get();

// reuse bins
_messageTypeBin.resize(0);
_midiNoteNumberBin.resize(0);
_timeCompensationBin.resize(0);
messageType.resize(0);
midiNoteNumber.resize(0);
timeCompensation.resize(0);

// TODO: this is not clear because it might remove an note_off message which is defined by dnote.
//#! it would be better just to provide some code for midiNoteNumbre when this happens
Expand All @@ -111,26 +111,22 @@ void Pitch2Midi::setOutputs(Real midiNoteNumberValue, float onsetTimeCompensatio

// let's define first the message type
if (_noteOff) {
_messageTypeBin.push_back("note_off");
messageType.push_back("note_off");
}

if (_noteOn) {
_messageTypeBin.push_back("note_on");
messageType.push_back("note_on");
}

if (!_applyCompensation) {
onsetTimeCompensation = 0.f;
offsetTimeCompensation = 0.f;
}

_midiNoteNumberBin.push_back(dnote);
_midiNoteNumberBin.push_back(midiNoteNumberValue);
_timeCompensationBin.push_back(offsetTimeCompensation);
_timeCompensationBin.push_back(onsetTimeCompensation);

messageType = _messageTypeBin;
midiNoteNumber = _midiNoteNumberBin;
timeCompensation = _timeCompensationBin;
midiNoteNumber.push_back(dnote);
midiNoteNumber.push_back(midiNoteNumberValue);
timeCompensation.push_back(offsetTimeCompensation);
timeCompensation.push_back(onsetTimeCompensation);
}

void Pitch2Midi::push(Real midiNoteNumber) {
Expand Down
7 changes: 2 additions & 5 deletions src/algorithms/tonal/pitch2midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ namespace standard {
// Containers
std::vector<Real> _midiNoteNumberVector; // always size 1, but frameBuffer algo expects vectors as input
std::vector<Real> _buffer;
std::vector<Real> _midiNoteNumberBin; // should be a vector of integers
std::vector<Real> _timeCompensationBin;
std::vector<std::string> _messageTypeBin;

int capacity();
bool hasCoherence();
Expand Down Expand Up @@ -91,8 +88,8 @@ namespace standard {
void declareParameters() {
declareParameter("sampleRate", "Audio sample rate", "[8000,inf)", 44100);
declareParameter("hopSize", "Pitch Detection analysis hop size in samples, equivalent to I/O buffer size", "[1,inf)", 128);
declareParameter("minFrequency", "minimum detectable frequency", "[20,20000]", 60.f);
declareParameter("minOcurrenceRate", "minimum number of times a midi note has to ocur compared to total capacity", "[0,1]", 0.5f);
declareParameter("minFrequency", "minimum detectable frequency", "[20,20000]", 60.0);
declareParameter("minOcurrenceRate", "minimum number of times a midi note has to ocur compared to total capacity", "[0,1]", 0.5);
declareParameter("midiBufferDuration", "duration in seconds of buffer used for voting in the note toggle detection algorithm", "[0.005,0.5]", 0.015); // 15ms
declareParameter("minNoteChangePeriod", "minimum time to wait until a note change is detected", "(0,1]", 0.030);
declareParameter("minOnsetCheckPeriod", "minimum time to wait until an onset is detected", "(0,1]", 0.075);
Expand Down

0 comments on commit 0d28456

Please sign in to comment.