1 // Copyright 2005 "Gilles Degottex"
3 // This file is part of "Music"
5 // "Music" is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or
8 // (at your option) any later version.
10 // "Music" is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <qdatetime.h>
29 #include <Music/Music.h>
30 using namespace Music;
31 #include <CppAddons/Observer.h>
33 struct QuantizerListener : Listener<QuantizerListener>
35 virtual void noteStarted(int tag, int ht, double dt) {todo("noteStarted");}
36 virtual void noteFinished(int tag, int ht, double dt) {todo("noteFinished");}
37 virtual void notePlayed(int ht, double duration, double dt) {todo("notePlayed");}
41 a function object for merging small note events into note events with a duration.
42 - Fill small holes where the note should appears
43 - Ignore notes which are too small
45 class Quantizer : public Talker<QuantizerListener>
56 State(double t, bool p) : time(t), play(p) {}
59 deque<State> old_states;
60 enum{QC_NOTHING, QC_STARTING, QC_PLAYING} state;
65 Channel() : state(QC_NOTHING) {}
70 Quantizer(float tolerance=1, float min_density=0.5);
72 double getTolerance() {return m_tolerance;}
73 void setTolerance(float tolerance) {m_tolerance=tolerance;}
74 double getMinDensity() {return m_min_density;}
75 void setMinDensity(float min_density) {m_min_density=min_density;}
77 void quantize(const vector<bool> hts, int min_ht);
80 int m_min_stored_recon;
81 int getMinStoredRecon(){return m_min_stored_recon;}
83 int getNbChannels() {return m_channels.size();}
84 int getSemitoneMin() {return m_min_ht;}
85 vector<Channel> m_channels;
89 double getLatency() {return m_tolerance;}
91 virtual ~Quantizer(){}
94 #endif // _QUANTIZER_H_