Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
soundgenerator.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // SoundGenerator - manage the tones that are being played
22 //=============================================================================
23 
24 #ifndef SOUNDGENERATOR_H
25 #define SOUNDGENERATOR_H
26 
27 #include <QQueue>
28 #include <QMutex>
29 
30 #include "request.h"
31 #include "tone.h"
32 #include "sampler.h"
33 
35 
36 class Application;
37 
41 
42 class SoundGenerator : public ThreadBase
43 {
44  Q_OBJECT
45 public:
47 
48  void init (Application *application, Voice *voice);
49  bool init() override { return true; }
50  void suspend() override final;
51 
54 
55 
56  void registerRequest (Request &request);
57  void registerAllNotesOff();
58 
59  Sampler& getSampler() { return mSampler; }
60  QList<Tone>* getTones() { return &mTones; }
61  void lockTones() { mToneMutex.lock(); }
62  void unlockTones() { mToneMutex.unlock(); }
63 
65 
66  quint32 getIncrement(int key);
67  void setIncrement(int key, quint32 increment);
68  void clearIncrements();
69 
70 public slots:
71  void receiveTuningCorrections(QMap<int, double> corrections);
72  void setSustainPedal (bool pressed);
73  void setSostenutoPedal (bool pressed);
74  void setSoftPedal (bool pressed);
75 
76 private slots:
77  void timeout() override final;
78 
79 signals:
81 
82 private:
83  void handleRequest (Request &request);
84  void manageToneDynamics();
85  bool queueFilled();
86 
87 
88  using State = Tone::State;
89 
90  QQueue<Request> mQueue;
91  QMutex mQueueMutex;
92 
93  QList<Tone> mTones;
94  QMutex mToneMutex;
95 
96  QVector<quint32> mIncrements;
98 
100 
103 
104  // TODO pedals
108 };
109 
110 #endif // SOUNDGENERATOR_H
Universal base class for threaded modules.
Definition: threadbase.h:60
Class managing the generation of sound.
Structure containing the data for a play-note request.
Definition: request.h:36
Voice - a set of scales, keeping the acoustic data of an instrument.
Definition: voice.h:39
void setMaxPacketSize(int n)
void receiveTuningCorrections(QMap< int, double > corrections)
QList< Tone > * getTones()
void registerRequest(Request &request)
Register a single request to play a note in the queue.
size_t getMaxPacketSize()
void handleRequest(Request &request)
State
Definition: tone.h:56
bool init() override
Virtual initialization function (no functionality here)
void setMaxPacketSize(int n)
Application * getApplication()
Sampler & getSampler()
QVector< quint32 > mIncrements
Sound-generating module which plays the tones held by the SoundGenerator.
Definition: sampler.h:57
size_t getMaxPacketSize()
void setIncrement(int key, quint32 increment)
void registerAllNotesOff()
QMutex mIncrementMutex
void timeout() override final
Private thread worker function.
Application * pApplication
void setSustainPedal(bool pressed)
void setSoftPedal(bool pressed)
void suspend() override final
Mark the thread as suspended.
Main application.
Definition: application.h:60
void forceImmediateProcessing()
QList< Tone > mTones
quint32 getIncrement(int key)
QQueue< Request > mQueue
void setSostenutoPedal(bool pressed)