PeerToFinderPeerLocationFindRequestPtr PeerToFinderPeerLocationFindRequest::create(ElementPtr root)
        {
          PeerToFinderPeerLocationFindRequestPtr ret(new message::PeerToFinderPeerLocationFindRequest);

          if (root)
          {
            ret->mID = IMessageHelper::getAttributeID(root);

            ElementPtr routes = root->findFirstChildElement("routes");
            if (routes)
            {
              RouteList routeLst;
              ElementPtr route = routes->findFirstChildElement("route");
              while (route)
              {
                String id = IMessageHelper::getAttributeID(route);
                routeLst.push_back(id);

                route = route->getNextSiblingElement();
              }

              if (routeLst.size() > 0)
                ret->mRoutes = routeLst;
            }

            ElementPtr exclude = root->findFirstChildElement("exclude");
            if (exclude)
            {
              ElementPtr locations = root->findFirstChildElement("locations");
              if (locations)
              {
                message::PeerToFinderPeerLocationFindRequest::ExcludedLocationList exclLst;
                ElementPtr loc = locations->findFirstChildElement("location");
                while (loc)
                {
                  String id = IMessageHelper::getAttributeID(loc);
                  exclLst.push_back(id);

                  loc = loc->getNextSiblingElement();
                }

                if (exclLst.size() > 0)
                  ret->mExcludedLocations = exclLst;
              }
            }

            ElementPtr location = root->findFirstChildElement("location");
            if (location)
            {
              ret->mLocation = MessageHelper::createLocation(location);
            }

          }

          return ret;
        }
Esempio n. 2
0
File: route.cpp Progetto: 87maxi/oom
void addRoute(Route src, Route dst)/*{{{*/
{
//TODO: Add hooks to update the patchcanvas on success
//This should be conditionally checked so we dont update if the canvas is what made the connection

#ifdef ROUTE_DEBUG
	fprintf(stderr, "addRoute:\n");
#endif

	if (!src.isValid() || !dst.isValid())
	{
		if (!src.isValid())
			fprintf(stderr, "addRoute: invalid src\n");
		if (!dst.isValid())
			fprintf(stderr, "addRoute: invalid dst\n");
		return;
	}

	if (src.type == Route::JACK_ROUTE)
	{
		if (dst.type == Route::TRACK_ROUTE)
		{
			if (dst.track->type() != Track::AUDIO_INPUT)
			{
				fprintf(stderr, "addRoute: source is jack, dest:%s is track but not audio input\n", dst.track->name().toLatin1().constData());
				return;
			}
			if (dst.channel < 0)
			{
				fprintf(stderr, "addRoute: source is jack, dest:%s is track but invalid channel:%d\n", dst.track->name().toLatin1().constData(), dst.channel);
				return;
			}

			src.channel = dst.channel;
			RouteList* inRoutes = dst.track->inRoutes();
			for (iRoute i = inRoutes->begin(); i != inRoutes->end(); ++i)
			{
				if (*i == src) // route already there
				{
					fprintf(stderr, "addRoute: src track route already exists.\n");
					return;
				}
			}
#ifdef ROUTE_DEBUG
			fprintf(stderr, "addRoute: src Jack dst track name: %s pushing source route\n", dst.track->name().toLatin1().constData());
#endif
			inRoutes->push_back(src);
		}
		else if (dst.type == Route::MIDI_DEVICE_ROUTE)
		{
			if (dst.device->deviceType() == MidiDevice::JACK_MIDI)
			{
				src.channel = dst.channel;

				RouteList* routes = dst.device->inRoutes();
				for (iRoute i = routes->begin(); i != routes->end(); ++i)
				{
					if (*i == src) // route already there
					{
						fprintf(stderr, "addRoute: src Jack midi route already exists.\n");
						return;
					}
				}
#ifdef ROUTE_DEBUG
				fprintf(stderr, "addRoute: src Jack dst Jack midi name: %s pushing source route\n", dst.device->name().toLatin1().constData());
#endif
				routes->push_back(src);
			}
			else
			{
				fprintf(stderr, "addRoute: source is Jack, but destination is not jack midi - type:%d\n", dst.device->deviceType());
				return;
			}
		}
		else
		{
			fprintf(stderr, "addRoute: source is Jack, but destination is not track or midi - type:%d \n", dst.type);
			return;
		}
	}
	else if (dst.type == Route::JACK_ROUTE)
	{
		if (src.type == Route::TRACK_ROUTE)
		{
			if (src.track->type() != Track::AUDIO_OUTPUT)
			{
				fprintf(stderr, "addRoute: destination is jack, source is track but not audio output\n");
				return;
			}
			if (src.channel < 0)
			{
				fprintf(stderr, "addRoute: destination is jack, source:%s is track but invalid channel:%d\n", src.track->name().toLatin1().constData(), src.channel);
				return;
			}

			RouteList* outRoutes = src.track->outRoutes();
			dst.channel = src.channel;

			for (iRoute i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				if (*i == dst) // route already there
				{
#ifdef ROUTE_DEBUG
					fprintf(stderr, "addRoute: dst track route already exists.\n");
#endif
					return;
				}
			}
#ifdef ROUTE_DEBUG
			fprintf(stderr, "addRoute: dst Jack src track name: %s pushing destination route\n", src.track->name().toLatin1().constData());
#endif
			outRoutes->push_back(dst);
		}
		else if (src.type == Route::MIDI_DEVICE_ROUTE)
		{
			if (src.device->deviceType() == MidiDevice::JACK_MIDI)
			{
				dst.channel = src.channel;

				RouteList* routes = src.device->outRoutes();
				for (iRoute i = routes->begin(); i != routes->end(); ++i)
				{
					if (*i == dst) // route already there
					{
						fprintf(stderr, "addRoute: dst Jack midi route already exists.\n");
						return;
					}
				}
#ifdef ROUTE_DEBUG
				fprintf(stderr, "addRoute: dst Jack src Jack midi name: %s pushing destination route\n", src.device->name().toLatin1().constData());
#endif
				routes->push_back(dst);
			}
			else
			{
				fprintf(stderr, "addRoute: destination is Jack, but source is not jack midi - type:%d\n", src.device->deviceType());
				return;
			}
		}
		else
		{
			fprintf(stderr, "addRoute: destination is Jack, but source is not track or midi - type:%d \n", src.type);
			return;
		}
	}
	else if (src.type == Route::MIDI_PORT_ROUTE) // p3.3.49
	{
		if (dst.type != Route::TRACK_ROUTE)
		{
			fprintf(stderr, "addRoute: source is midi port:%d, but destination is not track\n", src.midiPort);
			return;
		}
		if (dst.channel < 1 || dst.channel >= (1 << MIDI_CHANNELS))
		{
			fprintf(stderr, "addRoute: source is midi port:%d, but destination channel mask:%d out of range\n", src.midiPort, dst.channel);
			return;
		}

		MidiPort *mp = &midiPorts[src.midiPort];

		src.channel = dst.channel;
		RouteList* outRoutes = mp->outRoutes();
		iRoute ir = outRoutes->begin(); // p3.3.50
		for (; ir != outRoutes->end(); ++ir)
		{
			if (ir->type == Route::TRACK_ROUTE && ir->track == dst.track) // p3.3.50 Does a route to the track exist?
			{
				ir->channel |= dst.channel; // p3.3.50 Bitwise OR the desired channel bit with the existing bit mask.
				break;
			}
		}
#ifdef ROUTE_DEBUG
		fprintf(stderr, "addRoute: src midi port:%d dst track name:%s pushing dst and src routes\n", src.midiPort, dst.track->name().toLatin1().constData());
#endif

		if (ir == outRoutes->end()) // p3.3.50 Only if route not found, add the route, with the requested channel bits as mask to start with.
			outRoutes->push_back(dst);

		RouteList* inRoutes = dst.track->inRoutes();

		// p3.3.50 Make sure only one single route, with a channel mask, can ever exist.
		ir = inRoutes->begin();
		for (; ir != inRoutes->end(); ++ir)
		{
			if (ir->type == Route::MIDI_PORT_ROUTE && ir->midiPort == src.midiPort) // p3.3.50 Does a route to the midi port exist?
			{
				ir->channel |= src.channel; // p3.3.50 Bitwise OR the desired channel bit with the existing bit mask.
				break;
			}
		}

		if (ir == inRoutes->end()) // p3.3.50 Only if route not found, add the route, with the requested channel bits as mask to start with.
			inRoutes->push_back(src);
	}
	else if (dst.type == Route::MIDI_PORT_ROUTE) // p3.3.49
	{
		if (src.type != Route::TRACK_ROUTE)
		{
			fprintf(stderr, "addRoute: destination is midi port:%d, but source is not track\n", dst.midiPort);
			return;
		}
		if (src.channel < 1 || src.channel >= (1 << MIDI_CHANNELS))
		{
			fprintf(stderr, "addRoute: destination is midi port:%d, but source channel mask:%d out of range\n", dst.midiPort, src.channel);
			return;
		}

		dst.channel = src.channel;
		RouteList* outRoutes = src.track->outRoutes();

		iRoute ir = outRoutes->begin(); // p3.3.50
		for (; ir != outRoutes->end(); ++ir)
		{
			if (ir->type == Route::MIDI_PORT_ROUTE && ir->midiPort == dst.midiPort) // p3.3.50 Does a route to the midi port exist?
			{
				ir->channel |= dst.channel; // p3.3.50 Bitwise OR the desired channel bit with the existing bit mask.
				break;
			}
		}

		if (ir == outRoutes->end()) // p3.3.50 Only if route not found, add the route, with the requested channel bits as mask to start with.
			outRoutes->push_back(dst);

		MidiPort *mp = &midiPorts[dst.midiPort];

#ifdef ROUTE_DEBUG
		fprintf(stderr, "addRoute: src track:%s dst midi port:%d pushing dst and src routes\n", src.track->name().toLatin1().constData(), dst.midiPort);
#endif
		RouteList* inRoutes = mp->inRoutes();

		// p3.3.50 Make sure only one single route, with a channel mask, can ever exist.
		ir = inRoutes->begin();
		for (; ir != inRoutes->end(); ++ir)
		{
			if (ir->type == Route::TRACK_ROUTE && ir->track == src.track) // p3.3.50 Does a route to the track exist?
			{
				ir->channel |= src.channel; // p3.3.50 Bitwise OR the desired channel bit with the existing bit mask.
				break;
			}
		}

		if (ir == inRoutes->end()) // p3.3.50 Only if route not found, add the route, with the requested channel bits as mask to start with.
			inRoutes->push_back(src);
	}
	else
	{
		if (src.type != Route::TRACK_ROUTE || dst.type != Route::TRACK_ROUTE) // p3.3.49
		{
			fprintf(stderr, "addRoute: source or destination are not track routes\n");
			return;
		}

		{
			RouteList* outRoutes = src.track->outRoutes();

			//
			// Must enforce to ensure channel and channels are valid if defaults of -1 passed.
			//
			if (src.track->type() == Track::AUDIO_SOFTSYNTH)
			{
				if (src.channel == -1)
					src.channel = 0;
				if (src.channels == -1)
					src.channels = src.track->channels();
				dst.channel = src.channel;
				dst.channels = src.channels;
				dst.remoteChannel = src.remoteChannel;
			}

			for (iRoute i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				if (*i == dst) // route already there
				{
					//#ifdef ROUTE_DEBUG
					fprintf(stderr, "addRoute: src track route already exists.\n");
					//#endif
					return;
				}
			}
			outRoutes->push_back(dst);
			RouteList* inRoutes;

			{
#ifdef ROUTE_DEBUG
				fprintf(stderr, "addRoute: src track ch:%d chs:%d remch:%d  dst track ch:%d chs:%d remch:%d name: %s pushing dest and source routes\n",
						src.channel, src.channels, src.remoteChannel, dst.channel, dst.channels, dst.remoteChannel, dst.track->name().toLatin1().constData());
#endif
				inRoutes = dst.track->inRoutes();
			}


			//
			// make sure AUDIO_AUX is processed last
			//
			if (src.track->type() == Track::AUDIO_AUX)
				inRoutes->push_back(src);
			else
				inRoutes->insert(inRoutes->begin(), src);
		}
	}
}/*}}}*/