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