1 /*
2  * BW_Midi_Sequencer - MIDI Sequencer for C++
3  *
4  * Copyright (c) 2015-2018 Vitaly Novichkov <admin@wohlnet.ru>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 #ifndef BISQUIT_AND_WOHLSTANDS_MIDI_SEQUENCER_HHHH
27 #define BISQUIT_AND_WOHLSTANDS_MIDI_SEQUENCER_HHHH
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 /**
37   \brief Real-Time MIDI interface between Sequencer and the Synthesizer
38  */
39 typedef struct
40 {
41     /*! Raw MIDI event hook */
42     typedef void (*RawEventHook)(void *userdata, uint8_t type, uint8_t subtype, uint8_t channel, const uint8_t *data, size_t len);
43     /*! MIDI event hook which catches all MIDI events */
44     RawEventHook onEvent;
45     /*! User data which will be passed through On-Event hook */
46     void         *onEvent_userData;
47 
48     /*! Library internal debug messages */
49     typedef void (*DebugMessageHook)(void *userdata, const char *fmt, ...);
50     /*! Debug message hook */
51     DebugMessageHook onDebugMessage;
52     /*! User data which will be passed through Debug Message hook */
53     void *onDebugMessage_userData;
54 
55     /*! MIDI Run Time event calls user data */
56     void *rtUserData;
57 
58 
59     /***************************************************
60      * Standard MIDI events. All of them are required! *
61      ***************************************************/
62 
63     /*! Note-On MIDI event */
64     typedef void (*RtNoteOn)(void *userdata, uint8_t channel, uint8_t note, uint8_t velocity);
65     /*! Note-On MIDI event hook */
66     RtNoteOn            rt_noteOn;
67 
68     /*! Note-Off MIDI event */
69     typedef void (*RtNoteOff)(void *userdata, uint8_t channel, uint8_t note);
70     /*! Note-Off MIDI event hook */
71     RtNoteOff           rt_noteOff;
72 
73     /*! Note aftertouch MIDI event */
74     typedef void (*RtNoteAfterTouch)(void *userdata, uint8_t channel, uint8_t note, uint8_t atVal);
75     /*! Note aftertouch MIDI event hook */
76     RtNoteAfterTouch    rt_noteAfterTouch;
77 
78     /*! Channel aftertouch MIDI event */
79     typedef void (*RtChannelAfterTouch)(void *userdata, uint8_t channel, uint8_t atVal);
80     /*! Channel aftertouch MIDI event hook */
81     RtChannelAfterTouch rt_channelAfterTouch;
82 
83     /*! Controller change MIDI event */
84     typedef void (*RtControlerChange)(void *userdata, uint8_t channel, uint8_t type, uint8_t value);
85     /*! Controller change MIDI event hook */
86     RtControlerChange   rt_controllerChange;
87 
88     /*! Patch change MIDI event */
89     typedef void (*RtPatchChange)(void *userdata, uint8_t channel, uint8_t patch);
90     /*! Patch change MIDI event hook */
91     RtPatchChange       rt_patchChange;
92 
93     /*! Pitch bend MIDI event */
94     typedef void (*RtPitchBend)(void *userdata, uint8_t channel, uint8_t msb, uint8_t lsb);
95     /*! Pitch bend MIDI event hook */
96     RtPitchBend         rt_pitchBend;
97 
98     /*! System Exclusive MIDI event */
99     typedef void (*RtSysEx)(void *userdata, const uint8_t *msg, size_t size);
100     /*! System Exclusive MIDI event hook */
101     RtSysEx             rt_systemExclusive;
102 
103 
104     /*******************
105      * Optional events *
106      *******************/
107 
108     /*! Device Switch MIDI event */
109     typedef void (*RtDeviceSwitch)(void *userdata, size_t track, const char *data, size_t length);
110     /*! Device Switch MIDI event hook */
111     RtDeviceSwitch      rt_deviceSwitch;
112 
113     /*! Get the channels offset for current MIDI device */
114     typedef size_t (*RtCurrentDevice)(void *userdata, size_t track);
115     /*! Get the channels offset for current MIDI device hook. Returms multiple to 16 value. */
116     RtCurrentDevice     rt_currentDevice;
117 
118 
119     /******************************************
120      * NonStandard events. There are optional *
121      ******************************************/
122 
123     /*! [Non-Standard] Pass raw OPL3 data to the chip (when playing IMF files) */
124     typedef void (*RtRawOPL)(void *userdata, uint8_t reg, uint8_t value);
125     /*! [Non-Standard] Pass raw OPL3 data to the chip hook */
126     RtRawOPL            rt_rawOPL;
127 
128 } BW_MidiRtInterface;
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* BISQUIT_AND_WOHLSTANDS_MIDI_SEQUENCER_HHHH */
135