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