31 #define STATUS if (mVerbosity >= 4) qDebug() << "Voice:" 32 #define MESSAGE if (mVerbosity >= 3) qDebug() << "Voice:" 33 #define WARNING if (mVerbosity >= 2) qWarning() <<"Voice: WARNING:" 34 #define ERROR if (mVerbosity >= 1) qCritical() << "Voice: ERROR:" 47 , mHighestDampedKey(0)
48 , mDynamicVolume(true)
50 , mRecordedPitchInCents(128,0)
66 mScales[0].generateArtificialSound(
this,samplerate);
80 ERROR <<
"Voice::write: saving empty file.";
85 ERROR <<
"Voice::write: More than 128 scales.";
88 if (iodevice.isOpen()) iodevice.close();
89 if (not iodevice.open(QIODevice::WriteOnly))
91 WARNING <<
"Voice::read: Could not open device";
94 char tag[16]=
"justintonation ";
95 iodevice.write(tag,15);
103 if (not scale.write(iodevice,
this))
return false;
107 char endtag[14]=
" end of file ";
108 iodevice.write(endtag,13);
120 if (iodevice.isOpen()) iodevice.close();
121 if (not iodevice.open(QIODevice::ReadOnly))
123 WARNING <<
"read: Could not open device";
126 QByteArray tag = iodevice.read(15);
127 if (tag.size() != 15 or strncmp(tag.data(),
"justintonation ",11)!=0)
129 WARNING <<
"read: Invalid voice tag at the beginning";
132 int numberOfScales=0;
134 if (numberOfScales<0 or numberOfScales>255)
136 WARNING <<
"read: Unreasonable number of scales";
140 mScales.resize(numberOfScales);
147 for (
int scaleNumber=0; scaleNumber<
mScales.size(); ++scaleNumber)
149 QString progress = tr(
"Reading scale") +
" " + QString::number(scaleNumber+1)
150 +
"/" + QString::number(
mScales.size());
152 if (not
mScales[scaleNumber].
read(iodevice,
this))
return false;
153 if (QThread::currentThread()->isInterruptionRequested())
return false;
155 STATUS <<
"Reading pitch corrections";
160 QByteArray endtag = iodevice.read(13);
161 if (endtag.size() != 13 or strncmp(endtag.data(),
" end of file ",13)!=0)
163 WARNING <<
"Voice::read: Invalid voice tag and the end of file";
166 MESSAGE <<
"Voice::read: we have read" <<
mScales.size() <<
"scales.";
184 MESSAGE <<
"Voice::Clear: Clearing all scales";
195 qDebug() <<
"Voice containing" <<
mScales.size() <<
"scales";
196 for (
auto &e :
mScales) e.printInfo();
void generateArtificialSound(int samplerate)
void setProgressText(QVariant text)
static int mVerbosity
Verbosity of qDebug() message.
bool write(QIODevice &iodevice)
Scale - a set of PCM waves with a characteristic intensity and length.
void signalArtificialSoundGenerationComplete(bool)
bool read(QIODevice &iodevice)
static bool read(QIODevice &iodevice, const T &object)
QVector< double > mRecordedPitchInCents
static bool write(QIODevice &iodevice, const T &object)