Mercurial > hg > svapp
comparison audioio/AudioGenerator.cpp @ 299:ae1eedd6951f tonioni
Use NoteExportable, now in svcore, to generate note data
author | Chris Cannam |
---|---|
date | Mon, 02 Dec 2013 17:12:27 +0000 |
parents | 14b1768e5406 |
children | 9716c75499ef |
comparison
equal
deleted
inserted
replaced
298:e22642bcb07b | 299:ae1eedd6951f |
---|---|
23 | 23 |
24 #include "data/model/NoteModel.h" | 24 #include "data/model/NoteModel.h" |
25 #include "data/model/FlexiNoteModel.h" | 25 #include "data/model/FlexiNoteModel.h" |
26 #include "data/model/DenseTimeValueModel.h" | 26 #include "data/model/DenseTimeValueModel.h" |
27 #include "data/model/SparseOneDimensionalModel.h" | 27 #include "data/model/SparseOneDimensionalModel.h" |
28 #include "data/model/NoteData.h" | |
28 | 29 |
29 #include "plugin/RealTimePluginFactory.h" | 30 #include "plugin/RealTimePluginFactory.h" |
30 #include "plugin/RealTimePluginInstance.h" | 31 #include "plugin/RealTimePluginInstance.h" |
31 #include "plugin/PluginIdentifier.h" | 32 #include "plugin/PluginIdentifier.h" |
32 #include "plugin/PluginXml.h" | 33 #include "plugin/PluginXml.h" |
549 | 550 |
550 for (size_t i = 0; i < blocks; ++i) { | 551 for (size_t i = 0; i < blocks; ++i) { |
551 | 552 |
552 size_t reqStart = startFrame + i * m_pluginBlockSize; | 553 size_t reqStart = startFrame + i * m_pluginBlockSize; |
553 | 554 |
554 NoteList notes = getNotes(model, | 555 NoteList notes; |
555 reqStart + latency, | 556 NoteExportable *exportable = dynamic_cast<NoteExportable *>(model); |
556 reqStart + latency + m_pluginBlockSize); | 557 if (exportable) { |
558 notes = exportable->getNotes(reqStart + latency, | |
559 reqStart + latency + m_pluginBlockSize); | |
560 } | |
557 | 561 |
558 Vamp::RealTime blockTime = Vamp::RealTime::frame2RealTime | 562 Vamp::RealTime blockTime = Vamp::RealTime::frame2RealTime |
559 (startFrame + i * m_pluginBlockSize, m_sourceSampleRate); | 563 (startFrame + i * m_pluginBlockSize, m_sourceSampleRate); |
560 | 564 |
561 for (NoteList::const_iterator ni = notes.begin(); | 565 for (NoteList::const_iterator ni = notes.begin(); |
651 } | 655 } |
652 } | 656 } |
653 | 657 |
654 return got; | 658 return got; |
655 } | 659 } |
656 | |
657 AudioGenerator::NoteList | |
658 AudioGenerator::getNotes(Model *model, | |
659 size_t startFrame, | |
660 size_t endFrame) | |
661 { | |
662 NoteList notes; | |
663 | |
664 SparseOneDimensionalModel *sodm = | |
665 qobject_cast<SparseOneDimensionalModel *>(model); | |
666 | |
667 if (sodm) { | |
668 | |
669 SparseOneDimensionalModel::PointList points = | |
670 sodm->getPoints(startFrame, endFrame); | |
671 | |
672 for (SparseOneDimensionalModel::PointList::iterator pli = | |
673 points.begin(); pli != points.end(); ++pli) { | |
674 | |
675 notes.push_back | |
676 (NoteData(pli->frame, | |
677 m_sourceSampleRate / 6, // arbitrary short duration | |
678 64, // default pitch | |
679 100)); // default velocity | |
680 } | |
681 | |
682 return notes; | |
683 } | |
684 | |
685 NoteModel *nm = qobject_cast<NoteModel *>(model); | |
686 | |
687 if (nm) { | |
688 | |
689 NoteModel::PointList points = | |
690 nm->getPoints(startFrame, endFrame); | |
691 | |
692 for (NoteModel::PointList::iterator pli = | |
693 points.begin(); pli != points.end(); ++pli) { | |
694 | |
695 size_t duration = pli->duration; | |
696 if (duration == 0 || duration == 1) { | |
697 duration = m_sourceSampleRate / 20; | |
698 } | |
699 | |
700 int pitch = lrintf(pli->value); | |
701 | |
702 int velocity = 100; | |
703 if (pli->level > 0.f && pli->level <= 1.f) { | |
704 velocity = lrintf(pli->level * 127); | |
705 } | |
706 | |
707 NoteData note(pli->frame, | |
708 duration, | |
709 pitch, | |
710 velocity); | |
711 | |
712 if (nm->getScaleUnits() == "Hz") { | |
713 note.frequency = pli->value; | |
714 note.isMidiPitchQuantized = false; | |
715 } | |
716 | |
717 notes.push_back(note); | |
718 } | |
719 | |
720 return notes; | |
721 } | |
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 | |
763 return notes; | |
764 } |