32 #define STATUS if (Voice::mVerbosity >= 4) qDebug() << "Scale:" 33 #define MESSAGE if (Voice::mVerbosity >= 3) qDebug() << "Scale:" 34 #define WARNING if (Voice::mVerbosity >= 2) qWarning()<<"Scale: WARNING:" 35 #define ERROR if (Voice::mVerbosity >= 1) qCritical() << "Scale: ERROR:" 58 {
return mWaves[key & 0x7F]; }
73 const double A4 = 440;
75 for (
int n=21; n<=108; ++n)
79 if (QThread::currentThread()->isInterruptionRequested())
return;
80 double frequ = A4*pow(2,(n-69.0)/12.0);
81 mWaves[n].computeTriangularWave (frequ,samplerate,(n-20)/88.0);
104 const QVector<qint32> &L,
105 const QVector<qint32> &R,
107 const double amplification)
109 if (key<0 or key>127)
111 qDebug() <<
"Scale::insert: key" << key <<
"out of range";
114 if (L.size()==0 or L.size()!=R.size())
116 qDebug() <<
"Scale::insert of key" << key <<
": Waveform sizes" 117 << L.size() << R.size() <<
"inconsistent";
122 qDebug() <<
"Scale::insert: mWaveForm size =" <<
mWaves.size() <<
"invalid";
125 if (L.size() > 1<<20)
127 qDebug() <<
"Scale::insert: ERROR: mWaveForm exceeds maximal size 2^20";
130 return mWaves[key].insert(L,R,release,amplification);
150 for (
Wave &waveform :
mWaves)
if (waveform.waveFormExists()) cnt++;
155 for (
Wave &waveform : mWaves)
157 if (cnt) progress += 1.0/cnt;
else progress=1;
159 if (not waveform.write(iodevice))
return false;
184 qWarning() <<
"Scale::read: invalid tag.";
191 if (not waveform.read(iodevice))
return false;
192 if (waveform.waveFormExists() and cnt>0) progress += 1.0/cnt;
193 if (voice) emit voice->
setProgress(QVariant(progress));
209 qDebug() <<
" Scale with" <<
mWaves.size() <<
"waveforms.";
Wave & getWave(int &key)
Get the wave corresponding to a given key.
Class holding the sampled sound for one key.
static constexpr int N
Maximal number of waves in a scale.
Voice - a set of scales, keeping the acoustic data of an instrument.
bool read(QIODevice &iodevice, Voice *voice=nullptr)
Read data of a scale from a device.
Scale()
Constructor, creates N=128 empty wave objects.
const int ctag
Tag to recognize a scale in a file.
bool write(QIODevice &iodevice, Voice *voice=nullptr)
Write scale to device.
void printInfo()
Scale::printInfo.
void generateArtificialSound(Voice *voice=nullptr, int samplerate=44100)
Generate a scale of artificial sounds in equal temperament.
bool insert(const int key, const QVector< qint32 > &L, const QVector< qint32 > &R, const bool release, const double amplification)
Insert a newly recorded or generated waveform into the scale. This function checks the parameters and...
static bool read(QIODevice &iodevice, const T &object)
void setProgress(QVariant percent)
bool mCancellationRequested
Cancel loading.
QVector< Wave > mWaves
This is the actual vector of waves.
static bool write(QIODevice &iodevice, const T &object)