Forward input (but not sequencer or app-generated) MIDI messages to Python via on_idle.
[calfbox.git] / rt.h
blobc3b1c0e7249501af4d684400159a448f46b5a788
1 /*
2 Calf Box, an open source musical instrument.
3 Copyright (C) 2010-2011 Krzysztof Foltman
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CBOX_PROCMAIN_H
20 #define CBOX_PROCMAIN_H
22 #include <stdint.h>
23 #include <jack/ringbuffer.h>
25 #include "cmd.h"
26 #include "dom.h"
27 #include "midi.h"
28 #include "mididest.h"
30 #define RT_CMD_QUEUE_ITEMS 1024
31 #define RT_MAX_COST_PER_CALL 100
33 struct cbox_instruments;
34 struct cbox_scene;
35 struct cbox_io;
36 struct cbox_midi_pattern;
37 struct cbox_song;
38 struct cbox_rt_cmd_instance;
40 struct cbox_rt_cmd_definition
42 int (*prepare)(void *user_data); // non-zero to skip the whole thing
43 int (*execute)(void *user_data); // returns cost
44 void (*cleanup)(void *user_data);
47 CBOX_EXTERN_CLASS(cbox_rt)
49 struct cbox_rt
51 CBOX_OBJECT_HEADER()
53 struct cbox_scene *scene;
54 struct cbox_module *effect;
56 struct cbox_io *io;
57 struct cbox_io_callbacks *cbs;
58 struct cbox_master *master;
59 struct cbox_midi_buffer midibuf_aux, midibuf_jack, midibuf_song, midibuf_total;
60 struct cbox_midi_merger scene_input_merger;
62 jack_ringbuffer_t *rb_execute, *rb_cleanup;
63 struct cbox_midi_buffer midibufs_appsink[2];
64 int current_appsink_buffer;
66 struct cbox_command_target cmd_target;
67 int started, disconnected;
68 int srate;
69 int buffer_size;
72 extern struct cbox_rt *cbox_rt_new(struct cbox_document *doc);
74 extern void cbox_rt_set_io(struct cbox_rt *rt, struct cbox_io *io);
75 extern void cbox_rt_set_offline(struct cbox_rt *rt, int sample_rate, int buffer_size);
76 extern void cbox_rt_start(struct cbox_rt *rt, struct cbox_command_target *fb);
77 extern void cbox_rt_handle_cmd_queue(struct cbox_rt *rt);
78 extern void cbox_rt_stop(struct cbox_rt *rt);
80 extern void cbox_rt_update_song_playback(struct cbox_rt *rt);
82 // Those are for calling from the main thread. I will add a RT-thread version later.
83 extern void cbox_rt_execute_cmd_sync(struct cbox_rt *rt, struct cbox_rt_cmd_definition *cmd, void *user_data);
84 extern void cbox_rt_execute_cmd_async(struct cbox_rt *rt, struct cbox_rt_cmd_definition *cmd, void *user_data);
85 extern void *cbox_rt_swap_pointers(struct cbox_rt *rt, void **ptr, void *new_value);
86 extern void *cbox_rt_swap_pointers_and_update_count(struct cbox_rt *rt, void **ptr, void *new_value, int *pcount, int new_count);
88 extern void cbox_rt_array_insert(struct cbox_rt *rt, void ***ptr, int *pcount, int index, void *new_value);
89 extern void *cbox_rt_array_remove(struct cbox_rt *rt, void ***ptr, int *pcount, int index);
91 // These use an RT command internally
92 extern struct cbox_scene *cbox_rt_set_scene(struct cbox_rt *rt, struct cbox_scene *scene);
93 extern struct cbox_song *cbox_rt_set_song(struct cbox_rt *rt, struct cbox_song *song, int new_pos);
94 extern struct cbox_song *cbox_rt_set_pattern(struct cbox_rt *rt, struct cbox_midi_pattern *pattern, int new_pos);
95 extern void cbox_rt_set_pattern_and_destroy(struct cbox_rt *rt, struct cbox_midi_pattern *pattern);
96 extern void cbox_rt_send_events(struct cbox_rt *rt, struct cbox_midi_buffer *buffer);
97 extern struct cbox_midi_merger *cbox_rt_get_midi_output(struct cbox_rt *rt, struct cbox_uuid *uuid);
98 extern const struct cbox_midi_buffer *cbox_rt_get_input_midi_data(struct cbox_rt *rt);
100 extern int cbox_rt_get_sample_rate(struct cbox_rt *rt);
101 extern int cbox_rt_get_buffer_size(struct cbox_rt *rt);
103 extern void cbox_rt_destroy(struct cbox_rt *rt);
105 #endif