RecorderWindow.h revision 07db0c6fd02087bab5ec962ba5a6bd32c9004862
1/*
2 * Copyright 2005, J��r��me Duval. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
6 */
7
8#ifndef RECORDERWINDOW_H
9#define RECORDERWINDOW_H
10
11#include <Directory.h>
12#include <Entry.h>
13#include <File.h>
14#include <FilePanel.h>
15#include <MediaFile.h>
16#include <MediaNode.h>
17#include <MediaTrack.h>
18#include <SoundPlayer.h>
19#include <Window.h>
20
21#include "DrawButton.h"
22#include "ScopeView.h"
23#include "TransportButton.h"
24#include "TrackSlider.h"
25#include "UpDownButton.h"
26#include "VolumeSlider.h"
27#include "VUView.h"
28
29class BMediaRoster;
30class BBox;
31class BButton;
32class BCheckBox;
33class BMenuField;
34class SoundConsumer;
35class SoundListView;
36class BScrollView;
37class BSlider;
38class BStringView;
39
40class RecorderWindow : public BWindow {
41public:
42		RecorderWindow();
43	virtual	~RecorderWindow();
44		status_t InitCheck();
45
46
47	virtual	bool QuitRequested();
48	virtual	void MessageReceived(BMessage * message);
49
50		enum {
51			RECORD = 'cw00',			//	command messages
52			PLAY,
53			STOP,
54			REWIND,
55			FORWARD,
56			SAVE,
57			VIEW_LIST,
58			LOOP,
59			INPUT_SELECTED = 'cW00',	//	control messages
60			SOUND_SELECTED,
61			STOP_PLAYING,
62			STOP_RECORDING,
63			RECORD_PERIOD,
64			PLAY_PERIOD,
65			UPDATE_TRACKSLIDER,
66			POSITION_CHANGED
67		};
68
69		void AddSoundItem(const BEntry& entry, bool temp = false);
70
71private:
72		BMediaRoster * fRoster;
73		VUView *fVUView;
74		ScopeView *fScopeView;
75		RecordButton * fRecordButton;
76		PlayPauseButton * fPlayButton;
77		TransportButton * fStopButton;
78		TransportButton * fRewindButton;
79		TransportButton * fForwardButton;
80		TransportButton * fSaveButton;
81		DrawButton * fLoopButton;
82		VolumeSlider *fVolumeSlider;
83		TrackSlider *fTrackSlider;
84		UpDownButton * fUpDownButton;
85		BMenuField * fInputField;
86		SoundConsumer * fRecordNode;
87		BSoundPlayer * fPlayer;
88		bool fRecording;
89		SoundListView * fSoundList;
90		BDirectory fTempDir;
91		int fTempCount;
92
93		BBox * fBottomBox;
94		BBox * fFileInfoBox;
95		BStringView *fFilename;
96		BStringView *fFormat;
97		BStringView *fCompression;
98		BStringView *fChannels;
99		BStringView *fSampleSize;
100		BStringView *fSampleRate;
101		BStringView *fDuration;
102
103		enum BtnState {
104			btnPaused,
105			btnRecording,
106			btnPlaying
107		};
108		BtnState fButtonState;
109		BEntry fRecEntry;
110
111		media_format fRecordFormat;
112
113		BFile fRecFile;
114		off_t fRecSize;
115
116		media_node fAudioInputNode;
117		media_output fAudioOutput;
118		media_input fRecInput;
119
120		BMediaFile *fPlayFile;
121		media_format fPlayFormat;
122		BMediaTrack *fPlayTrack;
123		int64 fPlayLimit;
124		int64 fPlayFrame;
125		int64 fPlayFrames;
126
127		bool fLooping;
128
129		media_node fAudioMixerNode;
130
131		BFilePanel *fSavePanel;
132		status_t fInitCheck;
133
134		status_t InitWindow();
135
136		void Record(BMessage * message);
137		void Play(BMessage * message);
138		void Stop(BMessage * message);
139		void Save(BMessage * message);
140		void DoSave(BMessage * message);
141		void Input(BMessage * message);
142		void Length(BMessage * message);
143		void Selected(BMessage * message);
144
145		status_t MakeRecordConnection(const media_node & input);
146		status_t BreakRecordConnection();
147		status_t StopRecording();
148
149		status_t MakePlayConnection(const media_multi_audio_format & format);
150		status_t BreakPlayConnection();
151		status_t StopPlaying();
152
153		status_t NewTempName(char * buffer);
154		void CalcSizes(float min_width, float min_height);
155		void SetButtonState(BtnState state);
156		void UpdateButtons();
157		void UpdatePlayFile();
158		void ErrorAlert(const char * action, status_t err);
159
160static	void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_raw_audio_format & format);
161static	void NotifyRecordFile(void * cookie, int32 code, ...);
162
163static	void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
164static	void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
165
166		void RefsReceived(BMessage *msg);
167};
168
169#endif	/*	RECORDERWINDOW_H */
170
171