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