Mercurial > hg > svapp
comparison audioio/AudioGenerator.cpp @ 278:7be7b43b7264 tonioni
Add FlexiNoteModel support
author | Chris Cannam |
---|---|
date | Mon, 15 Apr 2013 17:57:47 +0100 |
parents | e647e880e711 |
children | cf32a7c584c2 |
comparison
equal
deleted
inserted
replaced
277:e647e880e711 | 278:7be7b43b7264 |
---|---|
20 #include "base/PlayParameterRepository.h" | 20 #include "base/PlayParameterRepository.h" |
21 #include "base/Pitch.h" | 21 #include "base/Pitch.h" |
22 #include "base/Exceptions.h" | 22 #include "base/Exceptions.h" |
23 | 23 |
24 #include "data/model/NoteModel.h" | 24 #include "data/model/NoteModel.h" |
25 #include "data/model/FlexiNoteModel.h" | |
25 #include "data/model/DenseTimeValueModel.h" | 26 #include "data/model/DenseTimeValueModel.h" |
26 #include "data/model/SparseOneDimensionalModel.h" | 27 #include "data/model/SparseOneDimensionalModel.h" |
27 | 28 |
28 #include "plugin/RealTimePluginFactory.h" | 29 #include "plugin/RealTimePluginFactory.h" |
29 #include "plugin/RealTimePluginInstance.h" | 30 #include "plugin/RealTimePluginInstance.h" |
393 if (dtvm) { | 394 if (dtvm) { |
394 return mixDenseTimeValueModel(dtvm, startFrame, frameCount, | 395 return mixDenseTimeValueModel(dtvm, startFrame, frameCount, |
395 buffer, gain, pan, fadeIn, fadeOut); | 396 buffer, gain, pan, fadeIn, fadeOut); |
396 } | 397 } |
397 | 398 |
398 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> | 399 bool synthetic = |
399 (model); | 400 (qobject_cast<SparseOneDimensionalModel *>(model) || |
400 if (sodm) { | 401 qobject_cast<NoteModel *>(model) || |
401 return mixSyntheticNoteModel(model, startFrame, frameCount, | 402 qobject_cast<FlexiNoteModel *>(model)); |
402 buffer, gain, pan, fadeIn, fadeOut); | 403 |
403 } | 404 if (synthetic) { |
404 | |
405 NoteModel *nm = dynamic_cast<NoteModel *>(model); | |
406 if (nm) { | |
407 return mixSyntheticNoteModel(model, startFrame, frameCount, | 405 return mixSyntheticNoteModel(model, startFrame, frameCount, |
408 buffer, gain, pan, fadeIn, fadeOut); | 406 buffer, gain, pan, fadeIn, fadeOut); |
409 } | 407 } |
410 | 408 |
411 std::cerr << "AudioGenerator::mixModel: WARNING: Model " << model << " of type " << model->getTypeName() << " is marked as playable, but I have no mechanism to play it" << std::endl; | 409 std::cerr << "AudioGenerator::mixModel: WARNING: Model " << model << " of type " << model->getTypeName() << " is marked as playable, but I have no mechanism to play it" << std::endl; |
720 } | 718 } |
721 | 719 |
722 return notes; | 720 return notes; |
723 } | 721 } |
724 | 722 |
723 FlexiNoteModel *fnm = qobject_cast<FlexiNoteModel *>(model); | |
724 | |
725 if (fnm) { | |
726 | |
727 // currently identical to NoteModel case above | |
728 | |
729 FlexiNoteModel::PointList points = | |
730 fnm->getPoints(startFrame, endFrame); | |
731 | |
732 for (FlexiNoteModel::PointList::iterator pli = | |
733 points.begin(); pli != points.end(); ++pli) { | |
734 | |
735 size_t duration = pli->duration; | |
736 if (duration == 0 || duration == 1) { | |
737 duration = m_sourceSampleRate / 20; | |
738 } | |
739 | |
740 int pitch = lrintf(pli->value); | |
741 | |
742 int velocity = 100; | |
743 if (pli->level > 0.f && pli->level <= 1.f) { | |
744 velocity = lrintf(pli->level * 127); | |
745 } | |
746 | |
747 NoteData note(pli->frame, | |
748 duration, | |
749 pitch, | |
750 velocity); | |
751 | |
752 if (fnm->getScaleUnits() == "Hz") { | |
753 note.frequency = pli->value; | |
754 note.isMidiPitchQuantized = false; | |
755 } | |
756 | |
757 notes.push_back(note); | |
758 } | |
759 | |
760 return notes; | |
761 } | |
762 | |
725 return notes; | 763 return notes; |
726 } | 764 } |
727 | 765 |