Exemplo n.º 1
0
status_t GlMidiEvent::ReadFrom(const BMessage& msg, bool portName)
{
	status_t				err;
	if (portName) {
		BString16			name;
		if ((err = msg.FindString(P_STR, &name)) != B_OK) return err;
		int32				id = 0;
		BMidiProducer*		prod;
		bool				found = false;
		while ((prod = BMidiRoster::NextProducer(&id)) != NULL) {
			if (prod->IsValid() && prod->Name() && name == prod->Name()) {
				portId = prod->ID();
				found = true;
				break;
			}
		}
		if (!found) return B_ERROR;
	} else {
		if ((err = msg.FindInt32(P_STR, &portId)) != B_OK) return err;
	}
	if ((err = msg.FindInt32(T_STR, &type)) != B_OK) return err;
	if ((err = msg.FindInt32(C_STR, &channel)) != B_OK) return err;
	if ((err = msg.FindInt32(V1_STR, &value1)) != B_OK) return err;
	if ((err = msg.FindInt32(V2_STR, &value2)) != B_OK) return err;
	return B_OK;
}
Exemplo n.º 2
0
static void get_dup_producer_names(map<BString, int32>& dups)
{
	int32 id = 0;
	BMidiProducer* prod;
	while ((prod=BMidiRoster::NextProducer(&id)) != NULL) {
		if (!prod->IsLocal()) {
			BString		name(prod->Name());
			dup_name_map::iterator	it = dups.find(name);
			if (it != dups.end()) (*it).second = (*it).second + 1;
			else {
				dups.insert(dup_name_map::value_type(name, 1));
			}
		}
	}
	dup_name_map::iterator		i;
	for (i = dups.begin(); i != dups.end(); i++) {
		if (i->second < 2) {
			dups.erase(i);
			/* THIS IS ABSOLUTELY NECESSARY -- if you try to iterate
			 * over begin() when the map is empty(), it just hangs.
			 */
			if (dups.empty()) break;
			i = dups.begin();
		}
	}
	for (i = dups.begin(); i != dups.end(); i++) {
		i->second = 1;
	}
}		
Exemplo n.º 3
0
/********************************************************
 * _ENDPOINT-LIST
 ********************************************************/
_EndpointList::_EndpointList(BRect frame)
		: inherited(frame, ENDPOINT_LIST_STR, B_FOLLOW_ALL,
					B_WILL_DRAW, B_NO_BORDER),
		  mLabelTarget(NULL), mDeviceTarget(NULL)
{
	SetSelectionMode(B_SINGLE_SELECTION_LIST);
	SetSortingEnabled(false);

	AddColumn( new SeqColoredColumn(MIDI_PORT_STR, 150, 20, 350, B_TRUNCATE_MIDDLE), 0);
	AddColumn( new SeqColoredColumn(TYPE_STR, 50, 20, 350, B_TRUNCATE_MIDDLE), 1);
	AddColumn( new SeqColoredColumn(DEVICE_STR, 150, 20, 350, B_TRUNCATE_MIDDLE), 2);
	AddColumn( new SeqColoredColumn(LABEL_STR, 50, 20, 350, B_TRUNCATE_MIDDLE), 3);

	int32 id = 0;
	BMidiProducer* prod;
	while ((prod=BMidiRoster::NextProducer(&id)) != NULL) {
		if (prod->IsValid() ) AddEndpoint(prod);
	}
	id = 0;
	BMidiConsumer* cons;
	while ((cons=BMidiRoster::NextConsumer(&id)) != NULL) {
		if (cons->IsValid() ) AddEndpoint(cons);
	}

	am_studio_endpoint		endpt;
	BString					l, m, n;
	for (uint32 k = 0; AmGlobals().GetStudioInfoAt(k, endpt, &l, &m, &n) == B_OK; k++) {
		AddChildRow(endpt, &l, &m, &n);
	}
}
Exemplo n.º 4
0
MidiEventMeter::MidiEventMeter(int32 producerID)
	:
	fCounter(NULL),
	fMeterLevel(0)
{
	BMidiRoster* roster = BMidiRoster::MidiRoster();
	if (roster != NULL) {
		BMidiProducer* producer = roster->FindProducer(producerID);
		if (producer != NULL) {
			BString name;
			name << producer->Name() << " Event Meter";
			fCounter = new CountEventConsumer(name.String());
			producer->Connect(fCounter);
			producer->Release();
		}
	}
}
Exemplo n.º 5
0
void MidiPlayerWindow::OnInputChanged(BMessage* msg)
{
    int32 newId;
    if (msg->FindInt32("id", &newId) == B_OK)
    {
        BMidiProducer* endp;

        endp = BMidiRoster::FindProducer(inputId);
        if (endp != NULL)
        {
            endp->Disconnect(bridge);
            endp->Release();
        }

        inputId = newId;

        endp = BMidiRoster::FindProducer(inputId);
        if (endp != NULL)
        {
            if (!instrLoaded)
            {
                scopeView->SetLoading(true);
                scopeView->Invalidate();
                UpdateIfNeeded();

                bridge->Init(B_BIG_SYNTH);
                instrLoaded = true;

                scopeView->SetLoading(false);
                scopeView->Invalidate();
            }

            endp->Connect(bridge);
            endp->Release();

            scopeView->SetLiveInput(true);
            scopeView->Invalidate();
        }
        else
        {
            scopeView->SetLiveInput(false);
            scopeView->Invalidate();
        }
    }
}
Exemplo n.º 6
0
void
MidiSetup::ConnectProducer(BString name)
{
	if (sMilkyMidiConsumer != NULL) {
		int32 id = 0;
		BMidiProducer* midiProducer = BMidiRoster::NextProducer(&id);

		while (midiProducer != NULL) {
			if (name == midiProducer->Name()) {
				midiProducer->Release();
				break;
			}

			midiProducer->Release();
			midiProducer = BMidiRoster::NextProducer(&id);
		}

		sMilkyMidiConsumer->ConnectProducer(id);
	}
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
	virtual void MessageReceived(BMessage *message)
	{
		if (message->what == B_MIDI_EVENT) {
			
			int32 op, id;
			const char* type;
			if (message->FindInt32("be:op", &op) == B_OK &&
				message->FindInt32("be:id", &id) == B_OK &&
				message->FindString("be:type", &type) == B_OK) {
				
				
				BAutolock _l(mRoster.Locker());
				
				// First look for a filter with this ID.
				AmFilterAddOnHandle* handle = NULL;
				AmConsumerFilterAddOn* caddon = NULL;
				AmProducerFilterAddOn* paddon = NULL;
				for (int32 i=0; i<mRoster.CountAddOns(); i++) {
					handle = dynamic_cast<AmFilterAddOnHandle*>(mRoster.AddOnAt(i));
					if (!handle) continue;
					caddon = dynamic_cast<AmConsumerFilterAddOn*>(handle->AddOn());
					paddon = dynamic_cast<AmProducerFilterAddOn*>(handle->AddOn());
					if (caddon && caddon->ConsumerID() == id) {
						break;
					}
					if (paddon && paddon->ProducerID() == id) {
						break;
					}
				}
				
				if (op == B_MIDI_REGISTERED) {
					// Only add if the newly registered consumer
					// doesn't already exist in the roster.
					if (strcmp(type, "consumer") == 0 && (!caddon
							|| caddon->ConsumerID() != id) ) {
						BMidiConsumer* cons = BMidiRoster::FindConsumer(id);
						if (!cons) return;
						if (cons->IsLocal()) return;
						caddon = new AmConsumerFilterAddOn(NULL, cons);
						if (caddon) {
							printf("Installing consumer %s (#%ld)\n",
									cons->Name(), cons->ID());
							mRoster.InstallAddOn(new AmFilterAddOnHandle(caddon));
						}
					} else if (strcmp(type, "producer") == 0 && (!paddon
							|| paddon->ProducerID() != id) ) {
						BMidiProducer* prod = BMidiRoster::FindProducer(id);
						if (!prod) return;
						if (prod->IsLocal()) return;
						paddon = new AmProducerFilterAddOn( NULL, prod );
						if (paddon) {
							printf("Installing producer %s (#%ld)\n",
									prod->Name(), prod->ID());
							mRoster.InstallAddOn(new AmFilterAddOnHandle(paddon));
						}
					}
					
				} else if (op == B_MIDI_UNREGISTERED) {
					if (handle && caddon || paddon) {
						printf("Removing %s (#%ld)\n",
								caddon ? caddon->Name().String() : paddon->Name().String(),
								caddon ? caddon->ConsumerID() : paddon->ProducerID());
						mRoster.RemoveAddOn(handle);
					}
				}
			}
			return;
		}
		
		BHandler::MessageReceived(message);
	}
Exemplo n.º 9
0
const BString16* GlMidiEvent::PortName() const
{
	BMidiProducer*			prod = BMidiRoster::FindProducer(portId);
	ArpVALIDATE(prod, return 0);
	return new BString16(prod->Name());
}