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