Player: set note and octave atomically

This commit is contained in:
Louis-Joseph Fournier 2016-01-14 15:56:19 +01:00
parent e45423edde
commit b9bf210551
5 changed files with 23 additions and 4 deletions

View file

@ -111,9 +111,11 @@ Item {
//octave: tuner.octave //octave: tuner.octave
onReleased: { onReleased: {
note = tuner.note = index % 12 note = index % 12
octave = tuner.octave = index / 12 octave = index / 12
toise_octave.index = tuner.octave toise_octave.index = octave
// set octave and note atomically
tuner.SetNoteOctave(note, octave)
toise_octave.updateFlickable() toise_octave.updateFlickable()
} }
} }

View file

@ -104,6 +104,14 @@ void Tuner::SetNote(int note)
emit resultChanged(); emit resultChanged();
} }
void Tuner::SetNoteOctave(int note, int octave)
{
result.note = note;
result.octave = octave;
worker->SetNoteOctave(note, octave);
emit resultChanged();
}
double Tuner::GetDeviation() double Tuner::GetDeviation()
{ {
return result.deviation; return result.deviation;

View file

@ -71,6 +71,7 @@ class Tuner : public QObject {
// slots from worker // slots from worker
void ResultUpdated(const PitchDetection::PitchResult &result); void ResultUpdated(const PitchDetection::PitchResult &result);
void TemperamentListUpdated(const QStringList &list); void TemperamentListUpdated(const QStringList &list);
void SetNoteOctave(int note, int octave);
signals: signals:
// signals to UI // signals to UI

View file

@ -134,7 +134,6 @@ void TunerWorker::SetNote(int note)
mutex.unlock(); mutex.unlock();
} }
void TunerWorker::SetOctave(int octave) void TunerWorker::SetOctave(int octave)
{ {
mutex.lock(); mutex.lock();
@ -142,6 +141,14 @@ void TunerWorker::SetOctave(int octave)
mutex.unlock(); mutex.unlock();
} }
void TunerWorker::SetNoteOctave(int note, int octave)
{
mutex.lock();
note_to_update = note;
octave_to_update = octave;
mutex.unlock();
}
void TunerWorker::Entry() void TunerWorker::Entry()
{ {
cerr << __func__ << endl; cerr << __func__ << endl;

View file

@ -67,6 +67,7 @@ class TunerWorker : public QObject {
void SetOctave(int octave); void SetOctave(int octave);
void Entry(); void Entry();
void Quit(); void Quit();
void SetNoteOctave(int note, int octave);
/// write a file with raw audio /// write a file with raw audio
static void set_record(const char *filename_record); static void set_record(const char *filename_record);