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