1/* FluidSynth - A Software Synthesizer
2 *
3 * Copyright (C) 2003  Peter Hanappe and others.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * as published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 * 02111-1307, USA
19 */
20
21/* Author: Markus Nentwig, nentwig@users.sourceforge.net
22 */
23
24#ifndef _FLUID_MIDIROUTER_H
25#define _FLUID_MIDIROUTER_H
26
27#include "fluidsynth_priv.h"
28#include "fluid_midi.h"
29#include "fluid_sys.h"
30
31
32
33void fluid_midi_router_destroy_all_rules(fluid_midi_router_t* router);
34fluid_midi_router_rule_t* new_fluid_midi_router_rule(void);
35
36int fluid_midi_router_handle_clear(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
37int fluid_midi_router_handle_default(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
38int fluid_midi_router_handle_begin(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
39int fluid_midi_router_handle_chan(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
40int fluid_midi_router_handle_par1(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
41int fluid_midi_router_handle_par2(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
42int fluid_midi_router_handle_end(fluid_synth_t* synth, int ac, char** av, fluid_ostream_t out);
43
44int fluid_midi_router_begin(fluid_midi_router_t* router, fluid_midi_router_rule_t** dest);
45int fluid_midi_router_end(fluid_midi_router_t* router);
46int fluid_midi_router_create_default_rules(fluid_midi_router_t* router);
47void fluid_midi_router_disable_all_rules(fluid_midi_router_t* router);
48void fluid_midi_router_free_unused_rules(fluid_midi_router_t* router);
49
50/*
51 * fluid_midi_router
52 */
53struct _fluid_midi_router_t {
54  fluid_synth_t* synth;
55
56  fluid_midi_router_rule_t* note_rules;
57  fluid_midi_router_rule_t* cc_rules;
58  fluid_midi_router_rule_t* progchange_rules;
59  fluid_midi_router_rule_t* pitchbend_rules;
60  fluid_midi_router_rule_t* channel_pressure_rules;
61  fluid_midi_router_rule_t* key_pressure_rules;
62
63  int new_rule_chan_min;
64  int new_rule_chan_max;
65  double new_rule_chan_mul;
66  int new_rule_chan_add;
67  int new_rule_par1_min;
68  int new_rule_par1_max;
69  double new_rule_par1_mul;
70  int new_rule_par1_add;
71  int new_rule_par2_min;
72  int new_rule_par2_max;
73  double new_rule_par2_mul;
74  int new_rule_par2_add;
75
76  fluid_midi_router_rule_t** dest;
77
78  handle_midi_event_func_t event_handler;    /* Callback function for generated events */
79  void* event_handler_data;                  /* One arg for the callback */
80
81  int nr_midi_channels;                      /* For clipping the midi channel */
82  fluid_mutex_t ruletables_mutex;
83};
84
85struct _fluid_midi_router_rule_t {
86    int chan_min;                             /* Channel window, for which this rule is valid */
87    int chan_max;
88    fluid_real_t chan_mul;                     /* Channel multiplier (usually 0 or 1) */
89    int chan_add;                             /* Channel offset */
90
91    int par1_min;                             /* Parameter 1 window, for which this rule is valid */
92    int par1_max;
93    fluid_real_t par1_mul;
94    int par1_add;
95
96    int par2_min;                              /* Parameter 2 window, for which this rule is valid */
97    int par2_max;
98    fluid_real_t par2_mul;
99    int par2_add;
100
101    int pending_events;                        /* In case of noteon: How many keys are still down? */
102    char keys_cc[128];                         /* Flags, whether a key is down / controller is set (sustain) */
103    fluid_midi_router_rule_t* next;             /* next entry */
104    int state;                                 /* Does this rule expire, as soon as (for example) all keys are up? */
105};
106
107enum fluid_midirule_state {
108    MIDIRULE_ACTIVE = 0x00,
109    MIDIRULE_WAITING,
110    MIDIRULE_DONE
111};
112#endif
113