aboutsummaryrefslogtreecommitdiff
path: root/router.h
blob: 006d3186e6dc75146e633986b6540c19fbfc347e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (c) 2017 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#ifndef _ROUTER_LV2_H
#define _ROUTER_LV2_H

#include <stdint.h>
#if !defined(_WIN32)
#	include <sys/mman.h>
#else
#	define mlock(...)
#	define munlock(...)
#endif

#include <lv2/lv2plug.in/ns/ext/atom/atom.h>
#include <lv2/lv2plug.in/ns/ext/atom/forge.h>
#include <lv2/lv2plug.in/ns/ext/urid/urid.h>
#include <lv2/lv2plug.in/ns/ext/time/time.h>
#include <lv2/lv2plug.in/ns/ext/midi/midi.h>
#include <lv2/lv2plug.in/ns/ext/state/state.h>
#include <lv2/lv2plug.in/ns/ext/worker/worker.h>
#include <lv2/lv2plug.in/ns/ext/log/log.h>
#include <lv2/lv2plug.in/ns/ext/log/logger.h>
#include <lv2/lv2plug.in/ns/ext/options/options.h>
#include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
#include <lv2/lv2plug.in/ns/lv2core/lv2.h>

#define ROUTER_URI								"http://open-music-kontrollers.ch/lv2/router"
#define ROUTER_PREFIX							ROUTER_URI"#"

// plugin uris
#define ROUTER__ATOM_SPRINKLER		ROUTER_PREFIX"atom_sprinkler"
#define ROUTER__AUDIO_SPRINKLER		ROUTER_PREFIX"audio_sprinkler"
#define ROUTER__AUDIO_SPRINKLER_2	ROUTER_PREFIX"audio_sprinkler_2"
#define ROUTER__CV_SPRINKLER			ROUTER_PREFIX"cv_sprinkler"

#define ROUTER__ATOM_BOUNCER			ROUTER_PREFIX"atom_bouncer"
#define ROUTER__AUDIO_BOUNCER			ROUTER_PREFIX"audio_bouncer"
#define ROUTER__AUDIO_BOUNCER_2		ROUTER_PREFIX"audio_bouncer_2"
#define ROUTER__CV_BOUNCER				ROUTER_PREFIX"cv_bouncer"

#define ROUTER__ATOM_DEFLECTOR		ROUTER_PREFIX"atom_deflector"
#define ROUTER__AUDIO_DEFLECTOR		ROUTER_PREFIX"audio_deflector"
#define ROUTER__AUDIO_DEFLECTOR_2	ROUTER_PREFIX"audio_deflector_2"
#define ROUTER__CV_DEFLECTOR			ROUTER_PREFIX"cv_deflector"

#define ROUTER__nextIndex					ROUTER_PREFIX"nextIndex"
#define ROUTER__prevIndex					ROUTER_PREFIX"prevIndex"
#define ROUTER__rollOverIndex			ROUTER_PREFIX"rollOverIndex"
#define ROUTER__currentIndex			ROUTER_PREFIX"currentIndex"
#define ROUTER__switchPeriod			ROUTER_PREFIX"switchPeriod"
#define ROUTER__gateToggle				ROUTER_PREFIX"gateToggle"
#define ROUTER__gateState					ROUTER_PREFIX"gateState"

extern const LV2_Descriptor router_atom_sprinkler;
extern const LV2_Descriptor router_audio_sprinkler;
extern const LV2_Descriptor router_audio_sprinkler_2;
extern const LV2_Descriptor router_cv_sprinkler;

extern const LV2_Descriptor router_atom_bouncer;
extern const LV2_Descriptor router_audio_bouncer;
extern const LV2_Descriptor router_audio_bouncer_2;
extern const LV2_Descriptor router_cv_bouncer;

extern const LV2_Descriptor router_atom_deflector;
extern const LV2_Descriptor router_audio_deflector;
extern const LV2_Descriptor router_audio_deflector_2;
extern const LV2_Descriptor router_cv_deflector;

typedef struct _craft_t craft_t;

struct _craft_t {
	union {
		LV2_Atom_Sequence *seq;
		uint8_t *buf;
	};
	LV2_Atom_Forge forge;
	LV2_Atom_Forge_Frame frame;
	LV2_Atom_Forge_Ref ref;
};

static inline void
_craft_init(craft_t *craft, LV2_URID_Map *map)
{
	lv2_atom_forge_init(&craft->forge, map);
}

static inline void
_craft_connect(craft_t *craft, LV2_Atom_Sequence *seq)
{
	craft->seq = seq;
}

static inline void
_craft_in(craft_t *craft)
{
	const uint32_t capacity = craft->seq->atom.size;
	lv2_atom_forge_set_buffer(&craft->forge, craft->buf, capacity);
	craft->ref = lv2_atom_forge_sequence_head(&craft->forge, &craft->frame, 0);
}

static inline void
_craft_out(craft_t *craft)
{
	if(craft->ref)
		lv2_atom_forge_pop(&craft->forge, &craft->frame);
	else
		lv2_atom_sequence_clear(craft->seq);
}

#endif // _ROUTER_LV2_H