root/branches/undo/gui/src/Mixer/MixerLine.cpp @ 1604

Revision 1604, 24.2 KB (checked in by wolke, 3 years ago)

merge rev 1601:1603 from trunk

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23#include <stdio.h>
24
25#include <QPainter>
26
27#include "../InstrumentEditor/InstrumentEditor.h"
28#include "../widgets/Fader.h"
29#include "../HydrogenApp.h"
30#include "../Skin.h"
31#include "../widgets/Rotary.h"
32#include "../widgets/Button.h"
33#include "../widgets/LCD.h"
34
35#include <hydrogen/hydrogen.h>
36#include <hydrogen/Preferences.h>
37#include <hydrogen/audio_engine.h>
38#include <hydrogen/action.h>
39using namespace H2Core;
40
41#include "MixerLine.h"
42
43#define MIXERLINE_WIDTH                 56
44#define MIXERLINE_HEIGHT                254
45#define MASTERMIXERLINE_WIDTH   126
46#define MASTERMIXERLINE_HEIGHT  284
47#define MIXERLINE_LABEL_H               115
48#define MASTERMIXERLINE_FADER_H 75
49
50using namespace H2Core;
51
52MixerLine::MixerLine(QWidget* parent, int nInstr)
53 : PixmapWidget( parent, "MixerLine" )
54{
55//      INFOLOG( "INIT" );
56
57        m_nWidth = MIXERLINE_WIDTH;
58        m_nHeight = MIXERLINE_HEIGHT;
59        m_fMaxPeak = 0.0;
60        m_nActivity = 0;
61        m_bIsSelected = false;
62        m_nPeakTimer = 0;
63
64        Action* pAction;
65
66        resize( m_nWidth, m_nHeight );
67        setFixedSize( m_nWidth, m_nHeight );
68
69        setPixmap( "/mixerPanel/mixerline_background.png" );
70
71        // Play sample button
72        m_pPlaySampleBtn = new Button(
73                        this,
74                        "/mixerPanel/btn_play_on.png",
75                        "/mixerPanel/btn_play_off.png",
76                        "/mixerPanel/btn_play_over.png",
77                        QSize( 18, 13 )
78        );
79        m_pPlaySampleBtn->move( 8, 2 );
80        m_pPlaySampleBtn->setToolTip( trUtf8( "Play sample" ) );
81        connect(m_pPlaySampleBtn, SIGNAL(clicked(Button*)), this, SLOT(click(Button*)));
82        connect(m_pPlaySampleBtn, SIGNAL(rightClicked(Button*)), this, SLOT(rightClick(Button*)));
83
84        // Trigger sample LED
85        m_pTriggerSampleLED = new Button(
86                        this,
87                        "/mixerPanel/led_trigger_on.png",
88                        "/mixerPanel/led_trigger_off.png",
89                        "/mixerPanel/led_trigger_off.png",
90                        QSize( 5, 13 )
91        );
92        m_pTriggerSampleLED->move( 26, 2 );
93        connect(m_pTriggerSampleLED, SIGNAL(clicked(Button*)), this, SLOT(click(Button*)));
94
95        // Mute button
96        m_pMuteBtn = new ToggleButton(
97                        this,
98                        "/mixerPanel/btn_mute_on.png",
99                        "/mixerPanel/btn_mute_off.png",
100                        "/mixerPanel/btn_mute_over.png",
101                        QSize( 18, 13 )
102        );
103        m_pMuteBtn->move( 8, 17 );
104        m_pMuteBtn->setToolTip( trUtf8( "Mute" ) );
105        connect(m_pMuteBtn, SIGNAL(clicked(Button*)), this, SLOT(click(Button*)));
106
107        // Solo button
108        m_pSoloBtn = new ToggleButton(
109                        this,
110                        "/mixerPanel/btn_solo_on.png",
111                        "/mixerPanel/btn_solo_off.png",
112                        "/mixerPanel/btn_solo_over.png",
113                        QSize( 18, 13 )
114        );
115        m_pSoloBtn->move( 30, 17);
116        m_pSoloBtn->setToolTip( trUtf8( "Solo" ) );
117        connect(m_pSoloBtn, SIGNAL(clicked(Button*)), this, SLOT(click(Button*)));
118
119        // pan rotary
120        m_pPanRotary = new Rotary( this, Rotary::TYPE_CENTER, trUtf8( "Pan" ), false, true);
121        m_pPanRotary->move( 14, 32 );
122        connect( m_pPanRotary, SIGNAL( valueChanged(Rotary*) ), this, SLOT( panChanged(Rotary*) ) );
123        pAction = new Action("PAN_ABSOLUTE");
124        pAction->setParameter1( QString::number(nInstr ));
125        pAction->setParameter2( QString::number( 1 ));
126        m_pPanRotary->setAction(pAction);
127
128        // FX send
129        uint y = 0;
130        for (uint i = 0; i < MAX_FX; i++) {
131                m_pKnob[i] = new Knob(this);
132                pAction = new Action(QString( "EFFECT%1_LEVEL_ABSOLUTE" ).arg( QString::number(i+1) ));
133                pAction->setParameter1( QString::number( nInstr ) );
134                m_pKnob[i]->setAction( pAction );
135                if ( (i % 2) == 0 ) {
136                        m_pKnob[i]->move( 9, 63 + (20 * y) );
137                }
138                else {
139                        m_pKnob[i]->move( 30, 63 + (20 * y) );
140                        y++;
141                }
142                connect( m_pKnob[i], SIGNAL( valueChanged(Knob*) ), this, SLOT( knobChanged(Knob*) ) );
143        }
144
145        Preferences *pref = Preferences::get_instance();
146
147        QString family = pref->getMixerFontFamily();
148        int size = pref->getMixerFontPointSize();
149        QFont mixerFont( family, size );
150        float m_fFalloffTemp = pref->getMixerFalloffSpeed();
151        m_fFalloffTemp = (m_fFalloffTemp * 20) - 2;
152        m_nFalloff = (int)m_fFalloffTemp;
153
154        QPixmap textBackground;
155        bool ok = textBackground.load( Skin::getImagePath() + "/mixerPanel/mixerline_text_background.png" );
156        if( ok == false ){
157                ERRORLOG( "Error loading pixmap" );
158        }
159
160        // instrument name widget
161        m_pNameWidget = new InstrumentNameWidget( this );
162        m_pNameWidget->move( 6, 128 );
163        m_pNameWidget->setToolTip( trUtf8( "Instrument name (double click to edit)" ) );
164        connect( m_pNameWidget, SIGNAL( doubleClicked () ), this, SLOT( nameClicked() ) );
165        connect( m_pNameWidget, SIGNAL( clicked () ), this, SLOT( nameSelected() ) );
166
167        // m_pFader
168        m_pFader = new Fader( this, false, false );
169        m_pFader->move( 23, 128 );
170        m_pFader->setMinValue( 0.0 );
171        m_pFader->setMaxValue( 1.5 );
172        connect( m_pFader, SIGNAL( valueChanged(Fader*) ), this, SLOT( faderChanged(Fader*) ) );
173
174        pAction = new Action("STRIP_VOLUME_ABSOLUTE");
175        pAction->setParameter1( QString::number(nInstr) );
176        m_pFader->setAction( pAction );
177
178
179        m_pPeakLCD = new LCDDisplay( this, LCDDigit::SMALL_BLUE, 4 );
180        m_pPeakLCD->move( 10, 106 );
181        m_pPeakLCD->setText( "0.00" );
182        QPalette lcdPalette;
183        lcdPalette.setColor( QPalette::Background, QColor( 49, 53, 61 ) );
184        m_pPeakLCD->setPalette( lcdPalette );
185}
186
187
188
189MixerLine::~MixerLine()
190{
191//      INFOLOG( "DESTROY" );
192        //delete m_pFader;
193}
194
195
196
197void MixerLine::updateMixerLine()
198{
199        if ( m_nPeakTimer > m_nFalloff ) {
200                if ( m_fMaxPeak > 0.05f ) {
201                        m_fMaxPeak = m_fMaxPeak - 0.05f;
202                }
203                else {
204                        m_fMaxPeak = 0.0f;
205                        m_nPeakTimer = 0;
206                }
207                char tmp[20];
208                sprintf(tmp, "%#.2f", m_fMaxPeak );
209                m_pPeakLCD->setText(tmp);
210                if ( m_fMaxPeak > 1.0 ) {
211                        m_pPeakLCD->setSmallRed();
212                }
213                else {
214                        m_pPeakLCD->setSmallBlue();
215                }
216        }
217        m_nPeakTimer++;
218}
219
220
221
222void MixerLine::click(Button *ref) {
223        Song *song = (Hydrogen::get_instance())->getSong();
224
225        if (ref == m_pMuteBtn) {
226                song->__is_modified = true;
227                emit muteBtnClicked(this);
228        }
229        else if (ref == m_pSoloBtn) {
230                song->__is_modified = true;
231                emit soloBtnClicked(this);
232        }
233        else if (ref == m_pPlaySampleBtn) {
234                emit noteOnClicked(this);
235        }
236}
237
238
239
240void MixerLine::rightClick(Button *ref)
241{
242        if (ref == m_pPlaySampleBtn) {
243                emit noteOffClicked(this);
244        }
245
246}
247
248
249
250void MixerLine::faderChanged(Fader *ref)
251{
252        Song *song = (Hydrogen::get_instance())->getSong();
253        song->__is_modified = true;
254        emit volumeChanged(this);
255
256        char m_pFaderPos[100];
257        float value = ref->getValue();
258        sprintf( m_pFaderPos, "%#.2f",  value);
259        ( HydrogenApp::get_instance() )->setStatusBarMessage( trUtf8( "Set instrument volume [%1]" ).arg( m_pFaderPos ), 2000 );
260}
261
262
263
264bool MixerLine::isMuteClicked() {
265        return m_pMuteBtn->isPressed();
266}
267
268
269
270void MixerLine::setMuteClicked(bool isClicked) {
271        m_pMuteBtn->setPressed(isClicked);
272}
273
274
275
276bool MixerLine::isSoloClicked() {
277        return m_pSoloBtn->isPressed();
278}
279
280
281
282void MixerLine::setSoloClicked(bool isClicked) {
283        m_pSoloBtn->setPressed(isClicked);
284}
285
286
287
288float MixerLine::getVolume()
289{
290        return m_pFader->getValue();
291}
292
293
294
295void MixerLine::setVolume( float value )
296{
297        m_pFader->setValue( value );
298}
299
300
301
302void MixerLine::setPeak_L( float peak ) {
303        if (peak != getPeak_L() ) {
304                m_pFader->setPeak_L( peak );
305                if (peak > m_fMaxPeak) {
306                        if ( peak < 0.1f ) {
307                                peak = 0.0f;
308                        }
309                        char tmp[20];
310                        sprintf(tmp, "%#.2f", peak);
311                        m_pPeakLCD->setText( tmp );
312                        if ( peak > 1.0 ) {
313                                m_pPeakLCD->setSmallRed();
314                        }
315                        else {
316                                m_pPeakLCD->setSmallBlue();
317                        }
318                        m_fMaxPeak = peak;
319                        m_nPeakTimer = 0;
320                }
321        }
322}
323
324
325
326float MixerLine::getPeak_L() {
327        return m_pFader->getPeak_L();
328}
329
330
331
332void MixerLine::setPeak_R( float peak ) {
333        if (peak != getPeak_R() ) {
334                m_pFader->setPeak_R( peak );
335                if (peak > m_fMaxPeak) {
336                        if ( peak < 0.1f ) {
337                                peak = 0.0f;
338                        }
339                        char tmp[20];
340                        sprintf(tmp, "%#.2f", peak);
341                        m_pPeakLCD->setText( tmp );
342                        if ( peak > 1.0 ) {
343                                m_pPeakLCD->setSmallRed();
344                        }
345                        else {
346                                m_pPeakLCD->setSmallBlue();
347                        }
348                        m_fMaxPeak = peak;
349                        m_nPeakTimer = 0;
350                }
351        }
352}
353
354
355
356float MixerLine::getPeak_R() {
357        return m_pFader->getPeak_R();
358}
359
360
361
362
363
364void MixerLine::nameClicked() {
365        emit instrumentNameClicked(this);
366}
367
368
369
370void MixerLine::nameSelected() {
371        emit instrumentNameSelected(this);
372}
373
374
375
376
377
378void MixerLine::panChanged(Rotary *ref)
379{
380        Song *song = Hydrogen::get_instance()->getSong();
381        song->__is_modified = true;
382        emit panChanged( this );
383
384        float panValue = ref->getValue();
385        float pan_L, pan_R;
386        if (panValue > 0.5) {
387                pan_L = (1.0 - panValue) * 2.0;
388                pan_R = 1.0;
389        } else {
390                pan_L = 1.0;
391                pan_R = panValue * 2.0;
392        }
393
394        char m_pFaderPos[100];
395        sprintf( m_pFaderPos, "%#.2fL, %#.2fR",  pan_L, pan_R);
396        HydrogenApp::get_instance()->setStatusBarMessage( trUtf8( "Set instr. pan [%1]" ).arg( m_pFaderPos ), 2000 );
397
398        m_pPanRotary->setToolTip( QString("Pan ") + QString( m_pFaderPos ) );
399}
400
401
402
403float MixerLine::getPan()
404{
405        return m_pPanRotary->getValue();
406}
407
408
409
410void MixerLine::setPan(float fValue)
411{
412        if ( fValue != m_pPanRotary->getValue() ) {
413                m_pPanRotary->setValue( fValue );
414                float pan_L, pan_R;
415                if (fValue > 0.5) {
416                        pan_L = (1.0 - fValue) * 2.0;
417                        pan_R = 1.0;
418                } else {
419                        pan_L = 1.0;
420                        pan_R = fValue * 2.0;
421                }
422                char m_pFaderPos[100];
423                sprintf( m_pFaderPos, "Pan %#.2fL, %#.2fR",  pan_L, pan_R);
424                m_pPanRotary->setToolTip( QString( m_pFaderPos ) );
425        }
426}
427
428
429void MixerLine::setPlayClicked( bool clicked ) {
430        m_pTriggerSampleLED->setPressed( clicked );
431}
432
433
434void MixerLine::knobChanged(Knob* pRef)
435{
436//      infoLog( "knobChanged" );
437        for (uint i = 0; i < MAX_FX; i++) {
438                if (m_pKnob[i] == pRef) {
439                        emit knobChanged( this, i );
440                        break;
441                }
442        }
443}
444
445
446void MixerLine::setFXLevel( uint nFX, float fValue )
447{
448        if (nFX > MAX_FX) {
449                ERRORLOG( QString("[setFXLevel] nFX > MAX_FX (nFX=%1)").arg(nFX) );
450        }
451        m_pKnob[nFX]->setValue( fValue );
452}
453
454float MixerLine::getFXLevel(uint nFX)
455{
456        if (nFX > MAX_FX) {
457                ERRORLOG( QString("[setFXLevel] nFX > MAX_FX (nFX=%1)").arg(nFX) );
458        }
459        return m_pKnob[nFX]->getValue();
460}
461
462
463void MixerLine::setSelected( bool bIsSelected )
464{
465        if (m_bIsSelected == bIsSelected )      return;
466
467        m_bIsSelected = bIsSelected;
468        if (m_bIsSelected) {
469                setPixmap( "/mixerPanel/mixerline_background_on.png" );
470        }
471        else {
472                setPixmap( "/mixerPanel/mixerline_background.png" );
473        }
474
475}
476
477
478
479
480
481// ::::::::::::::::::::::::::::
482
483
484
485
486MasterMixerLine::MasterMixerLine(QWidget* parent)
487 : PixmapWidget( parent, "MasterMixerLine" )
488{
489        m_nWidth = MASTERMIXERLINE_WIDTH;
490        m_nHeight = MASTERMIXERLINE_HEIGHT;
491        m_nPeakTimer = 0;
492
493        setMinimumSize( m_nWidth, m_nHeight );
494        setMaximumSize( m_nWidth, m_nHeight );
495        resize( m_nWidth, m_nHeight );
496        QPalette defaultPalette;
497        defaultPalette.setColor( QPalette::Background, QColor( 58, 62, 72 ) );
498        this->setPalette( defaultPalette );
499
500        // Background image
501        setPixmap( "/mixerPanel/masterMixerline_background.png" );
502
503        Preferences *pref = Preferences::get_instance();
504        int size = pref->getMixerFontPointSize();
505        QString family = pref->getMixerFontFamily();
506        float m_fFalloffTemp = pref->getMixerFalloffSpeed();
507        m_fFalloffTemp = (m_fFalloffTemp * 20) - 2;
508        m_nFalloff = (int)m_fFalloffTemp;
509
510        m_pMasterFader = new MasterFader( this );
511        m_pMasterFader->setMin( 0.0 );
512        m_pMasterFader->setMax( 1.5 );
513        m_pMasterFader->move( 24, MASTERMIXERLINE_FADER_H );
514        connect( m_pMasterFader, SIGNAL( valueChanged(MasterFader*) ), this, SLOT( faderChanged(MasterFader*) ) );
515
516        Action* pAction = new Action("MASTER_VOLUME_ABSOLUTE");
517        m_pMasterFader->setAction( pAction );
518
519        QFont mixerFont( family, size );
520
521        m_pPeakLCD = new LCDDisplay( this, LCDDigit::SMALL_BLUE, 4 );
522        m_pPeakLCD->move( 23, 53 );
523        m_pPeakLCD->setText( "0.00" );
524        QPalette lcdPalette;
525        lcdPalette.setColor( QPalette::Background, QColor( 49, 53, 61 ) );
526        m_pPeakLCD->setPalette( lcdPalette );
527
528        m_pHumanizeVelocityRotary = new Rotary( this, Rotary::TYPE_NORMAL, trUtf8( "Humanize velocity" ), false, false );
529        m_pHumanizeVelocityRotary->move( 74, 88 );
530        connect( m_pHumanizeVelocityRotary, SIGNAL( valueChanged(Rotary*) ), this, SLOT( rotaryChanged(Rotary*) ) );
531
532        m_pHumanizeTimeRotary = new Rotary( this, Rotary::TYPE_NORMAL, trUtf8( "Humanize time" ), false, false );
533        m_pHumanizeTimeRotary->move( 74, 125 );
534        connect( m_pHumanizeTimeRotary, SIGNAL( valueChanged(Rotary*) ), this, SLOT( rotaryChanged(Rotary*) ) );
535
536        m_pSwingRotary = new Rotary( this,  Rotary::TYPE_NORMAL, trUtf8( "Swing" ), false, false );
537        m_pSwingRotary->move( 74, 162 );
538        connect( m_pSwingRotary, SIGNAL( valueChanged(Rotary*) ), this, SLOT( rotaryChanged(Rotary*) ) );
539
540        // Mute btn
541        m_pMuteBtn = new ToggleButton(
542                        this,
543                        "/mixerPanel/master_mute_on.png",
544                        "/mixerPanel/master_mute_off.png",
545                        "/mixerPanel/master_mute_over.png",
546                        QSize( 42, 13 )
547        );
548        m_pMuteBtn->move( 20, 32 );
549        connect( m_pMuteBtn, SIGNAL( clicked(Button*) ), this, SLOT( muteClicked(Button*) ) );
550        m_pMuteBtn->setAction( new Action("MUTE_TOGGLE"));
551}
552
553
554
555
556MasterMixerLine::~MasterMixerLine()
557{
558//      cout << "MixerLine destroy" << endl;
559        m_fMaxPeak = 0.0;
560}
561
562
563
564void MasterMixerLine::muteClicked(Button* pBtn)
565{
566        Hydrogen::get_instance()->getSong()->__is_muted = pBtn->isPressed();
567}
568
569
570
571void MasterMixerLine::faderChanged(MasterFader *ref)
572{
573        m_pMasterFader->setValue( ref->getValue() );
574
575        emit volumeChanged(this);
576
577        Song *song = Hydrogen::get_instance()->getSong();
578        song->__is_modified = true;
579
580        char m_pMasterFaderPos[100];
581        float value = ref->getValue();
582        sprintf( m_pMasterFaderPos, "%#.2f",  value);
583        ( HydrogenApp::get_instance() )->setStatusBarMessage( trUtf8( "Set master volume [%1]" ).arg( m_pMasterFaderPos ), 2000 );
584}
585
586
587
588
589float MasterMixerLine::getVolume()
590{
591        return m_pMasterFader->getValue();
592}
593
594
595
596void MasterMixerLine::setVolume( float value )
597{
598        m_pMasterFader->setValue( value );
599}
600
601
602
603void MasterMixerLine::setPeak_L(float peak)
604{
605        if ( peak != getPeak_L() ) {
606                m_pMasterFader->setPeak_L(peak);
607                if (peak > m_fMaxPeak) {
608                        if ( peak < 0.1f ) {
609                                peak = 0.0f;
610                        }
611                        char tmp[20];
612                        sprintf(tmp, "%#.2f", peak);
613                        m_pPeakLCD->setText(tmp);
614                        if ( peak > 1.0 ) {
615                                m_pPeakLCD->setSmallRed();
616                        }
617                        else {
618                                m_pPeakLCD->setSmallBlue();
619                        }
620                        m_fMaxPeak = peak;
621                        m_nPeakTimer = 0;
622                }
623        }
624}
625
626
627
628
629float MasterMixerLine::getPeak_L() {
630        return m_pMasterFader->getPeak_L();
631}
632
633
634
635void MasterMixerLine::setPeak_R(float peak) {
636        if ( peak != getPeak_R() ) {
637                m_pMasterFader->setPeak_R(peak);
638                if (peak > m_fMaxPeak) {
639                        if ( peak < 0.1f ) {
640                                peak = 0.0f;
641                        }
642                        char tmp[20];
643                        sprintf(tmp, "%#.2f", peak);
644                        m_pPeakLCD->setText(tmp);
645                        if ( peak > 1.0 ) {
646                                m_pPeakLCD->setSmallRed();
647                        }
648                        else {
649                                m_pPeakLCD->setSmallBlue();
650                        }
651                        m_fMaxPeak = peak;
652                        m_nPeakTimer = 0;
653                }
654        }
655}
656
657
658
659float MasterMixerLine::getPeak_R() {
660        return m_pMasterFader->getPeak_R();
661}
662
663
664
665void MasterMixerLine::updateMixerLine()
666{
667
668        if ( m_nPeakTimer > m_nFalloff ) {
669                if ( m_fMaxPeak  > 0.05f ) {
670                        m_fMaxPeak = m_fMaxPeak - 0.05f;
671                }
672                else {
673                        m_fMaxPeak = 0.0f;
674                        m_nPeakTimer = 0;
675                }
676                char tmp[20];
677                sprintf(tmp, "%#.2f", m_fMaxPeak );
678                m_pPeakLCD->setText(tmp);
679                if ( m_fMaxPeak > 1.0 ) {
680                        m_pPeakLCD->setSmallRed();
681                }
682                else {
683                        m_pPeakLCD->setSmallBlue();
684                }
685        }
686        m_nPeakTimer++;
687
688        Song *pSong = Hydrogen::get_instance()->getSong();
689        if ( pSong ) {
690                m_pHumanizeTimeRotary->setValue( pSong->get_humanize_time_value() );
691                m_pHumanizeVelocityRotary->setValue( pSong->get_humanize_velocity_value() );
692                m_pSwingRotary->setValue( pSong->get_swing_factor() );
693        }
694        else {
695                WARNINGLOG( "pSong == NULL ");
696        }
697}
698
699
700void MasterMixerLine::rotaryChanged( Rotary *pRef )
701{
702        QString sMsg;
703        float fVal = pRef->getValue();
704        char sVal[100];
705        sprintf( sVal, "%#.2f", fVal);
706
707        Hydrogen *pEngine = Hydrogen::get_instance();
708        AudioEngine::get_instance()->lock( RIGHT_HERE );
709
710        if ( pRef == m_pHumanizeTimeRotary ) {
711                pEngine->getSong()->set_humanize_time_value( fVal );
712                sMsg = trUtf8( "Set humanize time parameter [%1]").arg( sVal );
713        }
714        else if ( pRef == m_pHumanizeVelocityRotary ) {
715                pEngine->getSong()->set_humanize_velocity_value( fVal );
716                sMsg = trUtf8( "Set humanize velocity parameter [%1]").arg( sVal );
717        }
718        else if ( pRef == m_pSwingRotary ) {
719                pEngine->getSong()->set_swing_factor( fVal );
720                sMsg = trUtf8( "Set swing factor [%1]").arg( sVal );
721        }
722        else {
723                ERRORLOG( "[knobChanged] Unhandled knob" );
724        }
725
726        AudioEngine::get_instance()->unlock();
727
728        ( HydrogenApp::get_instance() )->setStatusBarMessage( sMsg, 2000 );
729}
730
731
732
733
734/////////////////////////////////////////
735
736
737FxMixerLine::FxMixerLine(QWidget* parent)
738 : PixmapWidget( parent, "FxMixerLine" )
739{
740        m_nWidth = MIXERLINE_WIDTH;
741        m_nHeight = MIXERLINE_HEIGHT;
742
743        setMinimumSize( m_nWidth, m_nHeight );
744        setMaximumSize( m_nWidth, m_nHeight );
745        resize( m_nWidth, m_nHeight );
746//      QPalette defaultPalette;
747//      defaultPalette.setColor( QPalette::Background, QColor( 58, 62, 72 ) );
748//      this->setPalette( defaultPalette );
749        m_fMaxPeak = 0.0;
750
751        // MixerLine Background image
752        setPixmap( "/mixerPanel/mixerline_background.png" );
753
754        // MixerLine LABEL Background image
755//      QPixmap mixerLineLabelBackground;
756//      ok = mixerLineLabelBackground.load(Skin::getImagePath() + "/mixerPanel/mixerline_label_background.png");
757//      if( ok == false ){
758//              ERRORLOG( "Error loading pixmap" );
759//      }
760
761//      QPixmap textBackground;
762//      ok = textBackground.load( Skin::getImagePath() + "/mixerPanel/mixerline_text_background.png" );
763//      if( ok == false ){
764//              ERRORLOG( "Error loading pixmap" );
765//      }
766
767
768        // active button
769        activeBtn = new ToggleButton(
770                        this,
771                        "/mixerPanel/btn_on_on.png",
772                        "/mixerPanel/btn_on_off.png",
773                        "/mixerPanel/btn_on_over.png",
774                        QSize( 18, 12 )
775        );
776        activeBtn->move( 2, 5 );
777        activeBtn->setToolTip( trUtf8( "FX on/off") );
778        connect( activeBtn, SIGNAL( clicked(Button*) ), this, SLOT( click(Button*) ) );
779
780        Preferences *pref = Preferences::get_instance();
781
782        // m_pFader
783        m_pFader = new Fader( this, false, false );
784        m_pFader->move( 22, 106 );
785        connect( m_pFader, SIGNAL( valueChanged(Fader*) ), this, SLOT( faderChanged(Fader*) ) );
786
787        QString family = pref->getMixerFontFamily();
788        int size = pref->getMixerFontPointSize();
789        QFont mixerFont( family, size );
790
791
792        m_pNameWidget = new InstrumentNameWidget( this );
793        m_pNameWidget->move( 2, 106 );
794        m_pNameWidget->setText( trUtf8( "Master output" ) );
795
796        m_pPeakLCD = new LCDDisplay( this, LCDDigit::SMALL_BLUE, 4 );
797        m_pPeakLCD->move( 2, MIXERLINE_LABEL_H );
798        m_pPeakLCD->setText( "0.00" );
799}
800
801
802
803FxMixerLine::~FxMixerLine()
804{
805        delete m_pFader;
806}
807
808
809
810void FxMixerLine::click(Button *ref) {
811        Song *song = Hydrogen::get_instance()->getSong();
812
813        if (ref == activeBtn ) {
814                song->__is_modified = true;
815                emit activeBtnClicked( this );
816        }
817}
818
819
820
821void FxMixerLine::faderChanged(Fader *ref)
822{
823        UNUSED( ref );
824
825        m_fMaxPeak = 0.0;
826        char tmp[20];
827        sprintf( tmp, "%#.2f", m_fMaxPeak );
828        m_pPeakLCD->setText( tmp );
829        if ( m_fMaxPeak > 1.0 ) {
830                m_pPeakLCD->setSmallRed();
831        }
832        else {
833                m_pPeakLCD->setSmallBlue();
834        }
835
836
837        Song *song = Hydrogen::get_instance()->getSong();
838        song->__is_modified = true;
839        emit volumeChanged( this );
840
841}
842
843
844
845float FxMixerLine::getVolume()
846{
847        return m_pFader->getValue();
848}
849
850
851
852void FxMixerLine::setVolume( float value )
853{
854        m_pFader->setValue( value );
855}
856
857
858
859void FxMixerLine::setPeak_L( float peak )
860{
861        if (peak != getPeak_L() ) {
862                m_pFader->setPeak_L( peak );
863                if (peak > m_fMaxPeak) {
864                        char tmp[20];
865                        sprintf(tmp, "%#.2f", peak);
866                        m_pPeakLCD->setText(tmp);
867                        if ( peak > 1.0 ) {
868                                m_pPeakLCD->setSmallRed();
869                        }
870                        else {
871                                m_pPeakLCD->setSmallBlue();
872                        }
873
874                        m_fMaxPeak = peak;
875                }
876        }
877}
878
879
880
881float FxMixerLine::getPeak_L()
882{
883        return m_pFader->getPeak_L();
884}
885
886
887
888
889void FxMixerLine::setPeak_R(float peak)
890{
891        if (peak != getPeak_R() ) {
892                m_pFader->setPeak_R( peak );
893                if (peak > m_fMaxPeak) {
894                        char tmp[20];
895                        sprintf(tmp, "%#.2f", peak);
896                        m_pPeakLCD->setText(tmp);
897                        if ( peak > 1.0 ) {
898                                m_pPeakLCD->setSmallRed();
899                        }
900                        else {
901                                m_pPeakLCD->setSmallBlue();
902                        }
903
904                        m_fMaxPeak = peak;
905                }
906        }
907}
908
909
910
911
912float FxMixerLine::getPeak_R()
913{
914        return m_pFader->getPeak_R();
915}
916
917
918
919
920bool FxMixerLine::isFxActive()
921{
922        return activeBtn->isPressed();
923}
924
925
926
927
928void FxMixerLine::setFxActive( bool active )
929{
930        activeBtn->setPressed( active );
931}
932
933
934
935
936
937
938////////////////////////////////
939
940//QPixmap* InstrumentNameWidget::m_pBackground = NULL;
941
942
943InstrumentNameWidget::InstrumentNameWidget(QWidget* parent)
944 : PixmapWidget( parent, "InstrumentNameWidget" )
945{
946//      infoLog( "INIT" );
947        m_nWidgetWidth = 17;
948        m_nWidgetHeight = 116;
949
950        Preferences *pref = Preferences::get_instance();
951        QString family = pref->getMixerFontFamily();
952        int size = pref->getMixerFontPointSize();
953        m_mixerFont.setFamily( family );
954        m_mixerFont.setPointSize( size );
955//      m_mixerFont.setBold( true );
956//      m_mixerFont.setItalic( true );
957
958        setPixmap( "/mixerPanel/mixerline_label_background.png" );
959
960        this->resize( m_nWidgetWidth, m_nWidgetHeight );
961}
962
963
964
965
966InstrumentNameWidget::~InstrumentNameWidget()
967{
968//      infoLog( "DESTROY" );
969}
970
971
972
973void InstrumentNameWidget::paintEvent( QPaintEvent* ev )
974{
975        PixmapWidget::paintEvent( ev );
976
977        QPainter p( this );
978
979        p.setPen( QColor(230, 230, 230) );
980        p.setFont( m_mixerFont );
981        p.rotate( -90 );
982        p.drawText( -m_nWidgetHeight + 5, 0, m_nWidgetHeight - 10, m_nWidgetWidth, Qt::AlignVCenter, m_sInstrName );
983}
984
985
986
987
988void InstrumentNameWidget::setText( QString text )
989{
990        if (m_sInstrName != text ) {
991                m_sInstrName = text;
992                update();
993        }
994}
995
996
997
998QString InstrumentNameWidget::text()
999{
1000        return m_sInstrName;
1001}
1002
1003
1004
1005void InstrumentNameWidget::mousePressEvent( QMouseEvent * e )
1006{
1007        UNUSED( e );
1008        emit clicked();
1009}
1010
1011
1012
1013void InstrumentNameWidget::mouseDoubleClickEvent( QMouseEvent * e )
1014{
1015        UNUSED( e );
1016        emit doubleClicked();
1017}
1018
1019
1020
1021// :::::::::::::::::::::
1022
1023
1024
1025LadspaFXMixerLine::LadspaFXMixerLine(QWidget* parent)
1026 : PixmapWidget( parent, "LadspaFXMixerLine" )
1027{
1028        resize( 194, 43 );
1029        setMinimumSize( width(), height() );
1030        setMaximumSize( width(), height() );
1031
1032        setPixmap( "/mixerPanel/fxline_background.png" );
1033
1034        // active button
1035        m_pActiveBtn = new ToggleButton(
1036                        this,
1037                        "/mixerPanel/bypass_on.png",
1038                        "/mixerPanel/bypass_off.png",
1039                        "/mixerPanel/bypass_over.png",
1040                        QSize( 30, 13 )
1041        );
1042        m_pActiveBtn->move( 55, 25 );
1043        m_pActiveBtn->setToolTip( trUtf8( "FX bypass") );
1044        connect( m_pActiveBtn, SIGNAL( clicked(Button*) ), this, SLOT( click(Button*) ) );
1045
1046        // edit button
1047        m_pEditBtn = new Button(
1048                        this,
1049                        "/mixerPanel/edit_on.png",
1050                        "/mixerPanel/edit_off.png",
1051                        "/mixerPanel/edit_over.png",
1052                        QSize( 30, 13 )
1053        );
1054        m_pEditBtn->move( 87, 25 );
1055        m_pEditBtn->setToolTip( trUtf8( "Edit FX parameters") );
1056        connect( m_pEditBtn, SIGNAL( clicked(Button*) ), this, SLOT( click(Button*) ) );
1057
1058        // instrument name widget
1059        m_pNameLCD = new LCDDisplay( this, LCDDigit::SMALL_BLUE, 13 );
1060        m_pNameLCD->move( 11, 9 );
1061        m_pNameLCD->setText( "No name" );
1062        m_pNameLCD->setToolTip( trUtf8( "Ladspa FX name" ) );
1063
1064        // m_pRotary
1065        m_pRotary = new Rotary( this,  Rotary::TYPE_NORMAL, trUtf8( "Effect return" ), false, false );
1066        m_pRotary->move( 132, 4 );
1067        connect( m_pRotary, SIGNAL( valueChanged(Rotary*) ), this, SLOT( rotaryChanged(Rotary*) ) );
1068}
1069
1070
1071
1072LadspaFXMixerLine::~LadspaFXMixerLine()
1073{
1074//      infoLog( "DESTROY" );
1075}
1076
1077
1078
1079void LadspaFXMixerLine::setName(QString name)
1080{
1081        m_pNameLCD->setText( name );
1082}
1083
1084void LadspaFXMixerLine::click(Button *ref)
1085{
1086        if ( ref == m_pActiveBtn ) {
1087                emit activeBtnClicked( this );
1088        }
1089        else if( ref == m_pEditBtn ) {
1090                emit editBtnClicked( this );
1091        }
1092}
1093
1094
1095
1096bool LadspaFXMixerLine::isFxActive()
1097{
1098        return !m_pActiveBtn->isPressed();
1099}
1100
1101
1102
1103
1104void LadspaFXMixerLine::setFxActive( bool active )
1105{
1106        m_pActiveBtn->setPressed( !active );
1107}
1108
1109
1110
1111void LadspaFXMixerLine::rotaryChanged(Rotary *ref)
1112{
1113        UNUSED( ref );
1114        m_fMaxPeak = 0.0;
1115//      char tmp[20];
1116//      sprintf(tmp, "%#.1f", fMaxPeak);
1117//      m_pVolumeLbl->setText(tmp);
1118
1119        Song *song = Hydrogen::get_instance()->getSong();
1120        song->__is_modified = true;
1121        emit volumeChanged(this);
1122}
1123
1124
1125
1126void LadspaFXMixerLine::setPeaks( float fPeak_L, float fPeak_R )
1127{
1128        UNUSED( fPeak_L );
1129        UNUSED( fPeak_R );
1130/*
1131        m_pPeakmeter->setPeak_L( fPeak_L );
1132        m_pPeakmeter->setPeak_R( fPeak_R );
1133        m_pPeakmeter->updateFader();
1134*/
1135}
1136
1137
1138
1139void LadspaFXMixerLine::getPeaks( float *fPeak_L, float *fPeak_R )
1140{
1141        UNUSED( fPeak_L );
1142        UNUSED( fPeak_R );
1143/*
1144        (*fPeak_L) = m_pFader->getPeak_L();
1145        (*fPeak_R) = m_pFader->getPeak_R();
1146*/
1147}
1148
1149
1150
1151float LadspaFXMixerLine::getVolume()
1152{
1153        return m_pRotary->getValue();
1154}
1155
1156
1157
1158void LadspaFXMixerLine::setVolume(float value)
1159{
1160        m_pRotary->setValue( value );
1161//      m_pRotary->updateRotary();
1162}
Note: See TracBrowser for help on using the browser.