1 /*
2  *  tracker/ScopesControl.h
3  *
4  *  Copyright 2009 Peter Barth
5  *
6  *  This file is part of Milkytracker.
7  *
8  *  Milkytracker is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  Milkytracker is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with Milkytracker.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 /*
24  *  ScopesControl.h
25  *  MilkyTracker
26  *
27  *  Created by Peter Barth on 28.10.05.
28  *
29  */
30 
31 #ifndef SCOPESCONTROL__H
32 #define SCOPESCONTROL__H
33 
34 #include "BasicTypes.h"
35 #include "Control.h"
36 #include "Event.h"
37 #include "TrackerConfig.h"
38 
39 // Forwards
40 class PPButton;
41 class PPGraphicsAbstract;
42 class PPFont;
43 class PPControl;
44 class PlayerController;
45 
46 class ScopesControl : public PPControl
47 {
48 public:
49 	enum ClickTypes
50 	{
51 		ClickTypeMute,
52 		ClickTypeSolo,
53 		ClickTypeRec,
54 		ClickTypeSingleRec
55 	};
56 
57 	enum AppearanceTypes
58 	{
59 		AppearanceTypeNormal,
60 		AppearanceTypeSolid,
61 		AppearanceTypeLines
62 	};
63 
64 private:
65 	PPColor color;
66 
67 	bool border;
68 	PPColor ourOwnBorderColor;
69 	const PPColor* borderColor;
70 
71 	PPButton* backgroundButton;
72 
73 	// extent
74 	pp_int32 visibleWidth;
75 	pp_int32 visibleHeight;
76 
77 	PlayerController* playerController;
78 
79 	pp_int32 numChannels;
80 	pp_int32 channelWidthTable[TrackerConfig::MAXCHANNELS];
81 	bool onOffState[TrackerConfig::MAXCHANNELS];
82 	bool zeroVolumeState[TrackerConfig::MAXCHANNELS];
83 	pp_uint8 muteChannels[TrackerConfig::MAXCHANNELS];
84 	pp_uint8 lastMuteChannels[TrackerConfig::MAXCHANNELS];
85 	pp_uint8 recChannels[TrackerConfig::MAXCHANNELS];
86 	pp_uint8 lastRecChannels[TrackerConfig::MAXCHANNELS];
87 	pp_int32 lastNumChannels;
88     PPRect channelRects[TrackerConfig::MAXCHANNELS];
89 	PPFont* font;
90 	PPFont* smallFont;
91 
92 	pp_int32 lMouseDownInChannel, rMouseDownInChannel;
93 	bool didSoloChannel;
94 
95 	bool enabled;
96 
97 	AppearanceTypes appearance;
98 
99 	ClickTypes currentClickType;
100 
101 public:
102 	enum ChangeValueTypes
103 	{
104 		ChangeValueMuting,
105 		ChangeValueRecording
106 	};
107 
108 	ScopesControl(pp_int32 id,
109 				  PPScreen* parentScreen,
110 				  EventListenerInterface* eventListener,
111 				  const PPPoint& location, const PPSize& size,
112 				  bool border = true);
113 
114 	virtual ~ScopesControl();
115 
setColor(pp_int32 r,pp_int32 g,pp_int32 b)116 	void setColor(pp_int32 r,pp_int32 g,pp_int32 b) { color.r = r; color.g = g; color.b = b; }
setColor(PPColor color)117 	void setColor(PPColor color) { this->color = color; }
118 
setBorderColor(const PPColor & color)119 	void setBorderColor(const PPColor& color) { this->borderColor = &color; }
120 
121 	// from PPControl
122 	virtual void paint(PPGraphicsAbstract* graphics);
123 
124 	virtual pp_int32 dispatchEvent(PPEvent* event);
125 
126 	void attachSource(PlayerController* playerController);
127 
setNumChannels(pp_int32 numChannels)128 	void setNumChannels(pp_int32 numChannels) { this->numChannels = numChannels; }
129 
130 	bool needsUpdate();
enable(bool b)131 	void enable(bool b) { enabled = b; }
132 
muteChannel(pp_int32 index,bool b)133 	void muteChannel(pp_int32 index, bool b) { muteChannels[index] = (b ? 1 : 0); }
recordChannel(pp_int32 index,bool b)134 	void recordChannel(pp_int32 index, bool b) { recChannels[index] = (b ? 1 : 0); }
135 
136 	bool isSoloChannel(pp_int32 c) const;
137 	bool isSingleRecChannel(pp_int32 c) const;
138 
139 	void handleMute(pp_int32 channel);
140 	void handleSolo(pp_int32 channel);
141 	void handleRec(pp_int32 channel);
142 	void handleSingleRec(pp_int32 channel);
143 
144 	void handleUnmuteAll();
145 
setCurrentClickType(ClickTypes type)146 	void setCurrentClickType(ClickTypes type) { currentClickType = type; }
getCurrentClickType()147 	ClickTypes getCurrentClickType() const { return currentClickType; }
148 
setAppearance(AppearanceTypes appearance)149 	void setAppearance(AppearanceTypes appearance) { this->appearance = appearance; }
getAppearance()150 	AppearanceTypes getAppearance() const { return appearance; }
151 
152 private:
153 	pp_int32 pointToChannel(const PPPoint& pt);
154 
155 	pp_int32 WRAPCHANNELS() const;
156 
isWrapped()157     bool isWrapped() const { return ((numChannels - 2) / WRAPCHANNELS()) > 0; }
158 };
159 
160 
161 #endif
162