1 /*
2  * Copyright (C) 2002 - David W. Durham
3  *
4  * This file is part of ReZound, an audio editing application.
5  *
6  * ReZound is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License,
9  * or (at your option) any later version.
10  *
11  * ReZound is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  */
20 
21 #ifndef __FXGraphParamValue_H__
22 #define __FXGraphParamValue_H__
23 
24 #include "../../config/common.h"
25 #include "fox_compat.h"
26 
27 #include <string>
28 
29 #include "../backend/CSound_defs.h"
30 #include "../backend/CGraphParamValueNode.h"
31 
32 #include "../backend/AActionParamMapper.h"
33 
34 class FXGraphParamNode;
35 class CNestedDataFile;
36 class CHorzRuler;
37 
38 /*
39  * This can be constructed to be a widget for drawing a curve as a parameter
40  * to some action to be performed on a sound.  Either setSound() should be
41  * called to display a waveform behind the curve and 'time' will be the
42  * horizontal unit displayed.  OR, setHorzParameters should be called to indicate
43  * the horizontal units and the background will be a solid color.
44  * The vertical units are specified through setVertParameters
45  */
46 
47 class FXGraphParamValue : public FXVerticalFrame
48 {
49 	FXDECLARE(FXGraphParamValue);
50 public:
51 	FXGraphParamValue(const char *name,FXComposite *p,int opts,int x=0,int y=0,int w=0,int h=0);
52 	virtual ~FXGraphParamValue();
53 
54 	FXint getDefaultWidth();
55 	FXint getDefaultHeight();
56 	void setMinSize(FXint minWidth,FXint minHeight);
57 
58 	void setSound(CSound *sound,sample_pos_t start,sample_pos_t stop);
59 	void setHorzParameters(const string horzAxisLabel,const string horzUnits,AActionParamMapper *horzValueMapper);
60 	void setVertParameters(const string vertAxisLabel,const string vertUnits,AActionParamMapper *vertValueMapper);
61 
62 	void clearNodes();
63 
64 	long onGraphPanelPaint(FXObject *sender,FXSelector sel,void *ptr);
65 	long onGraphPanelResize(FXObject *sender,FXSelector sel,void *ptr);
66 
67 	long onCreateOrStartDragNode(FXObject *sender,FXSelector sel,void *ptr);
68 	long onDragNode(FXObject *sender,FXSelector sel,void *ptr);
69 	long onStopDragNode(FXObject *sender,FXSelector sel,void *ptr);
70 	long onDestroyNode(FXObject *sender,FXSelector sel,void *ptr);
71 
72 	long onScalarSpinnerChange(FXObject *sender,FXSelector sel,void *ptr);
73 
74 	long onPatternButton(FXObject *sender,FXSelector sel,void *ptr);
75 
76 	long onHorzDeformSliderChange(FXObject *sender,FXSelector sel,void *ptr);
77 	long onVertDeformSliderChange(FXObject *sender,FXSelector sel,void *ptr);
78 
79 	long onHorzDeformSliderReset(FXObject *sender,FXSelector sel,void *ptr);
80 	long onVertDeformSliderReset(FXObject *sender,FXSelector sel,void *ptr);
81 
82 	void updateNumbers();
83 
84 	const CGraphParamValueNodeList &getNodes() const;
85 
86 	void copyFrom(const FXGraphParamValue *src);
87 	void swapWith(FXGraphParamValue *src);
88 
89 	// ??? these necessary?
90 	const int getScalar() const;
91 	void setScalar(const int scalar);
92 
93 	const int getMinScalar() const;
94 	const int getMaxScalar() const;
95 	// -------- ^^^
96 
97 	const string getName() const;
98 
99 
100 	void readFromFile(const string &prefix,CNestedDataFile *f);
101 	void writeToFile(const string &prefix,CNestedDataFile *f) const;
102 
103 	enum
104 	{
105 		ID_GRAPH_CANVAS=FXVerticalFrame::ID_LAST,
106 
107 		ID_SCALAR_SPINNER,
108 
109 		ID_CLEAR_BUTTON,
110 		ID_HORZ_FLIP_BUTTON,
111 		ID_VERT_FLIP_BUTTON,
112 		ID_SMOOTH_BUTTON,
113 
114 		ID_HORZ_DEFORM_SLIDER,
115 		ID_VERT_DEFORM_SLIDER,
116 
117 		ID_LAST
118 	};
119 
120 
121 protected:
FXGraphParamValue()122 	FXGraphParamValue() {}
123 
124 
125 private:
126 	friend class FXGraphParamNode;
127 	friend class CVertRuler;
128 	friend class CHorzRuler;
129 
130 	const string name;
131 
132 	FXPacker *graphPanel;
133 		FXVerticalFrame *vertDeformPanel;
134 			FXSlider *vertDeformSlider;
135 		CHorzRuler *horzRuler;
136 		FXComposite *vertRuler;
137 		FXHorizontalFrame *horzDeformPanel;
138 			FXSlider *horzDeformSlider;
139 		FXCanvas *graphCanvas;
140 
141 
142 	FXHorizontalFrame *statusPanel;
143 		FXLabel *horzValueLabel;
144 		FXLabel *vertValueLabel;
145 		FXLabel *pointCountLabel;
146 
147 	FXHorizontalFrame *buttonPanel;
148 		FXLabel *scalarLabel;
149 		FXSpinner *scalarSpinner;
150 
151 
152 	int draggingNode;
153 	int dragOffsetX,dragOffsetY;
154 
155 	CGraphParamValueNodeList nodes;
156 	mutable CGraphParamValueNodeList retNodes; // a copy of nodes that is returned
157 
158 	int getGraphPanelWidth() const; // always returns an even value
159 	int getGraphPanelHeight() const; // always returns an even value
160 
161 	// returns the index where it was inserted
162 	int insertIntoNodes(const CGraphParamValueNode &node);
163 
164 	int findNodeAt(int x,int y);
165 
166 	double screenToNodeHorzValue(int x,bool undeform=true);
167 	double screenToNodeVertValue(int y,bool undeform=true);
168 
169 	int nodeToScreenX(const CGraphParamValueNode &node);
170 	int nodeToScreenY(const CGraphParamValueNode &node);
171 
172 	void updateStatus();
173 	void clearStatus();
174 
175 	const string getHorzValueString(double horzValue) const; /* horzValue is [0..1] */
176 	const string getVertValueString(double vertValue) const; /* vertValue is [0..1] */
177 
178 	double deformNodeX(double x,FXint sliderValue) const;
179 	double undeformNodeX(double x,FXint sliderValue) const;
180 
181 	CSound *sound;
182 	sample_pos_t start,stop;
183 
184 	string horzAxisLabel;
185 	string horzUnits;
186 	AActionParamMapper *horzValueMapper;
187 
188 	string vertAxisLabel;
189 	string vertUnits;
190 	AActionParamMapper *vertValueMapper;
191 
192 	// we draw on this one time and blit from it anytime we need to update the canvas
193 	FXImage *backBuffer;
194 
195 	FXFont *textFont;
196 
197 	FXint minWidth,minHeight;
198 };
199 
200 #endif
201