summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/AudioFaderBox.cpp
blob: 27980e7b343867149e1116c14fa8a0131c8195b7 (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */

/*
    Rosegarden
    A MIDI and audio sequencer and musical notation editor.
 
    This program is Copyright 2000-2008
        Guillaume Laurent   <[email protected]>,
        Chris Cannam        <[email protected]>,
        Richard Bown        <[email protected]>
 
    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
    Bown to claim authorship of this work have been asserted.
 
    Other copyrights also apply to some parts of this work.  Please
    see the AUTHORS file and individual file headers for details.
 
    This program 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 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/


#include "AudioFaderBox.h"
#include <tqlayout.h>

#include <klocale.h>
#include <kstddirs.h>
#include "misc/Debug.h"
#include "AudioRouteMenu.h"
#include "AudioVUMeter.h"
#include "base/AudioLevel.h"
#include "base/Instrument.h"
#include "base/Studio.h"
#include "Fader.h"
#include "gui/general/GUIPalette.h"
#include "gui/application/RosegardenGUIApp.h"
#include "gui/studio/AudioPluginOSCGUIManager.h"
#include "Rotary.h"
#include <kglobal.h>
#include <tqframe.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqobject.h>
#include <tqpixmap.h>
#include <tqpushbutton.h>
#include <tqsignalmapper.h>
#include <tqstring.h>
#include <tqtooltip.h>
#include <tqvbox.h>
#include <tqwidget.h>
#include "VUMeter.h"


namespace Rosegarden
{

AudioFaderBox::AudioFaderBox(TQWidget *parent,
                             TQString id,
                             bool haveInOut,
                             const char *name):
        TQFrame(parent, name),
        m_signalMapper(new TQSignalMapper(this)),
        m_id(id),
        m_isStereo(false)
{
    // Plugin box
    //
    TQPushButton *plugin;
    TQVBox *pluginVbox = 0;

    pluginVbox = new TQVBox(this);
    pluginVbox->setSpacing(2);

    for (int i = 0; i < 5; i++) {
        plugin = new TQPushButton(pluginVbox);
        plugin->setText(i18n("<no plugin>"));

        TQToolTip::add
            (plugin, i18n("Audio plugin button"));

        m_plugins.push_back(plugin);
        m_signalMapper->setMapping(plugin, i);
        connect(plugin, TQT_SIGNAL(clicked()),
                m_signalMapper, TQT_SLOT(map()));
    }

    m_synthButton = new TQPushButton(this);
    m_synthButton->setText(i18n("<no synth>"));
    TQToolTip::add
        (m_synthButton, i18n("Synth plugin button"));

    // VU meter and fader
    //
    TQHBox *faderHbox = new TQHBox(this);

    m_vuMeter = new AudioVUMeter(faderHbox, VUMeter::AudioPeakHoldShort,
                                 true, true);

    m_recordFader = new Fader(AudioLevel::ShortFader,
                              20, m_vuMeter->height(), faderHbox);

    m_recordFader->setOutlineColour(GUIPalette::getColour(GUIPalette::RecordFaderOutline));

    delete m_vuMeter; // only used the first one to establish height,
    // actually want it after the record fader in
    // hbox
    m_vuMeter = new AudioVUMeter(faderHbox, VUMeter::AudioPeakHoldShort,
                                 true, true);

    m_fader = new Fader(AudioLevel::ShortFader,
                        20, m_vuMeter->height(), faderHbox);

    m_fader->setOutlineColour(GUIPalette::getColour(GUIPalette::PlaybackFaderOutline));

    TQString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");
    m_monoPixmap.load(TQString("%1/misc/mono.xpm").arg(pixmapDir));
    m_stereoPixmap.load(TQString("%1/misc/stereo.xpm").arg(pixmapDir));

    m_pan = new Rotary(this, -100.0, 100.0, 1.0, 5.0, 0.0, 22,
                       Rotary::NoTicks, false, true);

    // same as the knob colour on the MIDI pan
    m_pan->setKnobColour(GUIPalette::getColour(GUIPalette::RotaryPastelGreen));

    m_stereoButton = new TQPushButton(this);
    m_stereoButton->setPixmap(m_monoPixmap); // default is mono
    m_stereoButton->setFixedSize(24, 24);

    connect(m_stereoButton, TQT_SIGNAL(clicked()),
            this, TQT_SLOT(slotChannelStateChanged()));

    m_synthGUIButton = new TQPushButton(this);
    m_synthGUIButton->setText(i18n("Editor"));

    if (haveInOut) {
        m_audioInput = new AudioRouteMenu(this,
                                          AudioRouteMenu::In,
                                          AudioRouteMenu::Regular);
        m_audioOutput = new AudioRouteMenu(this,
                                           AudioRouteMenu::Out,
                                           AudioRouteMenu::Regular);
    } else {
        m_pan->setKnobColour(GUIPalette::getColour(GUIPalette::RotaryPastelOrange));

        m_audioInput = 0;
        m_audioOutput = 0;
    }

    TQToolTip::add
        (m_pan, i18n("Set the audio pan position in the stereo field"));
    TQToolTip::add
        (m_synthGUIButton, i18n("Open synth plugin's native editor"));
    TQToolTip::add
        (m_stereoButton, i18n("Mono or Stereo Instrument"));
    TQToolTip::add
        (m_recordFader, i18n("Record level"));
    TQToolTip::add
        (m_fader, i18n("Playback level"));
    TQToolTip::add
        (m_vuMeter, i18n("Audio level"));

    TQGridLayout *grid = new TQGridLayout(this, 3, 6, 4, 4);

    grid->addMultiCellWidget(m_synthButton, 0, 0, 0, 2);

    if (haveInOut) {
        m_inputLabel = new TQLabel(i18n("In:"), this);
        grid->addWidget(m_inputLabel, 0, 0, AlignRight);
        grid->addMultiCellWidget(m_audioInput->getWidget(), 0, 0, 1, 2);
        m_outputLabel = new TQLabel(i18n("Out:"), this);
        grid->addWidget(m_outputLabel, 0, 3, AlignRight);
        grid->addMultiCellWidget(m_audioOutput->getWidget(), 0, 0, 4, 5);
    }

    grid->addMultiCellWidget(pluginVbox, 2, 2, 0, 2);
    grid->addMultiCellWidget(faderHbox, 1, 2, 3, 5);

    grid->addWidget(m_synthGUIButton, 1, 0);
    grid->addWidget(m_pan, 1, 2);
    grid->addWidget(m_stereoButton, 1, 1);

    for (int i = 0; i < 5; ++i) {
        // Force width
        m_plugins[i]->setFixedWidth(m_plugins[i]->width());
    }
    m_synthButton->setFixedWidth(m_plugins[0]->width());

    m_synthButton->hide();
    m_synthGUIButton->hide();
}

void
AudioFaderBox::setIsSynth(bool isSynth)
{
    if (isSynth) {
        m_inputLabel->hide();
        m_synthButton->show();
        m_synthGUIButton->show();
        m_audioInput->getWidget()->hide();
        m_recordFader->hide();
    } else {
        m_synthButton->hide();
        m_synthGUIButton->hide();
        m_inputLabel->show();
        m_audioInput->getWidget()->show();
        m_recordFader->show();
    }
}

void
AudioFaderBox::slotSetInstrument(Studio *studio,
                                 Instrument *instrument)
{
    if (m_audioInput)
        m_audioInput->slotSetInstrument(studio, instrument);
    if (m_audioOutput)
        m_audioOutput->slotSetInstrument(studio, instrument);
    if (instrument)
        setAudioChannels(instrument->getAudioChannels());
    if (instrument) {

        RG_DEBUG << "AudioFaderBox::slotSetInstrument(" << instrument->getId() << ")" << endl;

        setIsSynth(instrument->getType() == Instrument::SoftSynth);
        if (instrument->getType() == Instrument::SoftSynth) {
            bool gui = false;
            RG_DEBUG << "AudioFaderBox::slotSetInstrument(" << instrument->getId() << "): is soft synth" << endl;
#ifdef HAVE_LIBLO

            gui = RosegardenGUIApp::self()->getPluginGUIManager()->hasGUI
                  (instrument->getId(), Instrument::SYNTH_PLUGIN_POSITION);
            RG_DEBUG << "AudioFaderBox::slotSetInstrument(" << instrument->getId() << "): has gui = " << gui << endl;
#endif

            m_synthGUIButton->setEnabled(gui);
        }
    }
}

bool
AudioFaderBox::owns(const TQObject *object)
{
    return (object &&
            ((object->parent() == this) ||
             (object->parent() && (object->parent()->parent() == this))));
}

void
AudioFaderBox::setAudioChannels(int channels)
{
    m_isStereo = (channels > 1);

    switch (channels) {
    case 1:
        if (m_stereoButton)
            m_stereoButton->setPixmap(m_monoPixmap);
        m_isStereo = false;
        break;

    case 2:
        if (m_stereoButton)
            m_stereoButton->setPixmap(m_stereoPixmap);
        m_isStereo = true;
        break;
    default:
        RG_DEBUG << "AudioFaderBox::setAudioChannels - "
        << "unsupported channel numbers (" << channels
        << ")" << endl;
        return ;
    }

    if (m_audioInput)
        m_audioInput->slotRepopulate();
    if (m_audioOutput)
        m_audioOutput->slotRepopulate();
}

void
AudioFaderBox::slotChannelStateChanged()
{
    if (m_isStereo) {
        setAudioChannels(1);
        emit audioChannelsChanged(1);
    } else {
        setAudioChannels(2);
        emit audioChannelsChanged(2);
    }
}

}
#include "AudioFaderBox.moc"