Esempio n. 1
0
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();
		}
	}
}
Esempio n. 2
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();
    }
}
Esempio n. 3
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;
}
Esempio n. 4
0
BMidiConsumer* 
BMidiRoster::FindConsumer(int32 id, bool localOnly)
{
	BMidiEndpoint* endp = FindEndpoint(id, localOnly);

	if ((endp != NULL) && !endp->IsConsumer()) {
		endp->Release();
		endp = NULL;
	}

	return (BMidiConsumer*) endp;
}
Esempio n. 5
0
BMidiConsumer* 
BMidiRoster::NextConsumer(int32* id)
{
	BMidiEndpoint* endp;

	while ((endp = NextEndpoint(id)) != NULL) {
		if (endp->IsConsumer()) {
			return (BMidiConsumer*) endp;
		}
		endp->Release();
	}

	return NULL;
}
Esempio n. 6
0
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;
}
Esempio n. 7
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;
}
Esempio n. 8
0
EndpointInfo::EndpointInfo(int32 id)
    : m_id(id), m_icon(NULL)
{
    BMidiRoster* roster = BMidiRoster::MidiRoster();
    if (roster) {
        BMidiEndpoint* endpoint = roster->FindEndpoint(id);
        if (endpoint) {
            printf("endpoint %ld = %p\n", id, endpoint);
            BMessage msg;
            if (endpoint->GetProperties(&msg) == B_OK) {
                m_icon = CreateIcon(&msg, DISPLAY_ICON_SIZE);
            }
            endpoint->Release();
        }
    }
}
Esempio n. 9
0
BMidiEndpoint* 
BMidiRoster::NextEndpoint(int32* id)
{
	BMidiEndpoint* endp = NULL;

	if (id != NULL) {
		BMidiRosterLooper* looper = MidiRoster()->fLooper;
		if (looper->Lock()) {
			endp = looper->NextEndpoint(id);
			if (endp != NULL) {
				endp->Acquire();
			}
			looper->Unlock();
		}
	}

	return endp;
} 
Esempio n. 10
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;
}
Esempio n. 11
0
BMidiEndpoint* 
BMidiRoster::FindEndpoint(int32 id, bool localOnly)
{
	BMidiEndpoint* endp = NULL;

	BMidiRosterLooper* looper = MidiRoster()->fLooper;
	if (looper->Lock()) {
		endp = looper->FindEndpoint(id);

		if ((endp != NULL) && endp->IsRemote()) {
			if (localOnly || !endp->IsRegistered()) {
				endp = NULL;
			}
		}

		if (endp != NULL) {
			endp->Acquire();
		}

		looper->Unlock();
	}

	return endp;
} 
Esempio n. 12
0
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;
}