示例#1
0
文件: MidiPort.cpp 项目: mariuz/haiku
void 
BMidiPort::ScanDevices()
{
	EmptyDeviceList();

	int32 id = 0;
	BMidiEndpoint* endp;

	while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL) {
		// Each hardware port has two endpoints associated with it, a consumer
		// and a producer. Both have the same name, so we add only one of them.

		bool addItem = true;
		for (int32 t = 0; t < fDevices->CountItems(); ++t) {
			BMidiEndpoint* other = (BMidiEndpoint*) fDevices->ItemAt(t);
			if (strcmp(endp->Name(), other->Name()) == 0) {
				addItem = false;
				break;
			}
		}

		if (addItem) {
			fDevices->AddItem(endp);
		} else {
			endp->Release();
		}
	}
}
示例#2
0
文件: MidiPort.cpp 项目: mariuz/haiku
status_t 
BMidiPort::GetDeviceName(int32 n, char* name, size_t bufSize)
{
	BMidiEndpoint* endp = (BMidiEndpoint*) fDevices->ItemAt(n);
	if (endp == NULL)
		return B_BAD_VALUE;

	size_t size = strlen(endp->Name());
	if (size >= bufSize)
		return B_NAME_TOO_LONG;

	strcpy(name, endp->Name());
	return B_OK;
}
示例#3
0
void MidiPlayerWindow::MenusBeginning()
{
    for (int32 t = inputPopUp->CountItems() - 1; t > 0; --t)
    {
        delete inputPopUp->RemoveItem(t);
    }

    // Note: if the selected endpoint no longer exists, then no endpoint is
    // marked. However, we won't disconnect it until you choose another one.

    inputOff->SetMarked(inputId == -1);

    int32 id = 0;
    BMidiEndpoint* endp;
    while ((endp = BMidiRoster::NextEndpoint(&id)) != NULL)
    {
        if (endp->IsProducer())
        {
            BMessage* msg = new BMessage;
            msg->what = MSG_INPUT_CHANGED;
            msg->AddInt32("id", id);

            BMenuItem* item = new BMenuItem(endp->Name(), msg);
            inputPopUp->AddItem(item);
            item->SetMarked(inputId == id);
        }

        endp->Release();
    }
}
示例#4
0
bool
PatchView::GetToolTipAt(BPoint point, BToolTip** tip)
{
	bool found = false;
	int32 index = 0;
	endpoint_itor begin, end;
	int32 size = fConsumers.size();
	for (int32 i = 0; !found && i < size; i++) {
		BRect r = ColumnIconFrameAt(i);
		if (r.Contains(point)) {
			begin = fConsumers.begin();
			end = fConsumers.end();
			found = true;
			index = i;
		}
	}
	size = fProducers.size();
	for (int32 i = 0; !found && i < size; i++) {
		BRect r = RowIconFrameAt(i);
		if (r.Contains(point)) {
			begin = fProducers.begin();
			end = fProducers.end();
			found = true;
			index = i;
		}
	}
	
	if (!found)
		return false;

	endpoint_itor itor;
	for (itor = begin; itor != end; itor++, index--)
		if (index <= 0)
			break;
	
	if (itor == end)
		return false;

	BMidiRoster* roster = BMidiRoster::MidiRoster();
	if (roster == NULL)
		return false;
	BMidiEndpoint* obj = roster->FindEndpoint(itor->ID());
	if (obj == NULL)
		return false;

	BString str;
	str << "<" << obj->ID() << ">: " << obj->Name();
	obj->Release();

	SetToolTip(str.String());

	*tip = ToolTip();

	return true;
}
示例#5
0
status_t _EndpointList::MidiRegistered(int32 id, AmEndpointType type)
{
	BMidiEndpoint*	endpoint = BMidiRoster::FindEndpoint(id);
	if (!endpoint) {
		ArpASSERT(false);
		return B_ERROR;
	}
	if (!endpoint->IsValid() ) return B_ERROR;
	BString			name = endpoint->Name();
	_EndpointRow*	p = ParentNamed(name, type);
	if (p) return B_OK;
	AddEndpoint(endpoint);
	return B_OK;
}
示例#6
0
status_t _EndpointList::MidiUnregistered(int32 id, AmEndpointType type)
{
	BMidiEndpoint*	endpoint = BMidiRoster::FindEndpoint(id);
	if (!endpoint) {
		ArpASSERT(false);
		return B_ERROR;
	}
	BString			name = endpoint->Name();
	_EndpointRow*	p = ParentNamed(name, type);
	if (!p) return B_ERROR;
	if (!p->HasChanges() ) {
		DeleteRow(p);
	} else {
		p->SetIsValid(false);
		UpdateRow(p);
	}
	return B_OK;
}
示例#7
0
文件: MidiPort.cpp 项目: mariuz/haiku
status_t 
BMidiPort::Open(const char* name)
{
	fStatus = B_ERROR;

	if (name != NULL) {
		Close();

		for (int32 t = 0; t < fDevices->CountItems(); ++t) {
			BMidiEndpoint* endp = (BMidiEndpoint*) fDevices->ItemAt(t);
			if (strcmp(name, endp->Name()) != 0)
				continue;
			if (!endp->IsValid())  // still exists?
				continue;
			if (endp->IsProducer()) {
				if (fRemoteSource == NULL)
					fRemoteSource = (BMidiProducer*) endp;
			} else {
				if (fRemoteSink == NULL) {
					fRemoteSink = (BMidiConsumer*) endp;
					fLocalSource->Connect(fRemoteSink);
				}
			}
		}

		if (fRemoteSource != NULL) {
			fPortName = strdup(fRemoteSource->Name());
			fStatus = B_OK;
		} else if (fRemoteSink != NULL) {
			fPortName = strdup(fRemoteSink->Name());
			fStatus = B_OK;
		}
	}

	return fStatus;
}