xref: /haiku/src/apps/soundrecorder/RecorderWindow.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 "TransportButton.h"
24 #include "TrackSlider.h"
25 #include "UpDownButton.h"
26 #include "VolumeSlider.h"
27 #include "VUView.h"
28 
29 class BMediaRoster;
30 class BBox;
31 class BButton;
32 class BCheckBox;
33 class BTextControl;
34 class BMenuField;
35 class SoundConsumer;
36 class SoundListView;
37 class BScrollView;
38 class BSlider;
39 class BStringView;
40 
41 class RecorderWindow : public BWindow {
42 public:
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 			LENGTH_CHANGED,
62 			SOUND_SELECTED,
63 			STOP_PLAYING,
64 			STOP_RECORDING,
65 			RECORD_PERIOD,
66 			PLAY_PERIOD,
67 			UPDATE_TRACKSLIDER,
68 			POSITION_CHANGED
69 		};
70 
71 		void AddSoundItem(const BEntry& entry, bool temp = false);
72 
73 private:
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 		BTextControl * fLengthControl;
88 		BMenuField * fInputField;
89 		SoundConsumer * fRecordNode;
90 		BSoundPlayer * fPlayer;
91 		bool fRecording;
92 		SoundListView * fSoundList;
93 		BDirectory fTempDir;
94 		int fTempCount;
95 
96 		BBox * fBottomBox;
97 		BBox * fFileInfoBox;
98 		BStringView *fFilename;
99 		BStringView *fFormat;
100 		BStringView *fCompression;
101 		BStringView *fChannels;
102 		BStringView *fSampleSize;
103 		BStringView *fSampleRate;
104 		BStringView *fDuration;
105 
106 		enum BtnState {
107 			btnPaused,
108 			btnRecording,
109 			btnPlaying
110 		};
111 		BtnState fButtonState;
112 		BEntry fRecEntry;
113 
114 		BFile fRecFile;
115 		off_t fRecLimit;
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 		void UpdatePlayFile();
160 		void ErrorAlert(const char * action, status_t err);
161 
162 static	void RecordFile(void * cookie, bigtime_t timestamp, void * data, size_t size, const media_raw_audio_format & format);
163 static	void NotifyRecordFile(void * cookie, int32 code, ...);
164 
165 static	void PlayFile(void * cookie, void * data, size_t size, const media_raw_audio_format & format);
166 static	void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notification code, ...);
167 
168 		void RefsReceived(BMessage *msg);
169 };
170 
171 #endif	/*	RECORDERWINDOW_H */
172 
173