static osc_data_t *
oscmidi_engine_frame_cb(osc_data_t *buf, osc_data_t *end, CMC_Frame_Event *fev)
{
	osc_data_t *buf_ptr = buf;

	if(cmc_engines_active + config.dump.enabled > 1)
		buf_ptr = osc_start_bundle_item(buf_ptr, end, &pack);
	buf_ptr = osc_start_bundle(buf_ptr, end, fev->offset, &bndl);

	if(update_zones)
	{
		OSC_MIDI_Format format = config.oscmidi.format;
		uint_fast8_t multi = config.oscmidi.multi;
		osc_data_t *itm = NULL;

		for(uint8_t z=0; z<cmc_groups_n; z++)
		{
			if(multi)
			{
				buf_ptr = osc_start_bundle_item(buf_ptr, end, &itm);
				buf_ptr = osc_set_path(buf_ptr, end, config.oscmidi.path);
				buf_ptr = osc_set_fmt(buf_ptr, end, "mmmmmm");
			}

			const zone_t *zone = &mpe.zones[z];

			// define zone span
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_RPN_LSB, 0x6);
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_RPN_MSB, 0x0);
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_DATA_ENTRY, zone->span);

			// define zone bend range
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base+1, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_RPN_LSB, 0x0);
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base+1, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_RPN_MSB, 0x0);
			const uint8_t semitone_range = ceil(oscmidi_groups[z].range);
			buf_ptr = oscmidi_serialize(buf_ptr, end, format, zone->base+1, MIDI_STATUS_CONTROL_CHANGE, MIDI_CONTROLLER_DATA_ENTRY, semitone_range);

			if(multi)
				buf_ptr = osc_end_bundle_item(buf_ptr, end, itm);
		}

		update_zones = 0;
	}

	return buf_ptr;
}
Exemplo n.º 2
0
// rt
static int
_message(osc_time_t timestamp, const char *path, const char *fmt,
	const osc_data_t *buf, size_t size, void *data)
{
	prog_t *handle = data;
	LV2_Atom_Forge *forge = &handle->forge;
	LV2_Atom_Forge_Frame frame [2];

	const osc_data_t *ptr = buf;

	LV2_Atom_Forge_Ref ref = handle->ref;
	if(ref)
		ref = osc_forge_message_push(&handle->oforge, forge, frame, path, fmt);

	for(const char *type = fmt; *type; type++)
		switch(*type)
		{
			case 'i':
			{
				int32_t i = 0;
				ptr = osc_get_int32(ptr, &i);
				if(ref)
					ref = osc_forge_int32(&handle->oforge, forge, i);
				break;
			}
			case 'f':
			{
				float f = 0.f;
				ptr = osc_get_float(ptr, &f);
				if(ref)
					ref = osc_forge_float(&handle->oforge, forge, f);
				break;
			}
			case 's':
			case 'S':
			{
				const char *s = "";
				ptr = osc_get_string(ptr, &s);
				if(ref)
					ref = osc_forge_string(&handle->oforge, forge, s);
				break;
			}
			case 'b':
			{
				osc_blob_t b = {.size = 0, .payload=NULL};
				ptr = osc_get_blob(ptr, &b);
				if(ref)
					ref = osc_forge_blob(&handle->oforge, forge, b.size, b.payload);
				break;
			}

			case 'h':
			{
				int64_t h = 0;
				ptr = osc_get_int64(ptr, &h);
				if(ref)
					ref = osc_forge_int64(&handle->oforge, forge, h);
				break;
			}
			case 'd':
			{
				double d = 0.f;
				ptr = osc_get_double(ptr, &d);
				if(ref)
					ref = osc_forge_double(&handle->oforge, forge, d);
				break;
			}
			case 't':
			{
				uint64_t t = 0;
				ptr = osc_get_timetag(ptr, &t);
				if(ref)
					ref = osc_forge_timestamp(&handle->oforge, forge, t);
				break;
			}

			case 'T':
			case 'F':
			case 'N':
			case 'I':
			{
				break;
			}

			case 'c':
			{
				char c = '\0';
				ptr = osc_get_char(ptr, &c);
				if(ref)
					ref = osc_forge_char(&handle->oforge, forge, c);
				break;
			}
			case 'm':
			{
				const uint8_t *m = NULL;
				ptr = osc_get_midi(ptr, &m);
				if(ref)
					ref = osc_forge_midi(&handle->oforge, forge, 3, m + 1); // skip port byte
				break;
			}
		}

	if(ref)
		osc_forge_message_pop(&handle->oforge, forge, frame);

	handle->ref = ref;

	return 1;
}

static const osc_method_t methods [] = {
	{NULL, NULL, _message},

	{NULL, NULL, NULL}
};

// rt
static void
_bundle_push_cb(uint64_t timestamp, void *data)
{
	prog_t *handle = data;

	handle->osc_ptr = osc_start_bundle(handle->osc_ptr, handle->osc_end, timestamp,
		&handle->bndl[handle->bndl_cnt++]);
}