Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
bsemidievent.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_MIDI_EVENT_H__
3 #define __BSE_MIDI_EVENT_H__
4 
5 #include <bse/bseobject.hh>
6 
7 /* --- MIDI constants --- */
8 #define BSE_MIDI_MAX_CHANNELS (99)
9 
10 
11 /* --- MIDI event types --- */
12 #define BSE_MIDI_CHANNEL_VOICE_MESSAGE(s) ((s) < 0x0F0)
13 #define BSE_MIDI_SYSTEM_COMMON_MESSAGE(s) (((s) & 0x0F8) == 0x0F0)
14 #define BSE_MIDI_SYSTEM_REALTIME_MESSAGE(s) (((s) & 0x0F8) == 0x0F8)
15 typedef enum
16 {
17  /* channel voice messages */
18  BSE_MIDI_NOTE_OFF = 0x080, /* 7bit note, 7bit velocity */
19  BSE_MIDI_NOTE_ON = 0x090, /* 7bit note, 7bit velocity */
20  BSE_MIDI_KEY_PRESSURE = 0x0A0, /* 7bit note, 7bit intensity */
21  BSE_MIDI_CONTROL_CHANGE = 0x0B0, /* 7bit ctl-nr, 7bit value */
22  BSE_MIDI_PROGRAM_CHANGE = 0x0C0, /* 7bit prg-nr */
23  BSE_MIDI_CHANNEL_PRESSURE = 0x0D0, /* 7bit intensity */
24  BSE_MIDI_PITCH_BEND = 0x0E0, /* 14bit signed: 7lsb, 7msb */
25  /* system common messages */
26  BSE_MIDI_SYS_EX = 0x0F0, /* data... (without final 0x7F) */
27  BSE_MIDI_SONG_POINTER = 0x0F2, /* 14bit pointer: 7lsb, 7msb */
28  BSE_MIDI_SONG_SELECT = 0x0F3, /* 7bit song-nr */
29  BSE_MIDI_TUNE = 0x0F6,
30  BSE_MIDI_END_EX = 0x0F7,
31  /* system realtime messages */
32  BSE_MIDI_TIMING_CLOCK = 0x0F8,
33  BSE_MIDI_SONG_START = 0x0FA,
34  BSE_MIDI_SONG_CONTINUE = 0x0FB,
35  BSE_MIDI_SONG_STOP = 0x0FC,
36  BSE_MIDI_ACTIVE_SENSING = 0x0FE,
37  BSE_MIDI_SYSTEM_RESET = 0x0FF,
38  /* midi file meta events */
39  BSE_MIDI_SEQUENCE_NUMBER = 0x100, /* 16bit sequence number (msb, lsb) */
40  BSE_MIDI_TEXT_EVENT = 0x101, /* 8bit text */
41  BSE_MIDI_COPYRIGHT_NOTICE = 0x102, /* 8bit text */
42  BSE_MIDI_TRACK_NAME = 0x103, /* 8bit text */
43  BSE_MIDI_INSTRUMENT_NAME = 0x104, /* 8bit text */
44  BSE_MIDI_LYRIC = 0x105, /* 8bit text */
45  BSE_MIDI_MARKER = 0x106, /* 8bit text */
46  BSE_MIDI_CUE_POINT = 0x107, /* 8bit text */
47  BSE_MIDI_TEXT_EVENT_08 = 0x108, /* 8bit text */
48  BSE_MIDI_TEXT_EVENT_09 = 0x109, /* 8bit text */
49  BSE_MIDI_TEXT_EVENT_0A = 0x10A, /* 8bit text */
50  BSE_MIDI_TEXT_EVENT_0B = 0x10B, /* 8bit text */
51  BSE_MIDI_TEXT_EVENT_0C = 0x10C, /* 8bit text */
52  BSE_MIDI_TEXT_EVENT_0D = 0x10D, /* 8bit text */
53  BSE_MIDI_TEXT_EVENT_0E = 0x10E, /* 8bit text */
54  BSE_MIDI_TEXT_EVENT_0F = 0x10F, /* 8bit text */
55  BSE_MIDI_CHANNEL_PREFIX = 0x120, /* 8bit channel number (0..15) */
56  BSE_MIDI_END_OF_TRACK = 0x12F,
57  BSE_MIDI_SET_TEMPO = 0x151, /* 24bit usecs-per-quarter-note (msb first) */
58  BSE_MIDI_SMPTE_OFFSET = 0x154, /* 8bit hour, minute, second, frame, 100th-frame-fraction */
59  BSE_MIDI_TIME_SIGNATURE = 0x158, /* 8bit numerator, -ld(1/denominator), metro-clocks, 32nd-npq */
60  BSE_MIDI_KEY_SIGNATURE = 0x159, /* 8bit sharpsflats, majorminor */
61  BSE_MIDI_SEQUENCER_SPECIFIC = 0x17F, /* manufacturer specific sequencing data */
62  /* implementation specific add-ons */
63  BSE_MIDI_MULTI_SYS_EX_START = 0x201, /* BSE_MIDI_SYS_EX split across multiple events */
64  BSE_MIDI_MULTI_SYS_EX_NEXT = 0x202, /* continuation, last data byte of final packet is 0xF7 */
65  /* BSE specific extra events */
66  BSE_MIDI_X_CONTINUOUS_CHANGE = 0x400
67 } BseMidiEventType;
68 
69 
70 /* --- BSE MIDI Event --- */
71 #define BSE_TYPE_MIDI_EVENT (bse_midi_event_get_type ())
72 typedef struct
73 {
74  BseMidiEventType status;
75  guint channel; /* 1 .. 16 for standard events */
76  guint64 delta_time; /* GSL tick stamp, SMF tpqn or SMTPE */
77  union {
78  struct {
79  gfloat frequency;
80  gfloat velocity; /* or intensity: 0..+1 */
81  } note;
82  struct {
83  guint control; /* 0..0x7f */
84  gfloat value; /* -1..+1 */
85  } control;
86  guint program; /* 0..0x7f */
87  gfloat intensity; /* 0..+1 */
88  gfloat pitch_bend; /* -1..+1 */
89  guint song_pointer; /* 0..0x3fff */
90  guint song_number; /* 0..0x7f */
91  /* meta event data */
92  struct {
93  guint8 *bytes;
94  guint n_bytes;
95  } sys_ex; /* sys-ex variants and sequencer-specific */
96  guint sequence_number; /* 0..0xffff */
97  gchar *text;
98  guint usecs_pqn; /* micro seconds per quarter note */
99  struct {
100  guint8 hour, minute, second;
101  guint8 frame, fraction; /* fraction is always 100th of a frame */
102  } smpte_offset;
103  struct {
104  guint denominator;
105  guint8 numerator;
106  guint8 metro_clocks; /* # MIDI clocks in a metronome click */
107  guint8 notated_32nd; /* # of notated 32nd notes per quarter note */
108  } time_signature;
109  struct {
110  guint16 n_flats; /* there's not n_sharps and n_flats at the same time */
111  guint16 n_sharps;
112  guint major_key : 1; /* dur */
113  guint minor_key : 1; /* moll */
114  } key_signature;
115  /* implementation specific */
116  guint zprefix;
117  } data;
118 } BseMidiEvent;
119 
120 
121 /* --- API --- */
122 GType bse_midi_event_get_type (void); /* boxed */
123 BseMidiEvent* bse_midi_alloc_event (void);
124 BseMidiEvent* bse_midi_copy_event (const BseMidiEvent *src);
125 void bse_midi_free_event (BseMidiEvent *event);
126 BseMidiEvent* bse_midi_event_note_on (uint midi_channel,
127  Bse::uint64 delta_time,
128  float frequency,
129  float velocity);
130 BseMidiEvent* bse_midi_event_note_off (uint midi_channel,
131  Bse::uint64 delta_time,
132  gfloat frequency);
133 BseMidiEvent* bse_midi_event_signal (uint midi_channel,
134  Bse::uint64 delta_time,
135  Bse::MidiSignal signal_type,
136  float value);
137 double bse_midi_signal_default (Bse::MidiSignal signal);
138 const char* bse_midi_signal_name (Bse::MidiSignal signal);
139 
140 #endif /* __BSE_MIDI_EVENT_H__ */
void bse_midi_free_event(BseMidiEvent *event)
Definition: bsemidievent.cc:66
signal
double bse_midi_signal_default(Bse::MidiSignal signal)
Definition: bsemidievent.cc:20
uint64_t uint64
Definition: bsemidievent.hh:72