예제 #1
0
파일: sound.cpp 프로젝트: voorhees1979/PUAE
int setup_sound (void)
{
    status_t err;
    BMediaRoster *gMediaRoster;
    media_node *outNode;
    outNode = new media_node;
    gMediaRoster = BMediaRoster::Roster (&err);

    if (gMediaRoster && err == B_OK)
        err = gMediaRoster->GetAudioOutput (outNode);

    if ((!gMediaRoster) || (err != B_OK)) {
        write_log ("NO MEDIA ROSTER! The media server "
                   "appears to be dead.\n"
                   "\t-- roster %p -- error %08lx (%ld)\n",
                   gMediaRoster, err, err);

        sound_available = 0;
    } else
        sound_available = 1;

    return sound_available;
}
예제 #2
0
status_t
MediaWindow::_InitMedia(bool first)
{
	status_t err = B_OK;
	BMediaRoster* roster = BMediaRoster::Roster(&err);

	if (first && err != B_OK) {
		BAlert* alert = new BAlert("start_media_server",
			B_TRANSLATE("Could not connect to the media server.\n"
				"Would you like to start it ?"),
			B_TRANSLATE("Quit"),
			B_TRANSLATE("Start media server"), NULL,
			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetShortcut(0, B_ESCAPE);
		if (alert->Go() == 0)
			return B_ERROR;

		Show();

		launch_media_server();
	}

	Lock();

	bool isVideoSelected = true;
	if (!first && fListView->ItemAt(0) != NULL
		&& fListView->ItemAt(0)->IsSelected())
		isVideoSelected = false;

	while (fListView->CountItems() > 0)
		delete fListView->RemoveItem((int32)0);
	_EmptyNodeLists();

	// Grab Media Info
	_FindNodes();

	// Add video nodes first. They might have an additional audio
	// output or input, but still should be listed as video node.
	_AddNodeItems(fVideoOutputs, MediaListItem::VIDEO_TYPE);
	_AddNodeItems(fVideoInputs, MediaListItem::VIDEO_TYPE);
	_AddNodeItems(fAudioOutputs, MediaListItem::AUDIO_TYPE);
	_AddNodeItems(fAudioInputs, MediaListItem::AUDIO_TYPE);

	fAudioView->AddOutputNodes(fAudioOutputs);
	fAudioView->AddInputNodes(fAudioInputs);
	fVideoView->AddOutputNodes(fVideoOutputs);
	fVideoView->AddInputNodes(fVideoInputs);

	// build our list view
	DeviceListItem* audio = new DeviceListItem(B_TRANSLATE("Audio settings"),
		MediaListItem::AUDIO_TYPE);
	fListView->AddItem(audio);

	MidiListItem* midi = new MidiListItem(B_TRANSLATE("MIDI Settings"));
	fListView->AddItem(midi);

	MediaListItem* video = new DeviceListItem(B_TRANSLATE("Video settings"),
		MediaListItem::VIDEO_TYPE);
	fListView->AddItem(video);

	MediaListItem* mixer = new AudioMixerListItem(B_TRANSLATE("Audio mixer"));
	fListView->AddItem(mixer);

	fListView->SortItems(&MediaListItem::Compare);
	_UpdateListViewMinWidth();

	// Set default nodes for our setting views
	media_node defaultNode;
	dormant_node_info nodeInfo;
	int32 outputID;
	BString outputName;

	if (roster->GetAudioInput(&defaultNode) == B_OK) {
		roster->GetDormantNodeFor(defaultNode, &nodeInfo);
		fAudioView->SetDefaultInput(&nodeInfo);
			// this causes our listview to be updated as well
	}

	if (roster->GetAudioOutput(&defaultNode, &outputID, &outputName) == B_OK) {
		roster->GetDormantNodeFor(defaultNode, &nodeInfo);
		fAudioView->SetDefaultOutput(&nodeInfo);
		fAudioView->SetDefaultChannel(outputID);
			// this causes our listview to be updated as well
	}

	if (roster->GetVideoInput(&defaultNode) == B_OK) {
		roster->GetDormantNodeFor(defaultNode, &nodeInfo);
		fVideoView->SetDefaultInput(&nodeInfo);
			// this causes our listview to be updated as well
	}

	if (roster->GetVideoOutput(&defaultNode) == B_OK) {
		roster->GetDormantNodeFor(defaultNode, &nodeInfo);
		fVideoView->SetDefaultOutput(&nodeInfo);
			// this causes our listview to be updated as well
	}

	if (first)
		fListView->Select(fListView->IndexOf(mixer));
	else if (isVideoSelected)
		fListView->Select(fListView->IndexOf(video));
	else
		fListView->Select(fListView->IndexOf(audio));

	Unlock();

	return B_OK;
}
예제 #3
0
AmFilterRoster* AmFilterRoster::Default()
{
	if (atomic_or(&gFilterRosterCreated, 1) == 0) {
		gFilterRoster = new AmFilterRoster("Default Filter Roster");
		
		gFilterRoster->AddSearchPath("%A/add-ons/Filters");
		gFilterRoster->AddDirectory(B_SYSTEM_ADDONS_DIRECTORY,"AngryRedPlanet/Sequitur/Filters");
		gFilterRoster->AddDirectory(B_USER_ADDONS_DIRECTORY,"AngryRedPlanet/Sequitur/Filters");
		
		// Here are our standard filter addons...
		AmFilterAddOn *addon;
		
		// Forcibly add in all existing consumers, so that when we
		// return we have everything as it currently exists.  This is
		// to take care of situations where, say, the file loader is the
		// first thing to open the roster and immediately starts trying
		// to instantiate consumer filters.
		BMidiConsumer* cons;
		/* Hack -- keep track of the producer / consumer names that are
		 * installed, and if a name gets installed more than one, increment
		 * a counter for it.  This is so users can run multiple instances of
		 * a softsynth and access each independently.
		 */
		dup_name_map	dups;
		get_dup_consumer_names(dups);
		int32 id = 0;
		while ((cons=BMidiRoster::NextConsumer(&id)) != NULL) {
			if (!cons->IsLocal()) {
				BString msg("Installing MIDI consumer ");
				msg += cons->Name();
				msg += "...";
				am_report_startup_status(msg.String());
				int32					index = 0;
				dup_name_map::iterator	i = dups.find(BString(cons->Name()));
				if (i != dups.end()) {
					index = i->second;
					i->second = i->second + 1;
				}
				addon = new AmConsumerFilterAddOn(NULL, cons, index);
				if (addon) {
					printf("Installing consumer %s (#%ld)\n", cons->Name(), cons->ID());
					gFilterRoster->InstallAddOn(new AmFilterAddOnHandle(addon));
#if 0
					BMessage	props;
					if( cons->GetProperties( &props ) == B_OK ) {
printf("****** CONSUMER HAS PROPERTIES:\n");
props.PrintToStream();
printf("****** END PROPERTIES\n");
					}
#endif
				}
			}
		}

		dups.erase(dups.begin(), dups.end());
		get_dup_producer_names(dups);
		id = 0;
		BMidiProducer* prod;
		while ((prod=BMidiRoster::NextProducer(&id)) != NULL) {
			if (!prod->IsLocal()) {
				BString msg("Installing MIDI producer ");
				msg += prod->Name();
				msg += "...";
				am_report_startup_status(msg.String());
				int32					index = 0;
				dup_name_map::iterator	i = dups.find(BString(prod->Name()));
				if (i != dups.end()) {
					index = i->second;
					i->second = i->second + 1;
				}
				addon = new AmProducerFilterAddOn(NULL, prod, index);
				if (addon) {
					printf("Installing producer%s (#%ld)\n", prod->Name(), prod->ID());
					gFilterRoster->InstallAddOn(new AmFilterAddOnHandle(addon));
				}
			}
		}
		/* Add in a filter for the BeOS MIDI synth if there's any
		 * audio output.
		 */
		status_t		err;
		am_report_startup_status("Installing MIDI Synth consumer...");
		BMediaRoster*	roster = BMediaRoster::Roster( &err );
		if( err == B_OK && roster ) {
			media_node	node;
			err = roster->GetAudioOutput( &node );
			if( err == B_OK ) {
				// Add in a filter for the BeOS MIDI synth.
				if ((addon = new AmConsumerFilterAddOn(NULL)) != NULL)
					gFilterRoster->InstallAddOn(new AmFilterAddOnHandle(addon));
//				node.ReleaseNode();
			}
		}
		/* Add the generic input/output filters, for tool and multi filter pipelines.
		 */
		if ((addon = new AmNullInputAddOn(NULL)) != NULL)
			gFilterRoster->InstallAddOn(new AmFilterAddOnHandle(addon));
		if ((addon = new AmNullOutputAddOn(NULL)) != NULL)
			gFilterRoster->InstallAddOn(new AmFilterAddOnHandle(addon));

		// Go!
		gFilterRoster->Run();
	} else {
		while (!gFilterRoster) sleep(20000);
	}
	return gFilterRoster;
}
예제 #4
0
status_t
MediaWindow::InitMedia(bool first)
{
	status_t err = B_OK;
	BMediaRoster* roster = BMediaRoster::Roster(&err);

	if (first && err != B_OK) {
		BAlert* alert = new BAlert("start_media_server",
			B_TRANSLATE("Could not connect to the media server.\n"
			"Would you like to start it ?"),
			B_TRANSLATE("Quit"),
			B_TRANSLATE("Start media server"), NULL,
			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		if (alert->Go()==0)
			return B_ERROR;

		fAlert = new MediaAlert(BRect(0, 0, 300, 60),
			"restart_alert", B_TRANSLATE(
				"Restarting media services\nStarting media server"
				B_UTF8_ELLIPSIS "\n"));
		fAlert->Show();

		Show();

		launch_media_server();
	}

	Lock();

	bool isVideoSelected = true;
	if (!first && fListView->ItemAt(0) && fListView->ItemAt(0)->IsSelected())
		isVideoSelected = false;

	if ((!first || (first && err) ) && fAlert) {
		BAutolock locker(fAlert);
		if (locker.IsLocked())
			fAlert->TextView()->SetText(
				B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS));
	}

	while (fListView->CountItems() > 0)
		delete fListView->RemoveItem((int32)0);
	_EmptyNodeLists();

	// Grab Media Info
	_FindNodes();

	// Add video nodes first. They might have an additional audio
	// output or input, but still should be listed as video node.
	_AddNodeItems(fVideoOutputs, MediaListItem::VIDEO_TYPE);
	_AddNodeItems(fVideoInputs, MediaListItem::VIDEO_TYPE);
	_AddNodeItems(fAudioOutputs, MediaListItem::AUDIO_TYPE);
	_AddNodeItems(fAudioInputs, MediaListItem::AUDIO_TYPE);

	fAudioView->AddOutputNodes(fAudioOutputs);
	fAudioView->AddInputNodes(fAudioInputs);
	fVideoView->AddOutputNodes(fVideoOutputs);
	fVideoView->AddInputNodes(fVideoInputs);

	// build our list view
	DeviceListItem* audio = new DeviceListItem(B_TRANSLATE("Audio settings"),
		MediaListItem::AUDIO_TYPE);
	fListView->AddItem(audio);

	MediaListItem* video = new DeviceListItem(B_TRANSLATE("Video settings"),
		MediaListItem::VIDEO_TYPE);
	fListView->AddItem(video);

	MediaListItem* mixer = new AudioMixerListItem(B_TRANSLATE("Audio mixer"));
	fListView->AddItem(mixer);

	fListView->SortItems(&MediaListItem::Compare);
	_UpdateListViewMinWidth();

	// Set default nodes for our setting views
	media_node default_node;
	dormant_node_info node_info;
	int32 outputID;
	BString outputName;

	if (roster->GetAudioInput(&default_node) == B_OK) {
		roster->GetDormantNodeFor(default_node, &node_info);
		fAudioView->SetDefaultInput(&node_info);
			// this causes our listview to be updated as well
	}

	if (roster->GetAudioOutput(&default_node, &outputID, &outputName)==B_OK) {
		roster->GetDormantNodeFor(default_node, &node_info);
		fAudioView->SetDefaultOutput(&node_info);
		fAudioView->SetDefaultChannel(outputID);
			// this causes our listview to be updated as well
	}

	if (roster->GetVideoInput(&default_node)==B_OK) {
		roster->GetDormantNodeFor(default_node, &node_info);
		fVideoView->SetDefaultInput(&node_info);
			// this causes our listview to be updated as well
	}

	if (roster->GetVideoOutput(&default_node)==B_OK) {
		roster->GetDormantNodeFor(default_node, &node_info);
		fVideoView->SetDefaultOutput(&node_info);
			// this causes our listview to be updated as well
	}

	if (first) {
		fListView->Select(fListView->IndexOf(mixer));
	} else {
		if (isVideoSelected)
			fListView->Select(fListView->IndexOf(video));
		else
			fListView->Select(fListView->IndexOf(audio));
	}

	if (fAlert) {
		snooze(800000);
		fAlert->PostMessage(B_QUIT_REQUESTED);
	}
	fAlert = NULL;

	Unlock();

	return B_OK;
}