RecorderWindow.h revision 683cf2ff58b85b9224cd8a7e08310c2b1041b952
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		SoundListView * fSoundList;
100		BDirectory fTempDir;
101		int fTempCount;
102
103		float fDeployedHeight;
104
105		BBox * fBottomBox;
106		BBox * fFileInfoBox;
107		BStringView *fFilename;
108		BStringView *fFormat;
109		BStringView *fCompression;
110		BStringView *fChannels;
111		BStringView *fSampleSize;
112		BStringView *fSampleRate;
113		BStringView *fDuration;
114
115		enum BtnState {
116			btnPaused,
117			btnRecording,
118			btnPlaying
119		};
120		BtnState fButtonState;
121		BEntry fRecEntry;
122
123		media_format fRecordFormat;
124
125		BFile fRecFile;
126		off_t fRecSize;
127
128		media_node fAudioInputNode;
129
130		BMediaFile *fPlayFile;
131		media_format fPlayFormat;
132		BMediaTrack *fPlayTrack;
133		int64 fPlayLimit;
134		int64 fPlayFrame;
135		int64 fPlayFrames;
136
137		bool fLooping;
138
139		media_node fAudioMixerNode;
140
141		BFilePanel *fSavePanel;
142		status_t fInitCheck;
143
144		status_t InitWindow();
145
146		void Record(BMessage * message);
147		void Play(BMessage * message);
148		void Stop(BMessage * message);
149		void Save(BMessage * message);
150		void DoSave(BMessage * message);
151		void Input(BMessage * message);
152		void Length(BMessage * message);
153		void Selected(BMessage * message);
154
155		status_t MakeRecordConnection(const media_node & input);
156		status_t BreakRecordConnection();
157		status_t StopRecording();
158
159		status_t MakePlayConnection(const media_multi_audio_format & format);
160		status_t BreakPlayConnection();
161		status_t StopPlaying();
162
163		status_t NewTempName(char * buffer);
164		void CalcSizes(float min_width, float min_height);
165		void SetButtonState(BtnState state);
166		void UpdateButtons();
167		status_t UpdatePlayFile(SoundListItem *item, bool updateDisplay = false);
168		void ErrorAlert(const char * action, status_t err);
169
170static	void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_format & format);
171static	void NotifyRecordFile(void * cookie, BMediaRecorder::notification code, ...);
172
173static	void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
174static	void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
175
176		void RefsReceived(BMessage *msg);
177		void CopyTarget(BMessage *msg);
178};
179
180#endif	/*	RECORDERWINDOW_H */
181