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