File: synthcontroller.cpp

package info (click to toggle)
libdrumstick 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,876 kB
  • sloc: cpp: 25,685; xml: 122; sh: 14; makefile: 5
file content (187 lines) | stat: -rw-r--r-- 4,380 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
    Sonivox EAS Synthesizer for Qt applications
    Copyright (C) 2016-2024, Pedro Lopez-Cabanillas <plcl@users.sf.net>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QMutex>
#include "synthcontroller.h"
#include "synthrenderer.h"

namespace drumstick {
namespace rt {

SynthController::SynthController(QObject *parent) : MIDIOutput(parent)
{
    m_renderer = new SynthRenderer();
    m_renderer->moveToThread(&m_renderingThread);
    connect(&m_renderingThread, &QThread::started,  m_renderer, &SynthRenderer::run);
}

SynthController::~SynthController()
{
    //qDebug() << Q_FUNC_INFO;
    if (m_renderingThread.isRunning()) {
        stop();
    }
    delete m_renderer;
    m_renderer = nullptr;
}

void
SynthController::start()
{
    QMutex mutex;
    mutex.lock();
    m_renderer->setCondition(&m_rendering);
    m_renderingThread.start(QThread::HighPriority);
    m_rendering.wait(&mutex);
    mutex.unlock();
}

void
SynthController::stop()
{
    //qDebug() << Q_FUNC_INFO;
    m_renderer->stop();
    m_renderingThread.quit();
    m_renderingThread.wait();
}

void
SynthController::initialize(QSettings* settings)
{
    m_renderer->initialize(settings);
    //qDebug() << Q_FUNC_INFO;
}

QString SynthController::backendName()
{
    return SynthRenderer::QSTR_SONIVOXEAS;
}

QString SynthController::publicName()
{
    return SynthRenderer::QSTR_SONIVOXEAS;
}

void SynthController::setPublicName(QString name)
{
    Q_UNUSED(name)
}

QList<MIDIConnection> SynthController::connections(bool advanced)
{
    Q_UNUSED(advanced)
    return QList<MIDIConnection>{MIDIConnection(SynthRenderer::QSTR_SONIVOXEAS, SynthRenderer::QSTR_SONIVOXEAS)};
}

void SynthController::setExcludedConnections(QStringList conns)
{
    Q_UNUSED(conns)
}

void SynthController::open(const MIDIConnection& name)
{
    Q_UNUSED(name)
    //qDebug() << Q_FUNC_INFO << name;
    start();
}

void SynthController::close()
{
    //qDebug() << Q_FUNC_INFO;
    stop();
}

MIDIConnection SynthController::currentConnection()
{
    return m_renderer->connection();
}

void SynthController::sendNoteOff(int chan, int note, int vel)
{
    m_renderer->sendMessage(MIDI_STATUS_NOTEOFF + chan, note, vel);
}

void SynthController::sendNoteOn(int chan, int note, int vel)
{
    m_renderer->sendMessage(MIDI_STATUS_NOTEON + chan, note, vel);
}

void SynthController::sendKeyPressure(int chan, int note, int value)
{
    m_renderer->sendMessage(MIDI_STATUS_KEYPRESURE + chan, note, value);
}

void SynthController::sendController(int chan, int control, int value)
{
    m_renderer->sendMessage(MIDI_STATUS_CONTROLCHANGE + chan, control, value);
}

void SynthController::sendProgram(int chan, int program)
{
    m_renderer->sendMessage(MIDI_STATUS_PROGRAMCHANGE + chan, program);
}

void SynthController::sendChannelPressure(int chan, int value)
{
    m_renderer->sendMessage(MIDI_STATUS_CHANNELPRESSURE + chan, value);
}

void SynthController::sendPitchBend(int chan, int v)
{
    // -8192 <= v <= 8191; 0 <= value <= 16384
    int value = 8192 + v;
    m_renderer->sendMessage(MIDI_STATUS_PITCHBEND + chan, MIDI_LSB(value), MIDI_MSB(value));
}

void SynthController::sendSysex(const QByteArray &data)
{
    Q_UNUSED(data)
}

void SynthController::sendSystemMsg(const int status)
{
    Q_UNUSED(status)
}

void SynthController::writeSettings(QSettings *settings)
{
    m_renderer->writeSettings(settings);
}

QStringList SynthController::getDiagnostics()
{
    return m_renderer->getDiagnostics();
}

bool SynthController::getStatus()
{
    return m_renderer->getStatus();
}

QString SynthController::getLibVersion()
{
    return m_renderer->getLibVersion();
}

QString SynthController::getSoundFont()
{
    return m_renderer->getSoundFont();
}

} // namespace rt
} // namespace drumstick