Skip to content

Commit f5d0524

Browse files
authored
Enable track-wide color coding (#5573)
* Enable track-wide color coding * Add support for automation tracks * Allow saving & loading track colors * Allow track color to be reset to default * Partially migrate common settings to Track.cpp, fix bug * Completely migrate local TCO color functions to TCO class, fix bug * Set QColorDialog colors to better colors * Color the side of the track according to TCO colors * Disable color gradient when muted * Change selection color to depend on TCO color * Fix breaking builds * Bug fix * Fix another bug where BB track colors wouldn't load * Restore changed demo to original state * Fix BB Editor bug * Fix breaking builds * Allow random color picking * Fix copy-paste bug * Change how color is painted on a track * Cleanup, and implement per-pattern colors * Cleanup comments * Migrate some functions * Remove redundant function * Rename some functions * Migrate duplicates to superclass * Use ColorChooser and reorder some includes * Change how colors are saved * Fix some formatting * Fix some code * Change how clip colors work * Fix some unexpected behaviors * Fix note border coloring being green on colored tracks * Change name of an option * Remove redundant code * Fix ghost changes * Remove colorRgb * Rename backgroundColor, remove some variables we don't use * Remove a redundant variable * Migrate some duplicates to superclass * Check for nullpointer * Remove redundant variable * Update some logic * Change how muted colors are displayed * Change how dark muted tracks become * Place setModified() in appropriate places * Make getColorForDisplay() function * Change how colors are organised and saved * Remove m_useStyleColor * Remove a comment * Quick changes * Change how colors are saved * Remove redundant stuff * Remove redundant stuff pt. 2 * Change how colors are copied * Fixes pt. 3 * Fixes pt. 4 * Change spaces to tabs * Fix pseudochanges * Remove s_lastTCOColor * Fix pseudochanges pt. 2 * Fix breaking builds * Add files via upload * Add comments (again)
1 parent 8b2902c commit f5d0524

File tree

10 files changed

+337
-192
lines changed

10 files changed

+337
-192
lines changed
Binary file not shown.

include/AutomationPatternView.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727

2828
#include <QStaticText>
2929

30+
#include "AutomationPattern.h"
31+
#include "Song.h"
32+
#include "SongEditor.h"
3033
#include "Track.h"
3134

32-
class AutomationPattern;
33-
3435

3536
class AutomationPatternView : public TrackContentObjectView
3637
{

include/BBTrack.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,11 @@ class BBTCO : public TrackContentObject
5050
return( "bbtco" );
5151
}
5252

53-
unsigned int color() const
54-
{
55-
return( m_color.rgb() );
56-
}
57-
58-
QColor colorObj() const
59-
{
60-
return m_color;
61-
}
62-
63-
void setColor( const QColor & c )
64-
{
65-
m_color = QColor( c );
66-
}
67-
68-
void setUseStyleColor( bool b )
69-
{
70-
m_useStyleColor = b;
71-
}
72-
7353
int bbTrackIndex();
7454

7555
TrackContentObjectView * createView( TrackView * _tv ) override;
7656

7757
private:
78-
QColor m_color;
79-
bool m_useStyleColor;
8058

8159

8260
friend class BBTCOView;
@@ -92,11 +70,6 @@ class BBTCOView : public TrackContentObjectView
9270
BBTCOView( TrackContentObject * _tco, TrackView * _tv );
9371
virtual ~BBTCOView() = default;
9472

95-
QColor color() const
96-
{
97-
return( m_bbTCO->m_color );
98-
}
99-
void setColor( QColor _new_color );
10073

10174
public slots:
10275
void update() override;
@@ -105,8 +78,6 @@ protected slots:
10578
void openInBBEditor();
10679
void resetName();
10780
void changeName();
108-
void changeColor();
109-
void resetColor();
11081

11182

11283
protected:
@@ -162,27 +133,6 @@ class LMMS_EXPORT BBTrack : public Track
162133
m_disabledTracks.removeAll( _track );
163134
}
164135

165-
static void setLastTCOColor( const QColor & c )
166-
{
167-
if( ! s_lastTCOColor )
168-
{
169-
s_lastTCOColor = new QColor( c );
170-
}
171-
else
172-
{
173-
*s_lastTCOColor = QColor( c );
174-
}
175-
}
176-
177-
static void clearLastTCOColor()
178-
{
179-
if( s_lastTCOColor )
180-
{
181-
delete s_lastTCOColor;
182-
}
183-
s_lastTCOColor = NULL;
184-
}
185-
186136
protected:
187137
inline QString nodeName() const override
188138
{
@@ -196,8 +146,6 @@ class LMMS_EXPORT BBTrack : public Track
196146
typedef QMap<BBTrack *, int> infoMap;
197147
static infoMap s_infoMap;
198148

199-
static QColor * s_lastTCOColor;
200-
201149
friend class BBTrackView;
202150

203151
} ;

include/Track.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject
133133
{
134134
return m_autoResize;
135135
}
136+
137+
QColor color() const
138+
{
139+
return m_color;
140+
}
141+
142+
void setColor( const QColor & c )
143+
{
144+
m_color = c;
145+
}
146+
147+
bool hasColor();
148+
149+
void useCustomClipColor( bool b );
150+
151+
bool usesCustomClipColor()
152+
{
153+
return m_useCustomClipColor;
154+
}
136155

137156
virtual void movePosition( const MidiTime & pos );
138157
virtual void changeLength( const MidiTime & length );
@@ -154,6 +173,8 @@ class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject
154173

155174
MidiTime startTimeOffset() const;
156175
void setStartTimeOffset( const MidiTime &startTimeOffset );
176+
177+
void updateColor();
157178

158179
// Will copy the state of a TCO to another TCO
159180
static void copyStateTo( TrackContentObject *src, TrackContentObject *dst );
@@ -166,6 +187,7 @@ public slots:
166187
void lengthChanged();
167188
void positionChanged();
168189
void destroyedTCO();
190+
void trackColorChanged();
169191

170192

171193
private:
@@ -189,6 +211,9 @@ public slots:
189211

190212
bool m_selectViewOnCreate;
191213

214+
QColor m_color;
215+
bool m_useCustomClipColor;
216+
192217
friend class TrackContentObjectView;
193218

194219
} ;
@@ -264,11 +289,16 @@ class TrackContentObjectView : public selectableObject, public ModelView
264289
// some metadata to be written to the clipboard.
265290
static void remove( QVector<TrackContentObjectView *> tcovs );
266291
static void toggleMute( QVector<TrackContentObjectView *> tcovs );
292+
293+
QColor getColorForDisplay( QColor );
267294

268295
public slots:
269296
virtual bool close();
270297
void remove();
271298
void update() override;
299+
300+
void changeClipColor();
301+
void useTrackColor();
272302

273303
protected:
274304
enum ContextMenuAction
@@ -486,6 +516,10 @@ private slots:
486516
void cloneTrack();
487517
void removeTrack();
488518
void updateMenu();
519+
void changeTrackColor();
520+
void randomTrackColor();
521+
void resetTrackColor();
522+
void useTrackColor();
489523
void toggleRecording(bool on);
490524
void recordingOn();
491525
void recordingOff();
@@ -503,6 +537,9 @@ private slots:
503537

504538
signals:
505539
void trackRemovalScheduled( TrackView * t );
540+
void colorChanged( QColor & c );
541+
void colorParented();
542+
void colorReset();
506543

507544
} ;
508545

@@ -635,7 +672,16 @@ class LMMS_EXPORT Track : public Model, public JournallingObject
635672
{
636673
return m_processingLock.tryLock();
637674
}
638-
675+
676+
QColor color()
677+
{
678+
return m_color;
679+
}
680+
bool useColor()
681+
{
682+
return m_hasColor;
683+
}
684+
639685
BoolModel* getMutedModel();
640686

641687
public slots:
@@ -647,6 +693,8 @@ public slots:
647693

648694
void toggleSolo();
649695

696+
void trackColorChanged( QColor & c );
697+
void trackColorReset();
650698

651699
private:
652700
TrackContainer* m_trackContainer;
@@ -665,6 +713,9 @@ public slots:
665713
tcoVector m_trackContentObjects;
666714

667715
QMutex m_processingLock;
716+
717+
QColor m_color;
718+
bool m_hasColor;
668719

669720
friend class TrackView;
670721

src/core/AutomationPattern.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
538538
_this.setAttribute( "prog", QString::number( progressionType() ) );
539539
_this.setAttribute( "tens", QString::number( getTension() ) );
540540
_this.setAttribute( "mute", QString::number( isMuted() ) );
541+
542+
if( usesCustomClipColor() )
543+
{
544+
_this.setAttribute( "color", color().name() );
545+
}
541546

542547
for( timeMap::const_iterator it = m_timeMap.begin();
543548
it != m_timeMap.end(); ++it )
@@ -593,6 +598,12 @@ void AutomationPattern::loadSettings( const QDomElement & _this )
593598
m_idsToResolve << element.attribute( "id" ).toInt();
594599
}
595600
}
601+
602+
if( _this.hasAttribute( "color" ) )
603+
{
604+
useCustomClipColor( true );
605+
setColor( _this.attribute( "color" ) );
606+
}
596607

597608
int len = _this.attribute( "len" ).toInt();
598609
if( len <= 0 )

0 commit comments

Comments
 (0)