~baltix/gcompris-qt/0.97.1

« back to all changes in this revision

Viewing changes to src/core/synth/GSynth.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2020-07-06 18:07:11 UTC
  • Revision ID: baltix@gmail.com-20200706180711-g254osu02cn8bc8p
GCompris-QT 0.97.1 with Lithuanian translation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GCompris - GSynth.h
 
2
 *
 
3
 * Copyright (C) 2018 Timothée Giet <animtim@gmail.com>
 
4
 *
 
5
 * Authors:
 
6
 *   Johnny Jazeix <jazeix@gmail.com>
 
7
 *   Timothée Giet <animtim@gmail.com>
 
8
 *
 
9
 *   This program is free software; you can redistribute it and/or modify
 
10
 *   it under the terms of the GNU General Public License as published by
 
11
 *   the Free Software Foundation; either version 3 of the License, or
 
12
 *   (at your option) any later version.
 
13
 *
 
14
 *   This program is distributed in the hope that it will be useful,
 
15
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *   GNU General Public License for more details.
 
18
 *
 
19
 *   You should have received a copy of the GNU General Public License
 
20
 *   along with this program; if not, see <https://www.gnu.org/licenses/>.
 
21
 */
 
22
#ifndef GSYNTH_H
 
23
#define GSYNTH_H
 
24
 
 
25
#include <QAudioDeviceInfo>
 
26
#include <QAudioOutput>
 
27
#include <QTimer>
 
28
#include <QQmlEngine>
 
29
#include "preset.h"
 
30
 
 
31
class Generator;
 
32
 
 
33
class GSynth : public QObject
 
34
{
 
35
    Q_OBJECT
 
36
 
 
37
public:
 
38
    explicit GSynth(QObject *parent = 0);
 
39
    virtual ~GSynth();
 
40
 
 
41
    /**
 
42
     * Generate a note and start the corresponding timer
 
43
     *  to stop it at "duration" ms.
 
44
     *
 
45
     * @param note note to play
 
46
     * @param duration how much time the note needs to be played
 
47
     */
 
48
    Q_INVOKABLE void generate(int note, int duration);
 
49
 
 
50
    static GSynth *getInstance() {
 
51
        if(!m_instance) {
 
52
            m_instance = new GSynth();
 
53
        }
 
54
        return m_instance;
 
55
    }
 
56
    static QObject *synthProvider(QQmlEngine *engine,
 
57
                                  QJSEngine *scriptEngine);
 
58
 
 
59
protected:
 
60
    static GSynth *m_instance;
 
61
 
 
62
private slots:
 
63
    void stopAudio(int note);
 
64
    
 
65
private:
 
66
    unsigned int bufferSize;
 
67
 
 
68
    Generator        *m_generator;
 
69
    QAudioDeviceInfo  m_device;
 
70
    QAudioFormat      m_format;
 
71
    QByteArray        m_buffer;
 
72
    QAudioOutput     *m_audioOutput;
 
73
    QMap<int, QTimer *> m_timers;
 
74
    
 
75
    Preset PresetCustom;
 
76
};
 
77
 
 
78
#endif // GSYNTH_H
 
79