Exemplo n.º 1
0
Arquivo: route.cpp Projeto: 87maxi/oom
Route name2route(const QString& rn, bool /*dst*/, int rtype)/*{{{*/
{
	// printf("name2route %s\n", rn.toLatin1().constData());
	int channel = -1;
	QString s(rn);
	// Support old route style in oom files. Obsolete.
	if (rn.size() >= 2 && rn[0].isNumber() && rn[1] == ':')
	{
		channel = rn[0].toAscii() - int('1');
		s = rn.mid(2);
	}

	if (rtype == -1)
	{
		if (checkAudioDevice())
		{
			void* p = audioDevice->findPort(s.toLatin1().constData());
			if (p)
				return Route(p, channel);
		}

		TrackList* tl = song->tracks();
		for (iTrack i = tl->begin(); i != tl->end(); ++i)
		{
			if ((*i)->isMidiTrack())
			{
				MidiTrack* track = (MidiTrack*) * i;
				if (track->name() == s)
					return Route(track, channel);
			}
			else
			{
				AudioTrack* track = (AudioTrack*) * i;
				if (track->name() == s)
					return Route(track, channel);
			}
		}

		for (iMidiDevice i = midiDevices.begin(); i != midiDevices.end(); ++i)
		{
			if ((*i)->name() == s)
				return Route(*i, channel);
		}

		// p3.3.49
		if (s.left(ROUTE_MIDIPORT_NAME_PREFIX.length()) == ROUTE_MIDIPORT_NAME_PREFIX)
		{
			bool ok = false;
			int port = s.mid(ROUTE_MIDIPORT_NAME_PREFIX.length()).toInt(&ok);
			if (ok)
				return Route(port, channel);
		}
	}
	else
	{
		if (rtype == Route::TRACK_ROUTE)
		{
			TrackList* tl = song->tracks();
			for (iTrack i = tl->begin(); i != tl->end(); ++i)
			{
				if ((*i)->isMidiTrack())
				{
					MidiTrack* track = (MidiTrack*) * i;
					if (track->name() == s)
						return Route(track, channel);
				}
				else
				{
					AudioTrack* track = (AudioTrack*) * i;
					if (track->name() == s)
						return Route(track, channel);
				}
			}
		}// TODO Distinguish the device types
		else if (rtype == Route::MIDI_DEVICE_ROUTE)
		{
			for (iMidiDevice i = midiDevices.begin(); i != midiDevices.end(); ++i)
			{
				if ((*i)->name() == s)
					return Route(*i, channel);
			}
		}
		else if (rtype == Route::JACK_ROUTE)
		{
			if (checkAudioDevice())
			{
				void* p = audioDevice->findPort(s.toLatin1().constData());
				if (p)
					return Route(p, channel);
			}
		}
		else if (rtype == Route::MIDI_PORT_ROUTE) // p3.3.49
		{
			if (s.left(ROUTE_MIDIPORT_NAME_PREFIX.length()) == ROUTE_MIDIPORT_NAME_PREFIX)
			{
				bool ok = false;
				int port = s.mid(ROUTE_MIDIPORT_NAME_PREFIX.length()).toInt(&ok);
				if (ok)
					return Route(port, channel);
			}
		}
	}

	printf("  name2route: <%s> not found\n", rn.toLatin1().constData());
	return Route((Track*) 0, channel);
}/*}}}*/
Exemplo n.º 2
0
void AudioPortConfig::trackSelectionChanged()
{
    routeList->clear();
    newSrcList->clear();
    newDstList->clear();
    QListWidgetItem* titem = tracksList->currentItem();
    AudioTrack* atrack = (AudioTrack*)song->findTrack(titem->text());
    if(atrack)
    {
        _selected = atrack;
        selectedIndex = tracksList->row(titem);
        //TrackList* tl = song->tracks();
        //for(iTrack t = tl->begin(); t != tl->end(); ++t)
        //{
        //	if((*t)->isMidiTrack())
        //		continue;
        //	AudioTrack* track = (AudioTrack*) (*t);
        //	if(track->name() == atrack->name())
        //		continue; //You cant connect a track to itself
            //int channels = track->channels();
            switch (atrack->type())
            {
                case Track::WAVE_OUTPUT_HELPER:/*{{{*/
                    for(iTrack t = song->tracks()->begin(); t != song->tracks()->end(); ++t)
                    {
                        if((*t)->isMidiTrack())
                            continue;
                        AudioTrack* track = (AudioTrack*) (*t);
                        if(track->name() == atrack->name() || track->type() == Track::WAVE_OUTPUT_HELPER)
                            continue; //You cant connect a track to itself
                        //for (int channel = 0; channel < track->channels(); ++channel)
                        //{
                            Route r(track, -1);
                            newSrcList->addItem(r.name());
                        //}
                    }
                    insertInputs();
                    //newDstList->addItem(Route(track, -1).name());
                break;
                case Track::WAVE_INPUT_HELPER:
                    for(iTrack t = song->tracks()->begin(); t != song->tracks()->end(); ++t)
                    {
                        if((*t)->isMidiTrack())
                            continue;
                        AudioTrack* track = (AudioTrack*) (*t);
                        if(track->name() == atrack->name())
                            continue; //You cant connect a track to itself
                        switch(track->type())
                        {
                            case Track::WAVE_OUTPUT_HELPER:
                            case Track::WAVE:
                                newDstList->addItem(Route(track, -1).name());
                            break;
                            default:
                            break;
                        }
                    }
                    insertOutputs();
                break;
                case Track::WAVE:
                    for(iTrack t = song->tracks()->begin(); t != song->tracks()->end(); ++t)
                    {
                        if((*t)->isMidiTrack())
                            continue;
                        AudioTrack* track = (AudioTrack*) (*t);
                        if(track->name() == atrack->name())
                            continue; //You cant connect a track to itself
                        if(track->type() == Track::WAVE_INPUT_HELPER)
                        {
                            newSrcList->addItem(Route(track, -1).name());
                        }
                        else if(track->type() == Track::WAVE_OUTPUT_HELPER)
                        {
                            newDstList->addItem(Route(track, -1).name());
                        }
                    }
                break;
                default:
                break;/*}}}*/
            }
        //}

                QTreeWidgetItem* widgetItem;
        const RouteList* rl = atrack->outRoutes();
        for (ciRoute r = rl->begin(); r != rl->end(); ++r)
        {
                        QString src("");
            if (atrack->type() == Track::WAVE_OUTPUT_HELPER)
            {
                                widgetItem = new QTreeWidgetItem(routeList, QStringList() << src << QString("") << atrack->name() << r->name() << QString::number(r->channel), Track::WAVE_OUTPUT_HELPER);
            }
            else
            {
                                widgetItem = new QTreeWidgetItem(routeList, QStringList() << src << QString("") << atrack->name() << r->name() << QString::number(0), Track::WAVE_OUTPUT_HELPER);
            }
                        widgetItem->setTextAlignment(1, Qt::AlignHCenter);
                        widgetItem->setTextAlignment(4, Qt::AlignHCenter);
                }
                const RouteList* rli = atrack->inRoutes();
                for (ciRoute ri = rli->begin(); ri != rli->end(); ++ri)
                {
                        QString src("");
                        if (atrack->type() == Track::WAVE_INPUT_HELPER)
                        {
                                widgetItem = new QTreeWidgetItem(routeList, QStringList() << ri->name() << QString::number(ri->channel) << atrack->name() << src << QString(""), Track::WAVE_INPUT_HELPER);
                        }
                        else
                        {
                                widgetItem = new QTreeWidgetItem(routeList, QStringList() << ri->name() << QString::number(0) << atrack->name() << src << QString(""), Track::WAVE_INPUT_HELPER);
                        }
                        widgetItem->setTextAlignment(1, Qt::AlignHCenter);
                        widgetItem->setTextAlignment(4, Qt::AlignHCenter);
                }
        routeSelectionChanged(); // init remove button
        srcSelectionChanged(); // init select button
    }
}