~ubuntu-branches/debian/jessie/synthv1/jessie

« back to all changes in this revision

Viewing changes to src/synthv1widget_jack.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia, Jaromír Mikeš, Alessio Treglia
  • Date: 2013-07-01 07:54:55 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130701075455-y8d04axdwo1ui917
Tags: 0.3.3-1
[ Jaromír Mikeš ]
* Added myself as uploader

[ Alessio Treglia ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// synthv1widget_jack.cpp
2
2
//
3
3
/****************************************************************************
4
 
   Copyright (C) 2012, rncbc aka Rui Nuno Capela. All rights reserved.
 
4
   Copyright (C) 2012-2013, rncbc aka Rui Nuno Capela. All rights reserved.
5
5
 
6
6
   This program is free software; you can redistribute it and/or
7
7
   modify it under the terms of the GNU General Public License
23
23
 
24
24
#include "synthv1_jack.h"
25
25
 
 
26
#ifdef CONFIG_NSM
 
27
#include "synthv1_nsm.h"
 
28
#endif
 
29
 
26
30
#include <QApplication>
27
31
#include <QFileInfo>
28
32
#include <QDir>
57
61
// Constructor.
58
62
synthv1widget_jack::synthv1widget_jack ( synthv1_jack *pSynth )
59
63
        : synthv1widget(), m_pSynth(pSynth)
 
64
        #ifdef CONFIG_NSM
 
65
                , m_pNsmClient(NULL), m_bNsmDirty(false)
 
66
        #endif
60
67
{
 
68
#ifdef CONFIG_NSM
 
69
        // Check whether to participate into a NSM session...
 
70
        const QString& nsm_url
 
71
                = QString::fromLatin1(::getenv("NSM_URL"));
 
72
        if (!nsm_url.isEmpty()) {
 
73
                m_pNsmClient = new synthv1_nsm(nsm_url);
 
74
                QObject::connect(m_pNsmClient,
 
75
                        SIGNAL(open()),
 
76
                        SLOT(openSession()));
 
77
                QObject::connect(m_pNsmClient,
 
78
                        SIGNAL(save()),
 
79
                        SLOT(saveSession()));
 
80
                QObject::connect(m_pNsmClient,
 
81
                        SIGNAL(show()),
 
82
                        SLOT(showSession()));
 
83
                QObject::connect(m_pNsmClient,
 
84
                        SIGNAL(hide()),
 
85
                        SLOT(hideSession()));
 
86
                m_pNsmClient->announce(SYNTHV1_TITLE, ":switch:dirty:optional-gui:");
 
87
                return;
 
88
        }
 
89
#endif  // CONFIG_NSM
 
90
 
 
91
        m_pSynth->open(SYNTHV1_TITLE);
 
92
 
61
93
#ifdef CONFIG_JACK_SESSION
62
94
        // JACK session event callback...
63
95
        if (::jack_set_session_callback) {
81
113
synthv1widget_jack::~synthv1widget_jack (void)
82
114
{
83
115
        m_pSynth->deactivate();
 
116
        m_pSynth->close();
84
117
}
85
118
 
86
119
 
132
165
#endif  // CONFIG_JACK_SESSION
133
166
 
134
167
 
135
 
// Param method.
 
168
#ifdef CONFIG_NSM
 
169
 
 
170
void synthv1widget_jack::openSession (void)
 
171
{
 
172
        if (m_pNsmClient == NULL)
 
173
                return;
 
174
 
 
175
        if (!m_pNsmClient->is_active())
 
176
                return;
 
177
 
 
178
#ifdef CONFIG_DEBUG
 
179
        qDebug("synthv1widget_jack::openSession()");
 
180
#endif
 
181
 
 
182
        m_pSynth->deactivate();
 
183
        m_pSynth->close();
 
184
 
 
185
        const QString& path_name = m_pNsmClient->path_name();
 
186
        const QString& display_name = m_pNsmClient->display_name();
 
187
        const QString& client_id = m_pNsmClient->client_id();
 
188
 
 
189
        const QDir dir(path_name);
 
190
        if (!dir.exists())
 
191
                dir.mkpath(path_name);
 
192
 
 
193
        const QFileInfo fi(path_name, display_name + '.' + SYNTHV1_TITLE);
 
194
        if (fi.exists())
 
195
                loadPreset(fi.absoluteFilePath());
 
196
 
 
197
        m_pSynth->open(client_id.toUtf8().constData());
 
198
        m_pSynth->activate();
 
199
 
 
200
        m_bNsmDirty = false;
 
201
 
 
202
        m_pNsmClient->open_reply();
 
203
        m_pNsmClient->dirty(false);
 
204
 
 
205
        m_pNsmClient->visible(QWidget::isVisible());
 
206
}
 
207
 
 
208
void synthv1widget_jack::saveSession (void)
 
209
{
 
210
        if (m_pNsmClient == NULL)
 
211
                return;
 
212
 
 
213
        if (!m_pNsmClient->is_active())
 
214
                return;
 
215
 
 
216
#ifdef CONFIG_DEBUG
 
217
        qDebug("synthv1widget_jack::saveSession()");
 
218
#endif
 
219
 
 
220
        if (m_bNsmDirty) {
 
221
                const QString& path_name = m_pNsmClient->path_name();
 
222
                const QString& display_name = m_pNsmClient->display_name();
 
223
        //      const QString& client_id = m_pNsmClient->client_id();
 
224
                const QFileInfo fi(path_name, display_name + '.' + SYNTHV1_TITLE);
 
225
                savePreset(fi.absoluteFilePath());
 
226
                m_bNsmDirty = false;
 
227
        }
 
228
 
 
229
        m_pNsmClient->save_reply();
 
230
        m_pNsmClient->dirty(false);
 
231
}
 
232
 
 
233
 
 
234
void synthv1widget_jack::showSession (void)
 
235
{
 
236
        if (m_pNsmClient == NULL)
 
237
                return;
 
238
 
 
239
        if (!m_pNsmClient->is_active())
 
240
                return;
 
241
 
 
242
#ifdef CONFIG_DEBUG
 
243
        qDebug("synthv1widget_jack::showSession()");
 
244
#endif
 
245
 
 
246
        QWidget::show();
 
247
        QWidget::raise();
 
248
        QWidget::activateWindow();
 
249
}
 
250
 
 
251
void synthv1widget_jack::hideSession (void)
 
252
{
 
253
        if (m_pNsmClient == NULL)
 
254
                return;
 
255
 
 
256
        if (!m_pNsmClient->is_active())
 
257
                return;
 
258
 
 
259
#ifdef CONFIG_DEBUG
 
260
        qDebug("synthv1widget_jack::hideSession()");
 
261
#endif
 
262
 
 
263
        QWidget::hide();
 
264
}
 
265
 
 
266
 
 
267
#endif  // CONFIG_NSM
 
268
 
 
269
 
 
270
// Param port method.
136
271
void synthv1widget_jack::updateParam (
137
272
        synthv1::ParamIndex index, float fValue ) const
138
273
{
142
277
}
143
278
 
144
279
 
 
280
// Dirty flag method.
 
281
void synthv1widget_jack::updateDirtyPreset ( bool bDirtyPreset )
 
282
{
 
283
        synthv1widget::updateDirtyPreset(bDirtyPreset);
 
284
 
 
285
#ifdef CONFIG_NSM
 
286
        if (m_pNsmClient && m_pNsmClient->is_active()) {
 
287
                if (!m_bNsmDirty/* && bDirtyPreset*/) {
 
288
                        m_pNsmClient->dirty(true);
 
289
                        m_bNsmDirty = true;
 
290
                }
 
291
        }
 
292
#endif
 
293
}
 
294
 
 
295
 
145
296
// Application close.
146
297
void synthv1widget_jack::closeEvent ( QCloseEvent *pCloseEvent )
147
298
{
 
299
#ifdef CONFIG_NSM
 
300
        if (m_pNsmClient && m_pNsmClient->is_active())
 
301
                synthv1widget::updateDirtyPreset(false);
 
302
#endif
 
303
 
148
304
        // Let's be sure about that...
149
305
        if (queryClose()) {
150
306
                pCloseEvent->accept();
155
311
}
156
312
 
157
313
 
 
314
#ifdef CONFIG_NSM
 
315
 
 
316
// Optional GUI handlers.
 
317
void synthv1widget_jack::showEvent ( QShowEvent *pShowEvent )
 
318
{
 
319
        QWidget::showEvent(pShowEvent);
 
320
 
 
321
        if (m_pNsmClient)
 
322
                m_pNsmClient->visible(true);
 
323
}
 
324
 
 
325
void synthv1widget_jack::hideEvent ( QHideEvent *pHideEvent )
 
326
{
 
327
        if (m_pNsmClient)
 
328
                m_pNsmClient->visible(false);
 
329
 
 
330
        QWidget::hideEvent(pHideEvent);
 
331
}
 
332
 
 
333
#endif  // CONFIG_NSM
 
334
 
 
335
 
158
336
//-------------------------------------------------------------------------
159
337
// main
160
338