1a10cf76eSAxel Dörfler // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 2a10cf76eSAxel Dörfler // 3a10cf76eSAxel Dörfler // Copyright (c) 2003, OpenBeOS 4a10cf76eSAxel Dörfler // 5a10cf76eSAxel Dörfler // This software is part of the OpenBeOS distribution and is covered 6a10cf76eSAxel Dörfler // by the OpenBeOS license. 7a10cf76eSAxel Dörfler // 8a10cf76eSAxel Dörfler // 9a10cf76eSAxel Dörfler // File: MediaViews.cpp 10a10cf76eSAxel Dörfler // Author: Sikosis, Jérôme Duval 11a10cf76eSAxel Dörfler // Description: Media Preferences 12a10cf76eSAxel Dörfler // Created : June 25, 2003 13a10cf76eSAxel Dörfler // 14a10cf76eSAxel Dörfler // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15a10cf76eSAxel Dörfler 16a10cf76eSAxel Dörfler 17a10cf76eSAxel Dörfler // Includes -------------------------------------------------------------------------------------------------- // 18a10cf76eSAxel Dörfler #include <Box.h> 19a10cf76eSAxel Dörfler #include <Button.h> 20a10cf76eSAxel Dörfler #include <TextView.h> 21a10cf76eSAxel Dörfler #include <MenuField.h> 22a10cf76eSAxel Dörfler #include <PopUpMenu.h> 23a10cf76eSAxel Dörfler #include <MediaRoster.h> 24a10cf76eSAxel Dörfler #include <Deskbar.h> 25a10cf76eSAxel Dörfler #include <Entry.h> 26a10cf76eSAxel Dörfler #include <stdio.h> 27a10cf76eSAxel Dörfler #include <MediaAddOn.h> 28a10cf76eSAxel Dörfler #include <String.h> 29a10cf76eSAxel Dörfler #include "MediaViews.h" 30a10cf76eSAxel Dörfler 31a10cf76eSAxel Dörfler BarView::BarView(BRect frame) 32a10cf76eSAxel Dörfler : BView (frame, "barView", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW ), 33a10cf76eSAxel Dörfler mDisplay(true) 34a10cf76eSAxel Dörfler { 35a10cf76eSAxel Dörfler } 36a10cf76eSAxel Dörfler 37a10cf76eSAxel Dörfler void 38a10cf76eSAxel Dörfler BarView::Draw(BRect updateRect) 39a10cf76eSAxel Dörfler { 40a10cf76eSAxel Dörfler BRect r = Bounds(); 41a10cf76eSAxel Dörfler 42a10cf76eSAxel Dörfler if(mDisplay) { 43a10cf76eSAxel Dörfler // Display the 3D Look Divider Bar 44a10cf76eSAxel Dörfler SetHighColor(140,140,140,0); 45a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 46a10cf76eSAxel Dörfler SetHighColor(255,255,255,0); 47a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 48a10cf76eSAxel Dörfler } else { 49a10cf76eSAxel Dörfler SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 50a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 51a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 52a10cf76eSAxel Dörfler } 53a10cf76eSAxel Dörfler } 54a10cf76eSAxel Dörfler 55a10cf76eSAxel Dörfler 56a10cf76eSAxel Dörfler SettingsView::SettingsView (BRect frame, bool isVideo) 57a10cf76eSAxel Dörfler : BView (frame, "SettingsView", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ), 58a10cf76eSAxel Dörfler mIsVideo(isVideo) 59a10cf76eSAxel Dörfler { 60a10cf76eSAxel Dörfler SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 61a10cf76eSAxel Dörfler BRect rect(frame); 62a10cf76eSAxel Dörfler rect.left += 10; 63a10cf76eSAxel Dörfler rect.top += 12; 64a10cf76eSAxel Dörfler rect.right -=21; 65a10cf76eSAxel Dörfler rect.bottom = rect.top + 104; 66a10cf76eSAxel Dörfler BBox *defaultsBox = new BBox(rect, "defaults"); 67a10cf76eSAxel Dörfler defaultsBox->SetLabel(mIsVideo ? "Default Nodes" : "Defaults"); 68a10cf76eSAxel Dörfler AddChild(defaultsBox); 69a10cf76eSAxel Dörfler 70a10cf76eSAxel Dörfler BRect defaultRect(20, 22, 250, 40); 71*aaa9b739SJérôme Duval float divider = StringWidth(mIsVideo ? "Video Output:" : "Audio Output:") + 5; 72a10cf76eSAxel Dörfler mMenu1 = new BPopUpMenu("<none>"); 73a10cf76eSAxel Dörfler mMenu1->SetLabelFromMarked(true); 74a10cf76eSAxel Dörfler BMenuField *menuField1 = new BMenuField(defaultRect, "menuField1", 75a10cf76eSAxel Dörfler mIsVideo ? "Video Input:" : "Audio Input:", mMenu1); 76a10cf76eSAxel Dörfler defaultsBox->AddChild(menuField1); 77*aaa9b739SJérôme Duval menuField1->SetDivider(divider); 78a10cf76eSAxel Dörfler 79a10cf76eSAxel Dörfler defaultRect.OffsetBy(0, 26); 80a10cf76eSAxel Dörfler mMenu2 = new BPopUpMenu("<none>"); 81a10cf76eSAxel Dörfler mMenu2->SetLabelFromMarked(true); 82a10cf76eSAxel Dörfler BMenuField *menuField2 = new BMenuField(defaultRect, "menuField2", 83a10cf76eSAxel Dörfler mIsVideo ? "Video Output:" : "Audio Output:", mMenu2); 84a10cf76eSAxel Dörfler defaultsBox->AddChild(menuField2); 85*aaa9b739SJérôme Duval menuField2->SetDivider(divider); 86a10cf76eSAxel Dörfler 87a10cf76eSAxel Dörfler if(!mIsVideo) { 88a10cf76eSAxel Dörfler defaultRect.OffsetBy(186, 0); 89a10cf76eSAxel Dörfler mMenu3 = new BPopUpMenu("<none>"); 90a10cf76eSAxel Dörfler mMenu3->SetLabelFromMarked(true); 91a10cf76eSAxel Dörfler BMenuField *mMenuField3 = new BMenuField(defaultRect, "menuField3", 92a10cf76eSAxel Dörfler "Channel:", mMenu3); 93a10cf76eSAxel Dörfler defaultsBox->AddChild(mMenuField3); 94*aaa9b739SJérôme Duval mMenuField3->SetDivider(StringWidth("Channel:")+5); 95a10cf76eSAxel Dörfler defaultRect.OffsetBy(-186, 0); 96a10cf76eSAxel Dörfler } 97a10cf76eSAxel Dörfler 98a10cf76eSAxel Dörfler defaultRect.OffsetBy(0, 32); 99a10cf76eSAxel Dörfler BRect restartTextRect(defaultRect); 100a10cf76eSAxel Dörfler restartTextRect.OffsetTo(B_ORIGIN); 101a10cf76eSAxel Dörfler restartTextRect.InsetBy(1,1); 102a10cf76eSAxel Dörfler rgb_color red_color = {222, 32, 33}; 103a10cf76eSAxel Dörfler mRestartTextView = new BTextView(defaultRect, "restartTextView", restartTextRect, 104a10cf76eSAxel Dörfler be_plain_font, &red_color, B_FOLLOW_ALL, B_WILL_DRAW); 105a10cf76eSAxel Dörfler mRestartTextView->Insert("Restart the Media Server to apply changes."); 106a10cf76eSAxel Dörfler mRestartTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 107a10cf76eSAxel Dörfler defaultsBox->AddChild(mRestartTextView); 108a10cf76eSAxel Dörfler mRestartTextView->Hide(); 109a10cf76eSAxel Dörfler 110a10cf76eSAxel Dörfler rect.top = rect.bottom + 10; 111a10cf76eSAxel Dörfler rect.bottom = rect.top + 162; 112a10cf76eSAxel Dörfler BBox *realtimeBox = new BBox(rect, "realtime"); 113a10cf76eSAxel Dörfler realtimeBox->SetLabel("Real-Time"); 114a10cf76eSAxel Dörfler AddChild(realtimeBox); 115a10cf76eSAxel Dörfler 116a10cf76eSAxel Dörfler BMessage *message = new BMessage(ML_ENABLE_REAL_TIME); 117a10cf76eSAxel Dörfler message->AddBool("isVideo", mIsVideo); 118a10cf76eSAxel Dörfler BRect rect2(22,20, 190, 40); 119a10cf76eSAxel Dörfler mRealtimeCheckBox = new BCheckBox(rect2, "realtimeCheckBox", 120a10cf76eSAxel Dörfler mIsVideo ? "Enable Real-Time Video" : "Enable Real-Time Audio", message); 121a10cf76eSAxel Dörfler realtimeBox->AddChild(mRealtimeCheckBox); 122a10cf76eSAxel Dörfler 123a10cf76eSAxel Dörfler uint32 flags; 124a10cf76eSAxel Dörfler BMediaRoster::Roster()->GetRealtimeFlags(&flags); 125a10cf76eSAxel Dörfler if(flags & (mIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO)) 126a10cf76eSAxel Dörfler mRealtimeCheckBox->SetValue(B_CONTROL_ON); 127a10cf76eSAxel Dörfler 128a10cf76eSAxel Dörfler rect2.top += 26; 129a10cf76eSAxel Dörfler rect2.bottom = rect2.top + 80; 130a10cf76eSAxel Dörfler rect2.right = rect.right - 15; 131a10cf76eSAxel Dörfler BRect textRect(3, 3, rect2.Width() - 3, rect2.Height() - 3); 132a10cf76eSAxel Dörfler BTextView *textView = new BTextView(rect2, "textView", textRect, B_FOLLOW_ALL, B_WILL_DRAW); 133a10cf76eSAxel Dörfler textView->Insert(mIsVideo ? "Enabling Real-Time Video allows the BeOS to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." 134a10cf76eSAxel Dörfler : "Enabling Real-time Audio allows BeOS to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM."); 135a10cf76eSAxel Dörfler textView->Insert("\n\nOnly enable this feature if you need the lowest latency possible."); 136a10cf76eSAxel Dörfler textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 137a10cf76eSAxel Dörfler realtimeBox->AddChild(textView); 138a10cf76eSAxel Dörfler 139a10cf76eSAxel Dörfler rect.top = rect.bottom + 11; 140a10cf76eSAxel Dörfler rect.bottom = rect.top + 20; 141*aaa9b739SJérôme Duval rect.left = rect.right - StringWidth("Restart Media Services") - 20; 142a10cf76eSAxel Dörfler BButton *restartButton = new BButton(rect, "restartButton", 143a10cf76eSAxel Dörfler "Restart Media Services", new BMessage(ML_RESTART_MEDIA_SERVER)); 144a10cf76eSAxel Dörfler AddChild(restartButton); 145a10cf76eSAxel Dörfler 146a10cf76eSAxel Dörfler if(!mIsVideo) { 147a10cf76eSAxel Dörfler rect.top += 4; 148a10cf76eSAxel Dörfler rect.left = frame.left + 33; 149a10cf76eSAxel Dörfler rect.right = rect.left + 180; 150a10cf76eSAxel Dörfler 151a10cf76eSAxel Dörfler mVolumeCheckBox = new BCheckBox(rect, "volumeCheckBox", 152a10cf76eSAxel Dörfler "Show Volume Control on Deskbar", new BMessage(ML_SHOW_VOLUME_CONTROL)); 153a10cf76eSAxel Dörfler AddChild(mVolumeCheckBox); 154a10cf76eSAxel Dörfler 155a10cf76eSAxel Dörfler if(BDeskbar().HasItem("MediaReplicant")) 156a10cf76eSAxel Dörfler mVolumeCheckBox->SetValue(B_CONTROL_ON); 157a10cf76eSAxel Dörfler } 158a10cf76eSAxel Dörfler } 159a10cf76eSAxel Dörfler 160a10cf76eSAxel Dörfler void 161a10cf76eSAxel Dörfler SettingsView::AddNodes(BList &list, bool isInput) 162a10cf76eSAxel Dörfler { 163a10cf76eSAxel Dörfler BMenu *menu = isInput ? mMenu1 : mMenu2; 164a10cf76eSAxel Dörfler void *item; 165a10cf76eSAxel Dörfler while ((item = menu->RemoveItem((int32)0)) != NULL) 166a10cf76eSAxel Dörfler delete static_cast<dormant_node_info *>(item); 167a10cf76eSAxel Dörfler 168a10cf76eSAxel Dörfler BMessage message(ML_DEFAULT_CHANGE); 169a10cf76eSAxel Dörfler message.AddBool("isVideo", mIsVideo); 170a10cf76eSAxel Dörfler message.AddBool("isInput", isInput); 171a10cf76eSAxel Dörfler 172a10cf76eSAxel Dörfler for (int32 i = 0; i < list.CountItems(); i++) { 173a10cf76eSAxel Dörfler dormant_node_info *info = static_cast<dormant_node_info *>(list.ItemAt(i)); 174a10cf76eSAxel Dörfler menu->AddItem(new SettingsItem(info, new BMessage(message))); 175a10cf76eSAxel Dörfler } 176a10cf76eSAxel Dörfler } 177a10cf76eSAxel Dörfler 178a10cf76eSAxel Dörfler void 179a10cf76eSAxel Dörfler SettingsView::SetDefault(dormant_node_info &info, bool isInput, int32 outputID) 180a10cf76eSAxel Dörfler { 181a10cf76eSAxel Dörfler BMenu *menu = isInput ? mMenu1 : mMenu2; 182a10cf76eSAxel Dörfler 183a10cf76eSAxel Dörfler for (int32 i = 0; i < menu->CountItems(); i++) { 184a10cf76eSAxel Dörfler SettingsItem *item = static_cast<SettingsItem *>(menu->ItemAt(i)); 185a10cf76eSAxel Dörfler if(item->mInfo && item->mInfo->addon == info.addon && item->mInfo->flavor_id == info.flavor_id) { 186a10cf76eSAxel Dörfler item->SetMarked(true); 187a10cf76eSAxel Dörfler break; 188a10cf76eSAxel Dörfler } 189a10cf76eSAxel Dörfler } 190a10cf76eSAxel Dörfler 191a10cf76eSAxel Dörfler if (!mIsVideo&&!isInput&&outputID>-1) { 192a10cf76eSAxel Dörfler BMenuItem *item; 193a10cf76eSAxel Dörfler while ((item = mMenu3->RemoveItem((int32)0)) != NULL) 194a10cf76eSAxel Dörfler delete item; 195a10cf76eSAxel Dörfler BMediaRoster *roster = BMediaRoster::Roster(); 196a10cf76eSAxel Dörfler media_node node; 197a10cf76eSAxel Dörfler media_node_id node_id; 198a10cf76eSAxel Dörfler status_t err; 199a10cf76eSAxel Dörfler if (roster->GetInstancesFor(info.addon, info.flavor_id, &node_id)!=B_OK) 200a10cf76eSAxel Dörfler err = roster->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL); 201a10cf76eSAxel Dörfler else 202a10cf76eSAxel Dörfler err = roster->GetNodeFor(node_id, &node); 203a10cf76eSAxel Dörfler 204a10cf76eSAxel Dörfler if (err == B_OK) { 205a10cf76eSAxel Dörfler media_input inputs[16]; 206a10cf76eSAxel Dörfler int32 inputCount = 16; 207a10cf76eSAxel Dörfler if (roster->GetAllInputsFor(node, inputs, 16, &inputCount)==B_OK) { 208a10cf76eSAxel Dörfler BMessage message(ML_DEFAULTOUTPUT_CHANGE); 209a10cf76eSAxel Dörfler 210a10cf76eSAxel Dörfler for (int32 i = 0; i < inputCount; i++) { 211a10cf76eSAxel Dörfler media_input *input = new media_input(); 212a10cf76eSAxel Dörfler memcpy(input, &inputs[i], sizeof(*input)); 213a10cf76eSAxel Dörfler mMenu3->AddItem(item = new Settings2Item(&info, input, new BMessage(message))); 214a10cf76eSAxel Dörfler if(inputs[i].destination.id == outputID) 215a10cf76eSAxel Dörfler item->SetMarked(true); 216a10cf76eSAxel Dörfler } 217a10cf76eSAxel Dörfler } 218a10cf76eSAxel Dörfler } 219a10cf76eSAxel Dörfler } 220a10cf76eSAxel Dörfler } 221a10cf76eSAxel Dörfler 222a10cf76eSAxel Dörfler SettingsItem::SettingsItem(dormant_node_info *info, BMessage *message, 223a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 224a10cf76eSAxel Dörfler : BMenuItem(info->name, message, shortcut, modifiers), 225a10cf76eSAxel Dörfler mInfo(info) 226a10cf76eSAxel Dörfler { 227a10cf76eSAxel Dörfler 228a10cf76eSAxel Dörfler } 229a10cf76eSAxel Dörfler 230a10cf76eSAxel Dörfler Settings2Item::Settings2Item(dormant_node_info *info, media_input *input, BMessage *message, 231a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 232a10cf76eSAxel Dörfler : BMenuItem(input->name, message, shortcut, modifiers), 233a10cf76eSAxel Dörfler mInfo(info), 234a10cf76eSAxel Dörfler mInput(input) 235a10cf76eSAxel Dörfler { 236a10cf76eSAxel Dörfler 237a10cf76eSAxel Dörfler } 238a10cf76eSAxel Dörfler 239a10cf76eSAxel Dörfler Settings2Item::~Settings2Item() 240a10cf76eSAxel Dörfler { 241a10cf76eSAxel Dörfler delete mInput; 242a10cf76eSAxel Dörfler } 243a10cf76eSAxel Dörfler 244