1 /* nekobee DSSI software synthesizer plugin
2  *
3  * Copyright (C) 2004 Sean Bolton and others.
4  *
5  * Portions of this file may have come from Peter Hanappe's
6  * Fluidsynth, copyright (C) 2003 Peter Hanappe and others.
7  * Portions of this file may have come from alsa-lib, copyright
8  * and licensed under the LGPL v2.1.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be
16  * useful, but WITHOUT ANY WARRANTY; without even the implied
17  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  * PURPOSE.  See the GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public
21  * License along with this program; if not, write to the Free
22  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 #ifndef _XSYNTH_SYNTH_H
27 #define _XSYNTH_SYNTH_H
28 
29 #include <pthread.h>
30 
31 #include "nekobee.h"
32 #include "nekobee_types.h"
33 
34 #define XSYNTH_MONO_MODE_OFF  0
35 #define XSYNTH_MONO_MODE_ON   1
36 #define XSYNTH_MONO_MODE_ONCE 2
37 #define XSYNTH_MONO_MODE_BOTH 3
38 
39 #define XSYNTH_GLIDE_MODE_LEGATO   0
40 #define XSYNTH_GLIDE_MODE_INITIAL  1
41 #define XSYNTH_GLIDE_MODE_ALWAYS   2
42 #define XSYNTH_GLIDE_MODE_LEFTOVER 3
43 #define XSYNTH_GLIDE_MODE_OFF      4
44 
45 /*
46  * nekobee_synth_t
47  */
48 struct _nekobee_synth_t {
49     /* output */
50     unsigned long   sample_rate;
51     float           deltat;            /* 1 / sample_rate */
52     unsigned long   nugget_remains;
53 
54     /* voice tracking and data */
55     unsigned int    note_id;           /* incremented for every new note, used for voice-stealing prioritization */
56     int             polyphony;         /* requested polyphony, must be <= XSYNTH_MAX_POLYPHONY */
57     int             voices;            /* current polyphony, either requested polyphony above or 1 while in monophonic mode */
58     int             monophonic;        /* true if operating in monophonic mode */
59     int             glide;             /* current glide mode */
60     float           last_noteon_pitch; /* glide start pitch for non-legato modes */
61     signed char     held_keys[8];      /* for monophonic key tracking, an array of note-ons, most recently received first */
62     float           vcf_accent;        /* used to emulate the circuit that sweeps the vcf at full resonance */
63     float           vca_accent;        /* used to smooth the accent pulse, removing the click */
64 
65     //nekobee_voice_t *voice[XSYNTH_MAX_POLYPHONY];
66     nekobee_voice_t *voice;
67     pthread_mutex_t voicelist_mutex;
68     int             voicelist_mutex_grab_failed;
69 
70     /* current non-paramter-mapped controller values */
71     unsigned char   key_pressure[128];
72     unsigned char   cc[128];                  /* controller values */
73     unsigned char   channel_pressure;
74     unsigned char   pitch_wheel_sensitivity;  /* in semitones */
75     int             pitch_wheel;              /* range is -8192 - 8191 */
76 
77     /* translated controller values */
78     float           mod_wheel;                /* filter cutoff multiplier, off = 1.0, full on = 0.0 */
79     float           pitch_bend;               /* frequency multiplier, product of wheel setting and sensitivity, center = 1.0 */
80     float           cc_volume;                /* volume multiplier, 0.0 to 1.0 */
81 
82     /* patch parameters */
83     float          tuning;
84     float          waveform;
85     float          cutoff;
86     float          resonance;
87     float          envmod;
88     float          decay;
89     float          accent;
90     float          volume;
91 };
92 
93 void nekobee_synth_all_voices_off(nekobee_synth_t *synth);
94 void nekobee_synth_note_off(nekobee_synth_t *synth, unsigned char key,
95                             unsigned char rvelocity);
96 void nekobee_synth_all_notes_off(nekobee_synth_t *synth);
97 void nekobee_synth_note_on(nekobee_synth_t *synth, unsigned char key,
98                            unsigned char velocity);
99 void nekobee_synth_control_change(nekobee_synth_t *synth, unsigned int param,
100                                   signed int value);
101 void nekobee_synth_init_controls(nekobee_synth_t *synth);
102 void nekobee_synth_render_voices(nekobee_synth_t *synth, float *out,
103                                  unsigned long sample_count,
104                                  int do_control_update);
105 
106 /* these come right out of alsa/asoundef.h */
107 #define MIDI_CTL_MSB_MODWHEEL           0x01    /**< Modulation */
108 #define MIDI_CTL_MSB_PORTAMENTO_TIME    0x05    /**< Portamento time */
109 #define MIDI_CTL_MSB_MAIN_VOLUME        0x07    /**< Main volume */
110 #define MIDI_CTL_MSB_BALANCE            0x08    /**< Balance */
111 #define MIDI_CTL_LSB_MODWHEEL           0x21    /**< Modulation */
112 #define MIDI_CTL_LSB_PORTAMENTO_TIME    0x25    /**< Portamento time */
113 #define MIDI_CTL_LSB_MAIN_VOLUME        0x27    /**< Main volume */
114 #define MIDI_CTL_LSB_BALANCE            0x28    /**< Balance */
115 #define MIDI_CTL_SUSTAIN                0x40    /**< Sustain pedal */
116 
117 // nekobee defines
118 #define MIDI_CTL_TUNING                 0x4b    // impossible
119 #define MIDI_CTL_WAVEFORM               0x46    // select waveform
120 #define MIDI_CTL_CUTOFF                 0x4a    // VCF Cutoff
121 #define MIDI_CTL_RESONANCE              0x47    // VCF Resonance
122 #define MIDI_CTL_ENVMOD                 0x01    // cheat and use modwheel
123 #define MIDI_CTL_DECAY                  0x48    // Decay time (well release really)
124 #define MIDI_CTL_ACCENT                 0x4c    // impossible
125 
126 #define MIDI_CTL_ALL_SOUNDS_OFF         0x78    /**< All sounds off */
127 #define MIDI_CTL_RESET_CONTROLLERS      0x79    /**< Reset Controllers */
128 #define MIDI_CTL_ALL_NOTES_OFF          0x7b    /**< All notes off */
129 
130 #define XSYNTH_SYNTH_SUSTAINED(_s)  ((_s)->cc[MIDI_CTL_SUSTAIN] >= 64)
131 
132 #endif /* _XSYNTH_SYNTH_H */
133