1/* 2Author: Jerome LEVEQUE 3Email: jerl1@caramail.com 4*/ 5#include "MidiPlayerView.h" 6#include "Scope.h" 7#include "Activity.h" 8 9#include <StringView.h> 10#include <PopUpMenu.h> 11#include <MenuItem.h> 12#include <MenuField.h> 13#include <Button.h> 14#include <Window.h> 15#include <Synth.h> 16#include <Directory.h> 17#include <Slider.h> 18 19//---------------------------------------------------------- 20//---------------------------------------------------------- 21//---------------------------------------------------------- 22//---------------------------------------------------------- 23//---------------------------------------------------------- 24//---------------------------------------------------------- 25//---------------------------------------------------------- 26//---------------------------------------------------------- 27 28MidiPlayerView::MidiPlayerView(void) 29 : BView(BRect(0, 0, 660, 360), "StandartView", 30 B_FOLLOW_ALL, B_WILL_DRAW) 31{ 32 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 33 fInputStringView = new BStringView(BRect(10, 20, 200, 40), NULL, "None"); 34 fOutputStringView = new BStringView(BRect(10, 20, 200, 40), NULL, "None"); 35} 36 37//---------------------------------------------------------- 38 39MidiPlayerView::~MidiPlayerView(void) 40{ 41 delete fInputStringView; 42 delete fOutputStringView; 43} 44 45//---------------------------------------------------------- 46 47void MidiPlayerView::AttachedToWindow(void) 48{ 49BPopUpMenu *Menu = NULL; 50BMenuField *Field = NULL; 51BMessage *msg = NULL; 52 53 AddChild(fInputBox = new BBox(BRect(10, 0, 290, 170), "InputBox")); 54 Menu = new BPopUpMenu("Select Input"); 55 msg = new BMessage(INPUT_CHANGE_TO_FILE); 56 Menu->AddItem(new BMenuItem("From File", msg)); 57 msg = new BMessage(INPUT_CHANGE_TO_MIDIPORT); 58 Menu->AddItem(new BMenuItem("From MidiPort", msg)); 59 Field = new BMenuField(BRect(0, 0, 150, 20), NULL, NULL, Menu); 60 fInputBox->SetLabel((BView*)Field); 61 62 AddChild(fOutputBox = new BBox(BRect(10, 180, 290, 350), "OutputBox")); 63 Menu = new BPopUpMenu("Select Output"); 64 msg = new BMessage(OUTPUT_CHANGE_TO_FILE); 65 Menu->AddItem(new BMenuItem("To File", msg)); 66 msg = new BMessage(OUTPUT_CHANGE_TO_BEOS_SYNTH); 67 Menu->AddItem(new BMenuItem("To BeOS Synth", msg)); 68 msg = new BMessage(OUTPUT_CHANGE_TO_BEOS_SYNTH_FILE); 69 Menu->AddItem(new BMenuItem("To Midi Synth File", msg)); 70 msg = new BMessage(OUTPUT_CHANGE_TO_MIDIPORT); 71 Menu->AddItem(new BMenuItem("To MidiPort", msg)); 72 Field = new BMenuField(BRect(0, 0, 150, 20), NULL, NULL, Menu); 73 fOutputBox->SetLabel((BView*)Field); 74 75 AddChild(fViewBox = new BBox(BRect(300, 0, 650, 350), "OutputBox")); //Width = 350, High = 350 76 Menu = new BPopUpMenu("Select View"); 77 msg = new BMessage(VIEW_CHANGE_TO_NONE); 78 Menu->AddItem(new BMenuItem("None", msg)); 79 msg = new BMessage(VIEW_CHANGE_TO_SCOPE); 80 Menu->AddItem(new BMenuItem("Scope", msg)); 81 msg = new BMessage(VIEW_CHANGE_TO_ACTIVITY); 82 Menu->AddItem(new BMenuItem("Midi activity", msg)); 83 Field = new BMenuField(BRect(0, 0, 150, 20), NULL, NULL, Menu); 84 fViewBox->SetLabel((BView*)Field); 85 86} 87 88//---------------------------------------------------------- 89 90void MidiPlayerView::MessageReceived(BMessage *msg) 91{ 92BPopUpMenu *popupmenu = NULL; 93BMenuField *Field = NULL; 94Activity *view = NULL; 95 switch (msg->what) 96 { 97//-------------- 98//-------------- 99//For The Input 100//-------------- 101 case INPUT_CHANGE_TO_FILE : 102 RemoveAll(fInputBox); 103 fInputBox->AddChild(fInputStringView); 104 fInputBox->AddChild(new BButton(BRect(220, 20, 270, 40), NULL, "Select", new BMessage(CHANGE_INPUT_FILE))); 105 fInputBox->AddChild(new BButton(BRect(50, 140, 100, 160), NULL, "Rewind", new BMessage(REWIND_INPUT_FILE))); 106 fInputBox->AddChild(new BButton(BRect(110, 140, 160, 160), NULL, "Play", new BMessage(PLAY_INPUT_FILE))); 107 fInputBox->AddChild(new BButton(BRect(170, 140, 220, 160), NULL, "Pause", new BMessage(PAUSE_INPUT_FILE))); 108 break; 109//-------------- 110 case INPUT_CHANGE_TO_MIDIPORT : 111 RemoveAll(fInputBox); 112 msg->FindPointer("Menu", (void**)&popupmenu); 113 fInputBox->AddChild(Field = new BMenuField(BRect(10, 25, 280, 45), NULL, "Selected", popupmenu)); 114 Field->SetDivider(60); 115 break; 116//-------------- 117//-------------- 118//For the Output 119//-------------- 120 case OUTPUT_CHANGE_TO_FILE : 121 RemoveAll(fOutputBox); 122 fOutputBox->AddChild(fOutputStringView); 123 fOutputBox->AddChild(new BButton(BRect(220, 20, 270, 40), NULL, "Select", new BMessage(CHANGE_OUTPUT_FILE))); 124 fOutputBox->AddChild(new BButton(BRect(50, 140, 100, 160), NULL, "Rewind", new BMessage(REWIND_OUTPUT_FILE))); 125 fOutputBox->AddChild(new BButton(BRect(170, 140, 220, 160), NULL, "Save", new BMessage(SAVE_OUTPUT_FILE))); 126 break; 127//-------------- 128 case OUTPUT_CHANGE_TO_BEOS_SYNTH : 129 RemoveAll(fOutputBox); 130 SetBeOSSynthView(fOutputBox); 131 break; 132//-------------- 133 case OUTPUT_CHANGE_TO_BEOS_SYNTH_FILE : 134 RemoveAll(fOutputBox); 135 fOutputBox->AddChild(fOutputStringView); 136 fOutputBox->AddChild(new BButton(BRect(220, 20, 270, 40), NULL, "Select", new BMessage(CHANGE_BEOS_SYNTH_FILE))); 137 fOutputBox->AddChild(new BButton(BRect(50, 140, 100, 160), NULL, "Rewind", new BMessage(REWIND_BEOS_SYNTH_FILE))); 138 fOutputBox->AddChild(new BButton(BRect(110, 140, 160, 160), NULL, "Play", new BMessage(PLAY_BEOS_SYNTH_FILE))); 139 fOutputBox->AddChild(new BButton(BRect(170, 140, 220, 160), NULL, "Pause", new BMessage(PAUSE_BEOS_SYNTH_FILE))); 140 SetBeOSSynthView(fOutputBox); 141 break; 142//-------------- 143 case OUTPUT_CHANGE_TO_MIDIPORT : 144 RemoveAll(fOutputBox); 145 msg->FindPointer("Menu", (void**)&popupmenu); 146 fOutputBox->AddChild(Field = new BMenuField(BRect(10, 25, 280, 45), NULL, "Selected", popupmenu)); 147 Field->SetDivider(60); 148 break; 149//-------------- 150//-------------- 151//For the display view 152//-------------- 153 case VIEW_CHANGE_TO_NONE : 154 RemoveAll(fViewBox); 155 break; 156//-------------- 157 case VIEW_CHANGE_TO_SCOPE : 158 RemoveAll(fViewBox); 159 fViewBox->AddChild(new Scope(BRect(10, 25, 340, 340))); 160 break; 161//-------------- 162 case VIEW_CHANGE_TO_ACTIVITY : 163 RemoveAll(fViewBox); 164 msg->FindPointer("View", (void**)&view); 165 fViewBox->AddChild(view); 166 break; 167//-------------- 168//-------------- 169//-------------- 170//-------------- 171//-------------- 172//-------------- 173//-------------- 174//-------------- 175//-------------- 176//-------------- 177//-------------- 178//-------------- 179//-------------- 180//-------------- 181//-------------- 182//-------------- 183//-------------- 184//-------------- 185//-------------- 186//-------------- 187 default: BView::MessageReceived(msg); 188 } 189} 190 191//---------------------------------------------------------- 192 193BStringView *MidiPlayerView::GetInputStringView(void) 194{ 195 return fInputStringView; 196} 197 198//---------------------------------------------------------- 199 200BStringView *MidiPlayerView::GetOutputStringView(void) 201{ 202 return fOutputStringView; 203} 204 205//---------------------------------------------------------- 206 207void MidiPlayerView::RemoveAll(BView *aView) 208{//Remove and delete all view from aView exept the first one an TheStringView (delete) 209BView *Temp = NULL; 210 aView->Window()->Lock(); 211 Temp = aView->ChildAt(1); 212 while (Temp != NULL) 213 { 214 aView->RemoveChild(Temp); 215 if ((Temp != fInputStringView) && (Temp != fOutputStringView)) 216 delete Temp; 217 Temp = aView->ChildAt(1); 218 } 219 aView->Window()->Unlock(); 220} 221 222//---------------------------------------------------------- 223 224void MidiPlayerView::SetBeOSSynthView(BView *aView) 225{ 226BPopUpMenu *Menu = NULL; 227BMenuField *field = NULL; 228BMessage *msg = NULL; 229BMenuItem *item = NULL; 230int32 temp = 0; 231 232 Menu = new BPopUpMenu("Sample Rate"); 233 temp = be_synth->SamplingRate(); 234 msg = new BMessage(CHANGE_SAMPLE_RATE_SYNTH); 235 Menu->AddItem(item = new BMenuItem("11025 Hz", msg)); 236 if (temp == 11025) item->SetMarked(true); 237 msg = new BMessage(CHANGE_SAMPLE_RATE_SYNTH); 238 Menu->AddItem(item = new BMenuItem("22050 Hz", msg)); 239 if (temp == 22050) item->SetMarked(true); 240 msg = new BMessage(CHANGE_SAMPLE_RATE_SYNTH); 241 Menu->AddItem(item = new BMenuItem("44100 Hz", msg)); 242 if (temp == 44100) item->SetMarked(true); 243 field = new BMenuField(BRect(5, 50, 145, 70), NULL, "Sampling Rate", Menu); 244 aView->AddChild(field); 245 246 Menu = new BPopUpMenu("Interpolation"); 247 temp = be_synth->Interpolation(); 248 msg = new BMessage(CHANGE_INTERPOLATION_TYPE_SYNTH); 249 Menu->AddItem(item = new BMenuItem("Drop", msg)); 250 if (temp == B_DROP_SAMPLE) item->SetMarked(true); 251 msg = new BMessage(CHANGE_INTERPOLATION_TYPE_SYNTH); 252 Menu->AddItem(item = new BMenuItem("2 points", msg)); 253 if (temp == B_2_POINT_INTERPOLATION) item->SetMarked(true); 254 msg = new BMessage(CHANGE_INTERPOLATION_TYPE_SYNTH); 255 Menu->AddItem(item = new BMenuItem("Linear", msg)); 256 if (temp == B_LINEAR_INTERPOLATION) item->SetMarked(true); 257 field = new BMenuField(BRect(145, 50, 285, 70), NULL, "Interpolation", Menu); 258 aView->AddChild(field); 259 260 Menu = new BPopUpMenu("Reverb"); 261 temp = be_synth->Reverb(); 262 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 263 Menu->AddItem(item = new BMenuItem("None", msg)); 264 if (!be_synth->IsReverbEnabled()) 265 { 266 item->SetMarked(true); 267 temp = -1; 268 } 269 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 270 Menu->AddItem(item = new BMenuItem("Closet", msg)); 271 if (temp == B_REVERB_CLOSET) item->SetMarked(true); 272 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 273 Menu->AddItem(item = new BMenuItem("Garage", msg)); 274 if (temp == B_REVERB_GARAGE) item->SetMarked(true); 275 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 276 Menu->AddItem(item = new BMenuItem("Ballroom", msg)); 277 if (temp == B_REVERB_BALLROOM) item->SetMarked(true); 278 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 279 Menu->AddItem(item = new BMenuItem("Cavern", msg)); 280 if (temp == B_REVERB_CAVERN) item->SetMarked(true); 281 msg = new BMessage(CHANGE_REVERB_TYPE_SYNTH); 282 Menu->AddItem(item = new BMenuItem("Dungeon", msg)); 283 if (temp == B_REVERB_DUNGEON) item->SetMarked(true); 284 field = new BMenuField(BRect(5, 75, 145, 95), NULL, "Reverb", Menu); 285 aView->AddChild(field); 286 287BDirectory dir = BDirectory(BEOS_SYNTH_DIRECTORY); 288entry_ref refs; 289 Menu = new BPopUpMenu("Standart File"); 290 while (dir.GetNextRef(&refs) != B_ENTRY_NOT_FOUND) 291 { 292 msg = new BMessage(CHANGE_FILE_SAMPLE_SYNTH); 293 Menu->AddItem(item = new BMenuItem(refs.name, msg)); 294 } 295 field = new BMenuField(BRect(145, 75, 285, 95), NULL, "File", Menu); 296 field->SetDivider(25); 297 aView->AddChild(field); 298 299BSlider *slider = new BSlider(BRect(5, 100, 275, 130), NULL, "Volume", 300 new BMessage(CHANGE_VOLUME_SYNTH), 301 0, 1500, B_TRIANGLE_THUMB); 302 temp = (int32)(be_synth->SynthVolume() * be_synth->SampleVolume() * 1000); 303 slider->SetValue(temp); 304 slider->SetLimitLabels("Min", "Max"); 305 aView->AddChild(slider); 306} 307 308//---------------------------------------------------------- 309//---------------------------------------------------------- 310//---------------------------------------------------------- 311//---------------------------------------------------------- 312//---------------------------------------------------------- 313//---------------------------------------------------------- 314//---------------------------------------------------------- 315//---------------------------------------------------------- 316//---------------------------------------------------------- 317//---------------------------------------------------------- 318//---------------------------------------------------------- 319//---------------------------------------------------------- 320//---------------------------------------------------------- 321//---------------------------------------------------------- 322//---------------------------------------------------------- 323//---------------------------------------------------------- 324//---------------------------------------------------------- 325//---------------------------------------------------------- 326//---------------------------------------------------------- 327