Esempio n. 1
0
File: route.cpp Progetto: 87maxi/oom
void removeAllRoutes(Route src, Route dst)/*{{{*/
{
	if (src.isValid())
	{
		if (src.type == Route::MIDI_DEVICE_ROUTE)
			src.device->outRoutes()->clear();
		else
			printf("removeAllRoutes: source is not midi device\n");
	}

	if (dst.isValid())
	{
		if (dst.type == Route::MIDI_DEVICE_ROUTE)
			dst.device->inRoutes()->clear();
		else
			printf("removeAllRoutes: dest is not midi device\n");
	}
}/*}}}*/
Esempio n. 2
0
File: route.cpp Progetto: 87maxi/oom
void removeRoute(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
	if (src.type == Route::JACK_ROUTE)
	{
		if (!dst.isValid())
		{
			printf("removeRoute: source is jack, invalid destination\n");
			return;
		}

		if (dst.type == Route::TRACK_ROUTE)
		{
			if (dst.track->type() != Track::AUDIO_INPUT)
			{
				fprintf(stderr, "removeRoute: source is jack, destination is track but not audio input\n");
				// exit(-1);
				return;
			}
			RouteList* inRoutes = dst.track->inRoutes();
			iRoute i;
			for (i = inRoutes->begin(); i != inRoutes->end(); ++i)
			{
				if (*i == src)
				{
					inRoutes->erase(i);
					break;
				}
			}
		}
		else if (dst.type == Route::MIDI_DEVICE_ROUTE)
		{
			RouteList* routes = dst.device->inRoutes();
			iRoute i;
			for (i = routes->begin(); i != routes->end(); ++i)
			{
				if (*i == src)
				{
					routes->erase(i);
					break;
				}
			}
		}
		else
		{
			fprintf(stderr, "removeRoute: source is jack, destination unknown\n");
			return;
		}
	}
	else if (dst.type == Route::JACK_ROUTE)
	{
		if (!src.isValid())
		{
			printf("removeRoute: destination is jack, invalid source\n");
			return;
		}

		if (src.type == Route::TRACK_ROUTE)
		{
			if (src.track->type() != Track::AUDIO_OUTPUT)
			{
				fprintf(stderr, "removeRoute: destination is jack, source is track but not audio output\n");
				return;
			}
			RouteList* outRoutes = src.track->outRoutes();
			iRoute i;
			for (i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				if (*i == dst)
				{
					outRoutes->erase(i);
					break;
				}
			}
		}
		else if (src.type == Route::MIDI_DEVICE_ROUTE)
		{
			RouteList* routes = src.device->outRoutes();
			iRoute i;
			for (i = routes->begin(); i != routes->end(); ++i)
			{
				if (*i == dst)
				{
					routes->erase(i);
					break;
				}
			}
		}
		else
		{
			fprintf(stderr, "removeRoute: destination is jack, source unknown\n");
			// exit(-1);
			return;
		}
	}
	else if (src.type == Route::MIDI_PORT_ROUTE) // p3.3.49
	{
		if (dst.type != Route::TRACK_ROUTE)
		{
			fprintf(stderr, "removeRoute: source is midi port:%d, but destination is not track\n", src.midiPort);
			return;
		}

		if (src.isValid())
		{
			MidiPort *mp = &midiPorts[src.midiPort];
			RouteList* outRoutes = mp->outRoutes();
			for (iRoute i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				//if (*i == dst)
				if (i->type == Route::TRACK_ROUTE && i->track == dst.track) // p3.3.50 Is there a route to the track?
				{
					i->channel &= ~dst.channel; // p3.3.50 Unset the desired channel bits.
					if (i->channel == 0) // Only if there are no channel bits set, erase the route.
						outRoutes->erase(i);

					break; // For safety, keep looking and remove any more found.
					// No, must break, else crash. There should only be one route anyway...
				}
			}
		}
		else
			printf("removeRoute: source is midi port:%d but invalid\n", src.midiPort);

		if (dst.isValid())
		{
			RouteList* inRoutes = dst.track->inRoutes();
			for (iRoute i = inRoutes->begin(); i != inRoutes->end(); ++i)
			{
				if (i->type == Route::MIDI_PORT_ROUTE && i->midiPort == src.midiPort) // p3.3.50 Is there a route to the midi port?
				{
					i->channel &= ~src.channel; // p3.3.50 Unset the desired channel bits.
					if (i->channel == 0) // Only if there are no channel bits set, erase the route.
						inRoutes->erase(i);

					break; // For safety, keep looking and remove any more found.
					// No, must break, else crash. There should only be one route anyway...
				}
			}
		}
		else
			printf("removeRoute: source is midi port:%d but destination track invalid\n", src.midiPort);
	}
	else if (dst.type == Route::MIDI_PORT_ROUTE) // p3.3.49
	{
		if (src.type != Route::TRACK_ROUTE)
		{
			fprintf(stderr, "removeRoute: destination is midi port:%d, but source is not track\n", dst.midiPort);
			return;
		}

		if (src.isValid())
		{
			RouteList* outRoutes = src.track->outRoutes();
			for (iRoute i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				if (i->type == Route::MIDI_PORT_ROUTE && i->midiPort == dst.midiPort) // p3.3.50 Is there a route to the midi port?
				{
					i->channel &= ~dst.channel; // p3.3.50 Unset the desired channel bits.
					if (i->channel == 0) // Only if there are no channel bits set, erase the route.
						outRoutes->erase(i);

					break; // For safety, keep looking and remove any more found.
					// No, must break, else crash. There should only be one route anyway...
				}
			}
		}
		else
			printf("removeRoute: destination is midi port:%d but source track is invalid\n", dst.midiPort);

		if (dst.isValid())
		{
			MidiPort *mp = &midiPorts[src.midiPort];
			RouteList* inRoutes = mp->inRoutes();
			for (iRoute i = inRoutes->begin(); i != inRoutes->end(); ++i)
			{
				if (i->type == Route::TRACK_ROUTE && i->track == src.track) // p3.3.50 Is there a route to the track?
				{
					i->channel &= ~src.channel; // p3.3.50 Unset the desired channel bits.
					if (i->channel == 0) // Only if there are no channel bits set, erase the route.
						inRoutes->erase(i);

					break; // For safety, keep looking and remove any more found.
					// No, must break, else crash. There should only be one route anyway...
				}
			}
		}
		else
			printf("removeRoute: destination is midi port:%d but invalid\n", dst.midiPort);
	}
	else
	{
		if (src.type != Route::TRACK_ROUTE || dst.type != Route::TRACK_ROUTE) // p3.3.49
		{
			fprintf(stderr, "removeRoute: source and destination are not tracks\n");
			return;
		}

		if (src.isValid())
		{
			RouteList* outRoutes = src.track->outRoutes();
			for (iRoute i = outRoutes->begin(); i != outRoutes->end(); ++i)
			{
				if ((*i).name() == dst.name())
				{
					outRoutes->erase(i);
					break;
				}
			}
		}
		else
			printf("removeRoute: source is track but invalid\n");

		if (dst.isValid())
		{
			RouteList* inRoutes = dst.track->inRoutes();
			for (iRoute i = inRoutes->begin(); i != inRoutes->end(); ++i)
			{
				if ((*i).name() == src.name())
				{
					inRoutes->erase(i);
					break;
				}
			}
		}
		else
			printf("removeRoute: source is track but destination invalid\n");
	}
}/*}}}*/
Esempio n. 3
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);
		}
	}
}/*}}}*/