Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable mixer color-coding #5589

Merged
merged 22 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion include/ColorChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@
*
*/

#include <QColorDialog>
#include <QApplication>
#include <QColor>
#include <QColorDialog>
#include <QKeyEvent>
#include <QVector>

class ColorChooser: public QColorDialog
{
public:
ColorChooser(const QColor &initial, QWidget *parent): QColorDialog(initial, parent) {};
ColorChooser(QWidget *parent): QColorDialog(parent) {};

enum class CCPalette {Default, Track, Mixer};

//! Set global palette via array, checking bounds
void setPalette (const QVector<QColor>);
//! Set global paletter via enum
void setPalette (const CCPalette);
//! Set palette via enum, return self pointer for chaining
ColorChooser* setPaletteAndPoint (const CCPalette);

protected:
// Forward key events to the parent to prevent stuck notes when the dialog gets focus
Expand All @@ -38,4 +49,10 @@ class ColorChooser: public QColorDialog
QKeyEvent ke(*event);
QApplication::sendEvent(parentWidget(), &ke);
}

private:
//! Copy the current QColorDialog palette into an array
QVector<QColor> defaultPalette();
//! Generate a nice palette, with adjustable value
QVector<QColor> nicePalette (const int);
};
4 changes: 3 additions & 1 deletion include/FxLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QLineEdit>
#include <QWidget>

#include "ColorChooser.h"
#include "Knob.h"
#include "LcdWidget.h"
#include "SendButtonIndicator.h"
Expand Down Expand Up @@ -85,6 +86,8 @@ class FxLine : public QWidget
private:
void drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis );
QString elideName( const QString & name );
QColor mutedColor( QPainter* p, const FxLine *fxLine, bool isActive );
QColor unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive );

FxMixerView * m_mv;
LcdWidget* m_lcd;
Expand All @@ -99,7 +102,6 @@ class FxLine : public QWidget
bool m_inRename;
QLineEdit * m_renameLineEdit;
QGraphicsView * m_view;
QColorDialog m_dialog;

public slots:
void renameChannel();
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SET(LMMS_SRCS

gui/dialogs/FileDialog.cpp
gui/dialogs/VersionedSaveDialog.cpp
gui/dialogs/ColorChooser.cpp

gui/editors/AutomationEditor.cpp
gui/editors/BBEditor.cpp
Expand Down
81 changes: 81 additions & 0 deletions src/gui/dialogs/ColorChooser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* ColorChooser.cpp - definition of ColorChooser class.
*
* Copyright (c) 2020 russiankumar <adityakumar4644/at/gmail/dot/com>
*
* This file is part of LMMS - https://lmms.io
*
* 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.
*
* This program 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#include <ColorChooser.h>



void ColorChooser::setPalette (const QVector<QColor> colors)
{
const int max = qMin (colors.size(), 48);
for (int i = 0; i < max; i++)
{
ColorChooser::setStandardColor (i, colors[i]);
}
}


void ColorChooser::setPalette (const CCPalette palette)
{
switch (palette)
{
case CCPalette::Default: setPalette (defaultPalette()); break;
case CCPalette::Mixer: setPalette (nicePalette(140)); break;
case CCPalette::Track: setPalette (nicePalette(150)); break;
}
}


ColorChooser* ColorChooser::setPaletteAndPoint (const CCPalette palette)
{
setPalette (palette);
return this;
}




QVector<QColor> ColorChooser::defaultPalette()
{
QVector <QColor> result;
for (int i = 0; i < 48; i++)
{
result.push_back (QColorDialog::standardColor(i));
}
return result;
}


QVector<QColor> ColorChooser::nicePalette (const int base)
{
QVector <QColor> result;
result.resize(48);
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 6; y++)
{
result[6 * x + y].setHsl (qMax(0, 44 * x - 1), 150 - 20 * y, base - 10 * y);
}
}
return result;
}
48 changes: 28 additions & 20 deletions src/gui/widgets/FxLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) :
m_strokeOuterInactive( 0, 0, 0 ),
m_strokeInnerActive( 0, 0, 0 ),
m_strokeInnerInactive( 0, 0, 0 ),
m_inRename( false ),
m_dialog( QColor( 0, 0, 0 ) )
m_inRename( false )
{
if( !s_sendBgArrow )
{
Expand Down Expand Up @@ -129,17 +128,6 @@ FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) :

srand( time( 0 ) );

QColor buffer;
for( int i = 0; i < 48; i += 6 )
{
for( int j = 0; j < 6; j++ )
{
buffer.setHsl( qMax( 0, 44 * ( i / 6 ) - 1 ), 150 - 20 * j, 140 - 10 * j );
m_dialog.setStandardColor( i + j, buffer );
}

}

}


Expand All @@ -165,6 +153,30 @@ void FxLine::setChannelIndex( int index )



QColor FxLine::mutedColor( QPainter* p, const FxLine *fxLine, bool isActive )
{
return isActive ? fxLine->backgroundActive().color() : p->background().color();
}




QColor FxLine::unmutedColor( QPainter* p, const FxLine *fxLine, bool isActive )
{
auto channel = Engine::fxMixer()->effectChannel( m_channelIndex );

if( channel->m_hasColor )
{
return isActive ? channel->m_color.darker( 120 ) : channel->m_color.darker( 150 );
}
else
{
return isActive ? fxLine->backgroundActive().color() : p->background().color();
}
}



void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool sendToThis, bool receiveFromThis )
{
auto channel = Engine::fxMixer()->effectChannel( m_channelIndex );
Expand All @@ -180,11 +192,7 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, bool isActive, bool
int width = fxLine->rect().width();
int height = fxLine->rect().height();

QColor color = muted ? ( isActive ? fxLine->backgroundActive().color() : p->background().color() )
: ( channel->m_hasColor ? ( isActive ? channel->m_color.darker( 120 )
: channel->m_color.darker( 150 ) )
: ( isActive ? fxLine->backgroundActive().color()
: p->background().color() ) );
QColor color = muted ? mutedColor( p, fxLine, isActive ) : unmutedColor( p, fxLine, isActive );

p->fillRect( fxLine->rect(), color );

Expand Down Expand Up @@ -434,7 +442,7 @@ void FxLine::changeColor()
{
auto channel = Engine::fxMixer()->effectChannel( m_channelIndex );

QColor new_color = m_dialog.getColor( channel->m_color );
auto new_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->getColor( channel->m_color );
if( ! new_color.isValid() )
{ return; }

Expand All @@ -454,7 +462,7 @@ void FxLine::randomColor()
{
auto channel = Engine::fxMixer()->effectChannel( m_channelIndex );

channel->m_color = m_dialog.standardColor( rand() % 48 );
channel->m_color = ColorChooser( this ).setPaletteAndPoint( ColorChooser::CCPalette::Mixer )->standardColor( rand() % 48 );
channel->m_hasColor = true;

update();
Expand Down