RecorderWindow.h revision 5fa77532306a97ec33484c1436e1e0d7c0be76af
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 "ScopeView.h"
22#include "TransportButton.h"
23#include "TrackSlider.h"
24#include "UpDownButton.h"
25#include "VolumeSlider.h"
26#include "VUView.h"
27
28class BMediaRoster;
29class BBox;
30class BButton;
31class BCheckBox;
32class BTextControl;
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			INPUT_SELECTED = 'cW00',	//	control messages
59			LENGTH_CHANGED,
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		VolumeSlider *fVolumeSlider;
82		TrackSlider *fTrackSlider;
83		UpDownButton * fUpDownButton;
84		BTextControl * fLengthControl;
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		BFile fRecFile;
112		off_t fRecLimit;
113		off_t fRecSize;
114
115		media_node fAudioInputNode;
116		media_output fAudioOutput;
117		media_input fRecInput;
118
119		BMediaFile *fPlayFile;
120		media_format fPlayFormat;
121		BMediaTrack *fPlayTrack;
122		int64 fPlayLimit;
123		int64 fPlayFrame;
124
125		media_node fAudioMixerNode;
126
127		BFilePanel *fSavePanel;
128		status_t fInitCheck;
129
130		status_t InitWindow();
131
132		void Record(BMessage * message);
133		void Play(BMessage * message);
134		void Stop(BMessage * message);
135		void Save(BMessage * message);
136		void DoSave(BMessage * message);
137		void Input(BMessage * message);
138		void Length(BMessage * message);
139		void Selected(BMessage * message);
140
141		status_t MakeRecordConnection(const media_node & input);
142		status_t BreakRecordConnection();
143		status_t StopRecording();
144
145		status_t MakePlayConnection(const media_multi_audio_format & format);
146		status_t BreakPlayConnection();
147		status_t StopPlaying();
148
149		status_t NewTempName(char * buffer);
150		void CalcSizes(float min_width, float min_height);
151		void SetButtonState(BtnState state);
152		void UpdateButtons();
153		void UpdatePlayFile();
154		void ErrorAlert(const char * action, status_t err);
155
156static	void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_raw_audio_format & format);
157static	void NotifyRecordFile(void * cookie, int32 code, ...);
158
159static	void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
160static	void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
161
162		void RefsReceived(BMessage *msg);
163};
164
165#endif	/*	RECORDERWINDOW_H */
166
167