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 __FXWaveCanvas_H__
22 #define __FXWaveCanvas_H__
23 
24 /*
25  * This is an FXCanvas widget that can draw the waveform on itself.
26  * It is given a CSound object to from which get the audio data.
27  * It is given a horzontal and vertical zoom and a horizontal and
28  * vertical offset parameters for adjusting the view.
29  *
30  * This object, of course, has all the events of an FXCanvas for
31  * detecting things such as mouse events.
32  *
33  * ??? Potientially and frequency analysis mode should be supported.
34  * 	- I should store calculated data for FFT just like I do
35  */
36 
37 #include "../../config/common.h"
38 #include "fox_compat.h"
39 
40 #include "../backend/CSound_defs.h"
41 class CLoadedSound;
42 
43 class FXWaveCanvas : public FXCanvas
44 {
45 	FXDECLARE(FXWaveCanvas)
46 public:
47 	FXWaveCanvas(CLoadedSound* loadedSound, FXComposite* p, FXObject* tgt=NULL, FXSelector sel=0, FXuint opts=FRAME_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0);
48 	virtual ~FXWaveCanvas();
49 
50 	void updateFromEdit(bool undoing=false);
51 
52 	enum LastChangedPositions { lcpNone,lcpStart,lcpStop };
53 
54 	enum HorzRecenterTypes { hrtNone,hrtAuto,hrtStart,hrtStop,hrtLeftEdge };
55 
56 	// v is 0 to 1 (0 is all the way zoomed out, 1 is all the way zoomed in)
57 	void setHorzZoom(double v,HorzRecenterTypes horzRecenterType=hrtNone);
58 	const double getHorzZoom() const;
59 
60 	// returns the width of the wave according to the zoom factor
61 	const sample_pos_t getHorzSize() const;
62 
63 	void setHorzOffset(sample_pos_t v);
64 	const sample_pos_t getHorzOffset() const;
65 
66 
67 
68 	// v is 0 to 1 (0 is all the way zoomed out, 1 is all the way zoomed in)
69 	void setVertZoom(float v);
70 	const float getVertZoom() const;
71 
72 	// returns the width of the wave according to the zoom factor
73 	const int getVertSize() const;
74 
75 	void setVertOffset(int v);
76 	const int getVertOffset() const;
77 
78 
79 	const sample_pos_t getHorzOffsetToCenterTime(sample_pos_t time) const;
80 	const sample_pos_t getHorzOffsetToCenterStartPos() const;
81 	const sample_pos_t getHorzOffsetToCenterStopPos() const;
82 	void showAmount(double seconds,sample_pos_t pos,int marginPixels=0);
83 
84 	const bool isStartPosOnScreen() const;
85 	const bool isStopPosOnScreen() const;
86 
87 	const sample_fpos_t getRenderedDrawSelectStart() const;
88 	const sample_fpos_t getRenderedDrawSelectStop() const;
89 	const sample_fpos_t getDrawSelectStart() const;
90 	const sample_fpos_t getDrawSelectStop() const;
91 
92 	const sample_pos_t snapPositionToCue(sample_pos_t p) const;
93 	const FXint getCueScreenX(size_t cueIndex) const;
94 
95 	const sample_pos_t getSamplePosForScreenX(FXint X) const;
96 	void setSelectStartFromScreen(FXint X);
97 	void setSelectStopFromScreen(FXint X);
98 	void updateFromSelectionChange(LastChangedPositions lastChangedPosition=lcpNone);
99 
100 	void drawPlayPosition(sample_pos_t dataPosition,bool justErasing,bool scrollToMakeVisible,FXScrollArea *optScrollArea);
101 
102 
103 	long onPaint(FXObject *object,FXSelector sel,void *ptr);
104 	bool first;
105 
106 protected:
FXWaveCanvas()107 	FXWaveCanvas() {}
108 
109 private:
110 	void drawPortion(int left,int width,FXDCWindow *dc);
111 
112 	CLoadedSound *loadedSound;
113 
114 	sample_fpos_t horzZoomFactor;
115 	float vertZoomFactor;
116 
117 	sample_pos_t horzOffset;
118 	sample_fpos_t prevHorzZoomFactor_horzOffset;
119 
120 	int vertOffset;
121 
122 	FXint prevDrawPlayStatusX;
123 	sample_pos_t renderedStartPosition,renderedStopPosition;
124 
125 	double lastHorzZoom;
126 	float lastVertZoom;
127 
128 	LastChangedPositions lastChangedPosition;
129 	bool lastDrawWasUnsuccessful;
130 };
131 
132 #endif
133