1/*
2 * Copyright (C) 1998-1999 Be Incorporated. All rights reseved.
3 * Distributed under the terms of the Be Sample Code license.
4 *
5 * Copyright (C) 2001-2008 Stephan A��mus. All rights reserved.
6 * Distributed under the terms of the MIT license.
7 */
8
9/*----------------------------------------------------------
10PURPOSE:
11gui class for displaying stereo audio peak level info
12
13FEATURES:
14- uses a bitmap, but not a view accepting one, to redraw
15without flickering.
16- can be configured to use it's own message runner instead
17of the windows current pulse (in case you have text views in
18the window as well, which use a slow pulse for cursor blinking)
19- if used with own message runner, refresh delay is configurable
20- can be used in a dynamic liblayout gui
21
22USAGE:
23To display the peak level of your streaming audio, just
24calculate the local maximum of both channels within your
25audio buffer and call SetMax() once for every buffer. The
26PeakView will take care of the rest.
27min = 0.0
28max = 1.0
29----------------------------------------------------------*/
30#ifndef PEAK_VIEW_H
31#define PEAK_VIEW_H
32
33
34#include <View.h>
35
36class BBitmap;
37class BMessageRunner;
38
39class PeakView : public BView {
40public:
41								PeakView(const char* name,
42									bool useGlobalPulse = true,
43									bool displayLabels = true);
44	virtual						~PeakView();
45
46	// BView interface
47	virtual	void				MessageReceived(BMessage* message);
48	virtual	void				AttachedToWindow();
49	virtual	void				DetachedFromWindow();
50	virtual	void				MouseDown(BPoint where);
51	virtual	void				Draw(BRect area);
52	virtual	void				FrameResized(float width, float height);
53	virtual	void				Pulse();
54	virtual	BSize				MinSize();
55
56	// PeakView
57			bool				IsValid() const;
58			void				SetPeakRefreshDelay(bigtime_t delay);
59			void				SetPeakNotificationWhat(uint32 what);
60
61			void				SetChannelCount(uint32 count);
62			void				SetMax(float max, uint32 channel);
63
64private:
65			BRect				_BackBitmapFrame() const;
66			void				_ResizeBackBitmap(int32 width, int32 channels);
67			void				_UpdateBackBitmap();
68			void				_RenderSpan(uint8* span, uint32 width,
69									float current, float peak, bool overshot);
70			void				_DrawBitmap();
71
72private:
73			bool				fUseGlobalPulse;
74			bool				fDisplayLabels;
75			bool				fPeakLocked;
76
77			bigtime_t			fRefreshDelay;
78			BMessageRunner*		fPulse;
79
80			struct ChannelInfo {
81				float			current_max;
82				float			last_max;
83				bigtime_t		last_overshot_time;
84			};
85
86			ChannelInfo*		fChannelInfos;
87			uint32				fChannelCount;
88			bool				fGotData;
89
90			BBitmap*			fBackBitmap;
91			font_height			fFontHeight;
92
93			uint32				fPeakNotificationWhat;
94};
95
96#endif // PEAK_VIEW_H
97