Debian Codegraph @

src/tracks/playabletrack/wavetrack/ui/WaveformAppearance.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file WaveformApperance.h
7
8 Paul Licameli
9
10 **********************************************************************/
11 #ifndef __AUDACITY_WAVEFORM_APPEARANCE__
12 #define __AUDACITY_WAVEFORM_APPEARANCE__
13
14 #include "WaveClip.h"
15 #include "WaveTrack.h"
16
17 //! Persistent appearance settings that apply to all channels of a track
18 class WaveformAppearance : public TrackAttachment
19 {
20 public:
21 static WaveformAppearance &Get(WaveTrack &track);
22 static const WaveformAppearance &Get(const WaveTrack &track);
23
24 static WaveformAppearance &Get(WaveChannel &channel);
25 static const WaveformAppearance &Get(const WaveChannel &channel);
26
27 explicit WaveformAppearance(WaveTrack &track);
28 ~WaveformAppearance() override;
29
30 void CopyTo(Track &track) const override;
31 void Reparent(const std::shared_ptr<Track> &parent) override;
32 void WriteXMLAttributes(XMLWriter &writer) const override;
33 bool HandleXMLAttribute(
34 const std::string_view& attr, const XMLAttributeValueView& valueView)
35 override;
36
37 int GetColorIndex() const { return mColorIndex; }
38 void SetColorIndex(int colorIndex);
39
40 private:
41 void Subscribe(const std::shared_ptr<WaveTrack> &pTrack);
42
43 std::weak_ptr<WaveTrack> mwTrack;
44 Observer::Subscription mSubscription;
45 int mColorIndex{ 0 };
46 };
47
48 struct WaveColorAttachment final : WaveClipListener
49 {
50 explicit WaveColorAttachment();
51 ~WaveColorAttachment() override;
52
53 std::unique_ptr<WaveClipListener> Clone() const override;
54
55 static WaveColorAttachment &Get(WaveClip &clip);
56 static const WaveColorAttachment &Get(const WaveClip &clip);
57 static WaveColorAttachment &Get(WaveChannelInterval &clip);
58 static const WaveColorAttachment &Get(const WaveChannelInterval &clip);
59
60 void MarkChanged() noexcept override; // NOFAIL-GUARANTEE
61 void Invalidate() override; // NOFAIL-GUARANTEE
62
63 // Write color
64 void WriteXMLAttributes(XMLWriter &writer) const override;
65
66 // Read color
67 bool HandleXMLAttribute(const std::string_view &attr,
68 const XMLAttributeValueView &valueView) override;
69
70 int GetColorIndex() const { return mColorIndex; }
71 void SetColorIndex(int colorIndex) { mColorIndex = colorIndex; }
72
73 private:
74 int mColorIndex{};
75 };
76
77 #endif