Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
midiPlayer.h
Go to the documentation of this file.
1#pragma once
2
55
56//==============================================================================
57// Includes
58//==============================================================================
59
60#include "swSynth.h"
61#include "midiFileParser.h"
62#include "cnfs_image.h"
63
64#include <stdint.h>
65#include <stdbool.h>
66#include <stddef.h>
67
68//==============================================================================
69// Defines
70//==============================================================================
71
72#define MIDI_CHANNEL_COUNT 16
73// The total number of pooled voices
74#define POOL_VOICE_COUNT 24
75// The number of voices reserved for percussion
76#define PERCUSSION_VOICES 16
77// The number of global MIDI players
78#define NUM_GLOBAL_PLAYERS 2
79// The index of the system-wide MIDI player for sound effects
80#define MIDI_SFX 0
81// The index of the system-wide MIDI player for background music
82#define MIDI_BGM 1
83// The maximum volume setting for globalMidiPlayerSetVolume()
84#define MAX_VOLUME 13
85
86#define MIDI_TRUE 0x7F
87#define MIDI_FALSE 0x00
88#define MIDI_TO_BOOL(val) (val > 63)
89#define BOOL_TO_MIDI(val) (val ? MIDI_TRUE : MIDI_FALSE)
90#define MIDI_DEF_HEADROOM 0x4000
91#define PITCH_BEND_CENTER 0x2000
92
94#define SAMPLES_TO_MIDI_TICKS(n, tempo, div) ((int64_t)(n) * 1000000 * (div) / DAC_SAMPLE_RATE_HZ / (tempo))
95
96#define SAMPLES_PER_TICK(tempo, div) ((uint64_t)DAC_SAMPLE_RATE_HZ * (tempo) / div / 1000000)
97
99#define TICKS_TO_SAMPLES(ticks, tempo, div) ((int64_t)(ticks) * DAC_SAMPLE_RATE_HZ / (1000000) * (tempo) / (div))
100
102#define SAMPLES_TO_MS(samp) (((samp) * 1000) / DAC_SAMPLE_RATE_HZ)
103
105#define SAMPLES_TO_US(samp) (((samp) * 1000000) / DAC_SAMPLE_RATE_HZ)
106
108#define MS_TO_SAMPLES(ms) ((ms) * DAC_SAMPLE_RATE_HZ / 1000)
109
111#define MIDI_TICKS_TO_US(ticks, tempo, div) (int64_t)((int64_t)((int64_t)(ticks) * (int64_t)(tempo)) / ((int64_t)(div)))
112
114typedef void (*songFinishedCbFn)(void);
115
116//==============================================================================
117// Enums
118//==============================================================================
119
132
146
150typedef enum
151{
159
169
189
193typedef enum
194{
195 // Roland GS Extensions
196 /*HIGH_Q_OR_FILTER_SNAP = 27,
197 SLAP_NOISE = 28,
198 SCRATCH_PUSH = 29,
199 SCRATCH_PULL = 30,
200 DRUM_STICKS = 31,
201 SQUARE_CLICK = 32,
202 METRONOME_CLICK = 33,
203 METRONOME_BELL = 34,*/
204 // End Roland GS Extensions
242 CABASA = 69,
252 CLAVES = 75,
263 // Roland GS Extensions
264 /*SHAKER = 82,
265 JINGLE_BELL = 83,
266 BELLTREE = 84,
267 CASTANETS = 85,
268 MUTE_SURDO = 86,
269 OPEN_SURDO = 87,*/
270 // End Roland GS Extensions
272
282typedef enum
283{
287
293
298
303
307
313
318
319 //< Switch
321 //< Switch
323 //< Switch
325 //< Switch
327 //< Switch
329 //< Switch
336 // Decay
338 // Sustain level
343 //< Switch
345 //< Switch
347 //< Switch
349 //< Switch
351
363
364 //< No data
366 //< No data
368 //< Switch
370 //< No data
372 //< No data
374 //< No data
376 //< No data
378 //< No data
381
391
392//==============================================================================
393// Structs
394//==============================================================================
395
400typedef struct
401{
403 int32_t attackTime;
404
407
409 int32_t decayTime;
410
413
415 int32_t releaseTime;
416
419
421 uint8_t sustainVol;
422
425
427 // uint32_t loopStart;
429 // uint32_t loopEnd;
430
431} envelope_t;
432
433typedef struct
434{
436 uint8_t chorus;
438
448typedef int8_t (*percussionFunc_t)(percussionNote_t drum, uint32_t idx, bool* done, uint32_t scratch[4], void* data);
449
457typedef void (*midiTextCallback_t)(metaEventType_t type, const char* text, uint32_t length);
458
463typedef bool (*midiStreamingCallback_t)(midiEvent_t* event);
464
469typedef struct
470{
472 cnfsFileIdx_t fIdx;
473
475 uint32_t rate;
476
479
481 int8_t tune;
482
484 uint32_t loop;
485
487 uint32_t loopStart;
488
490 uint32_t loopEnd;
492
500
504typedef struct
505{
508
511
512 union
513 {
514 struct
515 {
517 uint16_t waveIndex;
518
521 };
522
523 timbreSample_t sample;
524
525 struct
526 {
528 const noteSampleMap_t* map;
530 size_t count;
531 } multiSample;
532
533 struct
534 {
538 void* data;
539 } playFunc;
540
542 oscillatorShape_t shape;
543 };
544
547
550
552 const char* name;
554
560typedef struct
561{
564
567
570
572 uint32_t voiceTick;
573
575 uint32_t sampleTick;
576
579
582
584 uint8_t note;
585
587 uint8_t velocity;
588
591 uint8_t channel;
592
595
596 union
597 {
598 struct
599 {
601 const uint8_t* data;
603 uint32_t length;
604
606 uint32_t rate;
607
609 uint32_t loopStart;
611 uint32_t loopEnd;
612
615
617 int8_t tune;
618
621
623 uint32_t loopsRemaining;
624
627 } sample;
628
629 struct
630 {
633 } wave;
634
635 struct
636 {
638 uint32_t scratch[4];
639 } playFunc;
640 };
641
645
651typedef struct
652{
654 uint32_t on;
655
657 uint32_t attack;
658
660 uint32_t sustain;
661
663 uint32_t decay;
664
666 uint32_t release;
667
669 uint32_t held;
670
672 uint32_t sustenuto;
674
678typedef struct
679{
681 uint16_t volume;
682
684 uint16_t bank;
685
687 uint8_t program;
688
691
694
697
700
702 uint16_t pitchBend;
703
706
708 bool held;
709
712
714 bool ignore;
716
805
811void midiPlayerInit(midiPlayer_t* player);
812
818void midiPlayerReset(midiPlayer_t* player);
819
827
834int32_t midiPlayerStep(midiPlayer_t* player);
835
844void midiPlayerFillBuffer(midiPlayer_t* player, uint8_t* samples, int16_t len);
845
854void midiPlayerFillBufferMulti(midiPlayer_t* players, uint8_t playerCount, uint8_t* samples, int16_t len);
855
861void midiAllSoundOff(midiPlayer_t* player);
862
873void midiResetChannelControllers(midiPlayer_t* player, uint8_t channel);
874
880void midiGmOn(midiPlayer_t* player);
881
887void midiGmOff(midiPlayer_t* player);
888
896void midiAllNotesOff(midiPlayer_t* player, uint8_t channel);
897
908void midiNoteOn(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
909
918void midiAfterTouch(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
919
928void midiNoteOff(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
929
937void midiSetProgram(midiPlayer_t* player, uint8_t channel, uint8_t program);
938
951void midiSustain(midiPlayer_t* player, uint8_t channel, uint8_t val);
952
963void midiSustenuto(midiPlayer_t* player, uint8_t channel, uint8_t val);
964
973void midiControlChange(midiPlayer_t* player, uint8_t channel, midiControl_t control, uint8_t val);
974
983uint8_t midiGetControlValue(midiPlayer_t* player, uint8_t channel, midiControl_t control);
984
993uint16_t midiGetControlValue14bit(midiPlayer_t* player, uint8_t channel, midiControl_t control);
994
1004void midiSetParameter(midiPlayer_t* player, uint8_t channel, bool registered, uint16_t param, uint16_t value);
1005
1016uint16_t midiGetParameterValue(midiPlayer_t* player, uint8_t channel, bool registered, uint16_t param);
1017
1031void midiPitchWheel(midiPlayer_t* player, uint8_t channel, uint16_t value);
1032
1039void midiSetTempo(midiPlayer_t* player, uint32_t tempo);
1040
1047void midiSetFile(midiPlayer_t* player, const midiFile_t* file);
1048
1055void midiPause(midiPlayer_t* player, bool pause);
1056
1068void midiSeek(midiPlayer_t* player, uint32_t ticks);
1069
1070//==============================================================================
1071// Global MIDI Player Functions
1072//==============================================================================
1073
1077void initGlobalMidiPlayer(void);
1078
1083void deinitGlobalMidiPlayer(void);
1084
1092void globalMidiPlayerFillBuffer(uint8_t* samples, int16_t len);
1093
1100void globalMidiPlayerPlaySong(midiFile_t* song, uint8_t trackType);
1101
1109void globalMidiPlayerPlaySongCb(midiFile_t* song, uint8_t trackType, songFinishedCbFn cb);
1110
1117void globalMidiPlayerSetVolume(uint8_t trackType, int32_t volumeSetting);
1118
1123void globalMidiPlayerPauseAll(void);
1124
1129void globalMidiPlayerResumeAll(void);
1130
1137void globalMidiPlayerStop(bool reset);
1138
1145void* globalMidiSave(void);
1146
1153void globalMidiRestore(void* data);
1154
1162midiPlayer_t* globalMidiPlayerGet(uint8_t trackType);
uint32_t uq24_8
unsigned 24 bits integer, 8 bits fraction
Definition fp_math.h:41
uint32_t uq8_24
unsigned 8 bits integer, 24 bits fraction
Definition fp_math.h:43
int32_t q24_8
24 bits integer, 8 bits fraction
Definition fp_math.h:36
int32_t q8_24
8 bits integer, 24 bits fraction
Definition fp_math.h:38
uint32_t uq16_16
unsigned 16 bits integer, 16 bits fraction
Definition fp_math.h:42
metaEventType_t
The possible types of meta-events.
Definition midiFileParser.h:34
Contains information for an entire MIDI event or non-MIDI meta-event.
Definition midiFileParser.h:236
Definition midiFileParser.h:110
Contains information which applies to the entire MIDI file.
Definition midiFileParser.h:87
int32_t releaseTime
Base time it takes to silence the note after release, in DAC samples.
Definition midiPlayer.h:415
uint32_t loopStart
The start of the loop portion of the sample.
Definition midiPlayer.h:487
void midiNoteOn(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Begin playing a note on a given MIDI channel.
Definition midiPlayer.c:1795
q8_24 volRate
Rate-of-change of the volume per tick, can be positive or negative.
Definition midiPlayer.h:566
uint16_t midiGetControlValue14bit(midiPlayer_t *player, uint8_t channel, midiControl_t control)
Get the combined value of two MIDI control registers.
Definition midiPlayer.c:2493
uint32_t loop
0 to loop forever, or the number of loops to play
Definition midiPlayer.h:484
midiEvent_t pendingEvent
The next event in the MIDI file, which occurs after the current time.
Definition midiPlayer.h:779
bool paused
True when playback of the current file is paused.
Definition midiPlayer.h:791
q24_8 sustainVolVel
This value will be multiplied by the note velocity and added to the attack time.
Definition midiPlayer.h:424
void midiSustain(midiPlayer_t *player, uint8_t channel, uint8_t val)
Set the hold pedal status.
Definition midiPlayer.c:2183
uint32_t stateChangeTick
The next tick at which state will change.
Definition midiPlayer.h:578
void globalMidiRestore(void *data)
Resume MIDI playback from the state stored in the given pointer. The data will be freed after this ca...
Definition midiFileParser.c:1075
void midiResetChannelControllers(midiPlayer_t *player, uint8_t channel)
Reset all controllers on a MIDI channel.
Definition midiPlayer.c:1694
const noteSampleMap_t * map
A map of different samples to use.
bool registeredParameter
Whether selectedParameter represents a registered or non-registered parameter.
Definition midiPlayer.h:690
bool songEnding
If true, all events from the current song have been read and we are waiting for notes to end.
Definition midiPlayer.h:800
timbreType_t
The sample source for an instrument.
Definition midiPlayer.h:137
@ PLAY_FUNC
Definition midiPlayer.h:144
@ SAMPLE
Definition midiPlayer.h:140
@ WAVETABLE
Samples are generated by sampling a particular wave shape.
Definition midiPlayer.h:139
@ WAVE_SHAPE
Definition midiPlayer.h:142
@ MULTI_SAMPLE
Definition midiPlayer.h:143
@ NOISE
Definition midiPlayer.h:141
uint32_t tick
The current MIDI tick.
Definition midiPlayer.h:776
q24_8 releaseTimeVel
This value will be multiplied by the note velocity and added to the attack time.
Definition midiPlayer.h:418
envelope_t envelope
Definition midiPlayer.h:498
void midiGmOn(midiPlayer_t *player)
Activate General MIDI mode on a MIDI player.
Definition midiPlayer.c:1709
uint32_t tempo
The number of microseconds per quarter note.
Definition midiPlayer.h:785
void midiPlayerResetNewSong(midiPlayer_t *player)
Reset the MIDI player state by only doing the bare minimum. This is useful when playing multiple soun...
Definition midiPlayer.c:1464
uint32_t length
The number of samples in the data.
void globalMidiPlayerPlaySong(midiFile_t *song, uint8_t trackType)
Play a song on one of the system-wide MIDI players, either BGM or SFX.
Definition midiPlayer.c:2810
synthOscillator_t oscillator
uint32_t sustenuto
Bitfield of voices which are being held by the sustenuto pedal.
Definition midiPlayer.h:672
uint32_t held
Bitfield of voices which are being held by the pedal.
Definition midiPlayer.h:669
midiManufacturerId_t
Values that can be directly compared against midiSysexEvent_t::manufacturerId.
Definition midiPlayer.h:386
@ MMFR_EDUCATIONAL_USE
Definition midiPlayer.h:387
@ MMFR_UNIVERSAL_NON_REAL_TIME
Definition midiPlayer.h:388
@ MMFR_UNIVERSAL_REAL_TIME
Definition midiPlayer.h:389
int32_t midiPlayerStep(midiPlayer_t *player)
Calculate and return the next MIDI sample, stepping the player state forward by one sample.
Definition midiPlayer.c:1478
void midiAfterTouch(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Change the velocity of a note on a given MIDI channel, after the note starts playing.
Definition midiPlayer.c:2017
q8_24 volAccel
Acceleration of the volume per tick, which will be added to the rate.
Definition midiPlayer.h:569
voiceStates_t poolVoiceStates
The global voice pool state bitmaps.
Definition midiPlayer.h:745
void midiPlayerFillBuffer(midiPlayer_t *player, uint8_t *samples, int16_t len)
Fill a buffer with the next set of samples from the MIDI player. This should be called by the callbac...
Definition midiPlayer.c:1569
midiTimbre_t timbre
The actual current timbre definition which the program ID corresponds to.
Definition midiPlayer.h:696
waveFunc_t waveFunc
The function to use to retrieve wavetable samples.
int32_t attackTime
Base time taken to ramp up to full volume.
Definition midiPlayer.h:403
timbreSample_t sample
Definition midiPlayer.h:497
midiVoice_t percVoices[PERCUSSION_VOICES]
The voices reserved for percussion.
Definition midiPlayer.h:729
uq16_16 baseNote
The sample's base frequency.
voiceStates_t percVoiceStates
The percussion voice state bitmaps.
Definition midiPlayer.h:732
uint32_t loopStart
The sample number to return to after reaching the loop end.
uint32_t loopEnd
The end of the loop portion of the sample.
Definition midiPlayer.h:490
q24_8 attackTimeVel
This value will be multiplied by the note velocity and added to the attack time,.
Definition midiPlayer.h:406
timbreType_t type
The source of samples for this instrument.
Definition midiPlayer.h:507
uint32_t loopEnd
The sample number after which to return to the loop start.
void midiSetParameter(midiPlayer_t *player, uint8_t channel, bool registered, uint16_t param, uint16_t value)
Set a registered or non-registered parameter value.
Definition midiPlayer.c:2511
void midiSeek(midiPlayer_t *player, uint32_t ticks)
Seek to a given time offset within a file.
Definition midiPlayer.c:2673
voiceType_t
Enum which defines the method used to retrieve a sample from each voice.
Definition midiPlayer.h:164
@ VOICE_PLAY_FUNC
Definition midiPlayer.h:166
@ VOICE_WAVE_FUNC
Definition midiPlayer.h:165
@ VOICE_SAMPLE
Definition midiPlayer.h:167
void deinitGlobalMidiPlayer(void)
Deinitialize and free memory associated with the system-wide MIDI players.
Definition midiPlayer.c:2782
void globalMidiPlayerStop(bool reset)
Stop all songs currently being played by the system-wide MIDI players, optionally resetting their sta...
Definition midiPlayer.c:2876
bool held
Whether notes will be held after release.
Definition midiPlayer.h:708
uint32_t percSpecialStates
A bitmap to track which percussion voices have special notes playing This includes all 3 hi-hats (ope...
Definition midiPlayer.h:739
void midiSustenuto(midiPlayer_t *player, uint8_t channel, uint8_t val)
Set the sustenuto pedal status.
Definition midiPlayer.c:2230
uq16_16 pitch
The ultimate pitch of this voice after pitch bending, etc.
Definition midiPlayer.h:581
void midiSetProgram(midiPlayer_t *player, uint8_t channel, uint8_t program)
Change the program (instrument) on a given MIDI channel.
Definition midiPlayer.c:2166
uq24_8 sampleRateRatio
The pre-calculated samples-per-second.
bool loop
If true, the playing file will automatically repeat when complete.
Definition midiPlayer.h:797
adsrState_t
Enum representing specific ADSR states.
Definition midiPlayer.h:175
@ ADSR_ON
On, in which the note is on but doesn't have any specific ADSR states set (what?)
Definition midiPlayer.h:177
@ ADSR_RELEASE
Release, in which the volume falls from the sustain volume to 0 quadratically.
Definition midiPlayer.h:185
@ ADSR_OFF
Off, in which the note has finished playing completely.
Definition midiPlayer.h:187
@ ADSR_DECAY
Decay, in which the volume falls from the max volume to the sustain volume linearly.
Definition midiPlayer.h:181
@ ADSR_ATTACK
Attack, in which the volume rises from 0 to the max volume linearly.
Definition midiPlayer.h:179
@ ADSR_SUSTAIN
Sustain, in which the volume remains at the sustain volume.
Definition midiPlayer.h:183
bool sustenuto
Whether certain notes will be held after release.
Definition midiPlayer.h:711
midiFileReader_t reader
A MIDI reader to use for file playback, when in MIDI_FILE mode.
Definition midiPlayer.h:751
uint32_t rate
The number of samples per second of raw sample data.
uint8_t velocity
The MIDI note velocity of the playing note.
Definition midiPlayer.h:587
void midiPlayerInit(midiPlayer_t *player)
Initialize the MIDI player.
Definition midiPlayer.c:1429
uint8_t channel
The index of the MIDI channel that owns the currently playing note. If 255 or any other value >= 16,...
Definition midiPlayer.h:591
uint8_t sustainVol
The base volume of the sustained note, proportional to the sample volume.
Definition midiPlayer.h:421
uq8_24 curVol
The current volume as a fixed-point value.
Definition midiPlayer.h:563
void globalMidiPlayerResumeAll(void)
Resume all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2865
#define PERCUSSION_VOICES
Definition midiPlayer.h:76
int32_t headroom
The constant value to multiply each frame's samples by, before being shifted right 16 bits This value...
Definition midiPlayer.h:766
void globalMidiPlayerFillBuffer(uint8_t *samples, int16_t len)
Fill the given sample buffer with samples from both the BGM and SFX system-wide MIDI players.
Definition midiPlayer.c:2798
void midiPitchWheel(midiPlayer_t *player, uint8_t channel, uint16_t value)
Set the pitch wheel value on a given MIDI channel.
Definition midiPlayer.c:2599
uint32_t attack
Bitfield of voices currently in the attack stage.
Definition midiPlayer.h:657
void midiGmOff(midiPlayer_t *player)
Deactivate General MIDI mode on a MIDI player.
Definition midiPlayer.c:1725
uint8_t note
The MIDI note number for the sound being played.
Definition midiPlayer.h:584
int8_t tune
The sample's fine tuning.
percussionFunc_t func
A callback to call for drum data.
void midiNoteOff(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Stop playing a particular note on a given MIDI channel.
Definition midiPlayer.c:2102
#define POOL_VOICE_COUNT
Definition midiPlayer.h:74
uint32_t rate
The sample rate.
Definition midiPlayer.h:475
midiPlayerMode_t
Represents the source of MIDI data.
Definition midiPlayer.h:125
@ MIDI_STREAMING
Streaming over USB.
Definition midiPlayer.h:127
@ MIDI_FILE
Reading from a midiFileReader_t.
Definition midiPlayer.h:130
midiVoice_t poolVoices[POOL_VOICE_COUNT]
The global voice pool for non-percussion channels.
Definition midiPlayer.h:742
uint32_t decay
Bitfield of voices currently in the decay stage.
Definition midiPlayer.h:663
bool percussion
Whether this channel is reserved for percussion.
Definition midiPlayer.h:705
void globalMidiPlayerPauseAll(void)
Pause all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2854
int32_t decayTime
Base time taken for the volume to fade to the sustain volume.
Definition midiPlayer.h:409
uint32_t clipped
Number of samples that were clipped Note: This is not set when using midiPlayerFillBufferMulti()
Definition midiPlayer.h:770
void * data
User data to pass to the drumkit.
void midiAllSoundOff(midiPlayer_t *player)
Stop all sound immediately. This is not affected by the sustain pedal.
Definition midiPlayer.c:1638
const char * name
The name of this timbre, if any.
Definition midiPlayer.h:552
void(* midiTextCallback_t)(metaEventType_t type, const char *text, uint32_t length)
A function to handle text meta-messages from playing MIDI files.
Definition midiPlayer.h:457
#define MIDI_CHANNEL_COUNT
Definition midiPlayer.h:72
bool eventAvailable
True if pendingEvent is valid, false if it must be updated.
Definition midiPlayer.h:782
midiTextCallback_t textMessageCallback
A callback to call when a text meta-message is received.
Definition midiPlayer.h:757
uint32_t samplesPerTick
The number of audio samples per MIDI tick.
Definition midiPlayer.h:788
uint64_t sampleCount
The number of samples elapsed in the playing song.
Definition midiPlayer.h:773
q24_8 decayTimeVel
This value will be multiplied by the note velocity and added to the decay time.
Definition midiPlayer.h:412
uint32_t allocedVoices
A bitmap of which voices have been allocated to this channel.
Definition midiPlayer.h:699
uint16_t selectedParameter
The ID of the currently selected registered or non-registered parameter.
Definition midiPlayer.h:693
void midiAllNotesOff(midiPlayer_t *player, uint8_t channel)
Tun off all notes which are currently on, as though midiNoteOff() were called for each note....
Definition midiPlayer.c:1777
uint32_t release
Bitfield of voices currently in the release stage.
Definition midiPlayer.h:666
bool seeking
True when the MIDI player is seeking, and will not produce sound.
Definition midiPlayer.h:794
uint8_t midiGetControlValue(midiPlayer_t *player, uint8_t channel, midiControl_t control)
Get the value of a MIDI control.
Definition midiPlayer.c:2455
midiChannel_t channels[MIDI_CHANNEL_COUNT]
The state of all MIDI channels.
Definition midiPlayer.h:726
void globalMidiPlayerPlaySongCb(midiFile_t *song, uint8_t trackType, songFinishedCbFn cb)
Play a song on noe of the system-wide MIDI players, with a callback once the song finishes.
Definition midiPlayer.c:2824
uint16_t bank
The bank to use for program changes on this channel.
Definition midiPlayer.h:684
uint16_t waveIndex
The index of this timbre's wave in the table, when type is WAVETABLE.
uint8_t program
The ID of the program (timbre) set for this channel.
Definition midiPlayer.h:687
uint8_t noteEnd
Definition midiPlayer.h:496
uint32_t on
Whether this note is set to on via MIDI, regardless of if it's making sound.
Definition midiPlayer.h:654
void midiControlChange(midiPlayer_t *player, uint8_t channel, midiControl_t control, uint8_t val)
Set a MIDI control value.
Definition midiPlayer.c:2273
midiPlayerMode_t mode
Whether this player is playing a song or a MIDI stream.
Definition midiPlayer.h:748
uint16_t volume
The 14-bit volume level for this channel only.
Definition midiPlayer.h:681
uint8_t noteStart
Definition midiPlayer.h:495
void midiSetFile(midiPlayer_t *player, const midiFile_t *file)
Configure this MIDI player to read from a MIDI file.
Definition midiPlayer.c:2647
songFinishedCbFn songFinishedCallback
A callback to call when the playing song is finished.
Definition midiPlayer.h:760
void initGlobalMidiPlayer(void)
Initialize the system-wide MIDI players for both BGM and SFX.
Definition midiPlayer.c:2770
uq24_8 error
The number of fractional samples remaining.
bool forceCheckEvents
Force a check for MIDI events on the next sample.
Definition midiPlayer.h:803
timbreFlags_t flags
Flags bitfield for this timbre.
Definition midiPlayer.h:510
void midiPause(midiPlayer_t *player, bool pause)
Set the paused state of a MIDI song.
Definition midiPlayer.c:2668
midiControl_t
Defines the MIDI continuous controller registers.
Definition midiPlayer.h:283
@ MCC_GP_BUTTON_1
Definition midiPlayer.h:344
@ MCC_PAN_LSB
Definition midiPlayer.h:314
@ MCC_OMNI_MODE_ON
Definition midiPlayer.h:375
@ MCC_EFFECT_1_MSB
Definition midiPlayer.h:296
@ MCC_DETUNE_LEVEL
Definition midiPlayer.h:355
@ MCC_BREATH_LSB
Definition midiPlayer.h:306
@ MCC_BANK_LSB
Definition midiPlayer.h:304
@ MCC_MODULATION_WHEEL_MSB
Definition midiPlayer.h:285
@ MCC_PORTAMENTO
Definition midiPlayer.h:322
@ MCC_SOUND_CONTROL_10
Definition midiPlayer.h:342
@ MCC_GP_SLIDER_4
Definition midiPlayer.h:302
@ MCC_FOOT_PEDAL_MSB
Definition midiPlayer.h:288
@ MCC_BALANCE_MSB
Definition midiPlayer.h:292
@ MCC_LOCAL_KEYBOARD
Definition midiPlayer.h:369
@ MCC_FOOT_PEDAL_LSB
Definition midiPlayer.h:308
@ MCC_PAN_MSB
Definition midiPlayer.h:294
@ MCC_SOUND_CONTROL_7
Definition midiPlayer.h:339
@ MCC_REGISTERED_PARAM_MSB
Definition midiPlayer.h:362
@ MCC_VOLUME_LSB
Definition midiPlayer.h:311
@ MCC_OMNI_MODE_OFF
Definition midiPlayer.h:373
@ MCC_HOLD_PEDAL
Definition midiPlayer.h:320
@ MCC_GP_BUTTON_2
Definition midiPlayer.h:346
@ MCC_NON_REGISTERED_PARAM_MSB
Definition midiPlayer.h:360
@ MCC_GP_SLIDER_2
Definition midiPlayer.h:300
@ MCC_ALL_SOUND_OFF
Definition midiPlayer.h:365
@ MCC_HOLD_2_PEDAL
Definition midiPlayer.h:330
@ MCC_PORTAMENTO_TIME_MSB
Definition midiPlayer.h:289
@ MCC_DATA_BUTTON_DEC
Definition midiPlayer.h:358
@ MCC_LEGATO_PEDAL
Definition midiPlayer.h:328
@ MCC_PORTAMENTO_TIME_LSB
Definition midiPlayer.h:309
@ MCC_SOUND_CONTROL_8
Definition midiPlayer.h:340
@ MCC_EFFECT_2_LSB
Definition midiPlayer.h:317
@ MCC_DATA_ENTRY_LSB
Definition midiPlayer.h:310
@ MCC_VOLUME_MSB
Definition midiPlayer.h:291
@ MCC_DATA_BUTTON_INC
Definition midiPlayer.h:357
@ MCC_BREATH_MSB
Definition midiPlayer.h:286
@ MCC_EFFECT_2_MSB
Definition midiPlayer.h:297
@ MCC_SOFT_PEDAL
Definition midiPlayer.h:326
@ MCC_SOUND_VARIATION
Definition midiPlayer.h:331
@ MCC_PHASER_LEVEL
Definition midiPlayer.h:356
@ MCC_CHORUS_LEVEL
Definition midiPlayer.h:354
@ MCC_EFFECT_1_LSB
Definition midiPlayer.h:316
@ MCC_DATA_ENTRY_MSB
Definition midiPlayer.h:290
@ MCC_ALL_CONTROLS_OFF
Definition midiPlayer.h:367
@ MCC_BANK_MSB
Definition midiPlayer.h:284
@ MCC_BALANCE_LSB
Definition midiPlayer.h:312
@ MCC_EXPRESSION_LSB
Definition midiPlayer.h:315
@ MCC_GP_BUTTON_4
Definition midiPlayer.h:350
@ MCC_SOUND_BRIGHTNESS
Definition midiPlayer.h:335
@ MCC_SOUND_TIMBRE
Definition midiPlayer.h:332
@ MCC_SOUND_CONTROL_9
Definition midiPlayer.h:341
@ MCC_MODULATION_WHEEL_LSB
Definition midiPlayer.h:305
@ MCC_GP_SLIDER_3
Definition midiPlayer.h:301
@ MCC_SOUND_ATTACK_TIME
Definition midiPlayer.h:334
@ MCC_SOUND_RELEASE_TIME
Definition midiPlayer.h:333
@ MCC_REGISTERED_PARAM_LSB
Definition midiPlayer.h:361
@ MCC_NON_REGISTERED_PARAM_LSB
Definition midiPlayer.h:359
@ MCC_MONO_OPERATION
Definition midiPlayer.h:377
@ MCC_ALL_NOTE_OFF
Definition midiPlayer.h:371
@ MCC_TREMOLO_LEVEL
Definition midiPlayer.h:353
@ MCC_EFFECTS_LEVEL
Definition midiPlayer.h:352
@ MCC_SOUND_CONTROL_6
Definition midiPlayer.h:337
@ MCC_SUSTENUTO_PEDAL
Definition midiPlayer.h:324
@ MCC_POLY_OPERATION
Definition midiPlayer.h:379
@ MCC_EXPRESSION_MSB
Definition midiPlayer.h:295
@ MCC_GP_SLIDER_1
Definition midiPlayer.h:299
@ MCC_GP_BUTTON_3
Definition midiPlayer.h:348
uint32_t sampleTick
The non-monotonic tick counter for playback of sampled timbres.
Definition midiPlayer.h:575
uint16_t midiGetParameterValue(midiPlayer_t *player, uint8_t channel, bool registered, uint16_t param)
Get the value of a registered or non-registered parameter.
Definition midiPlayer.c:2572
cnfsFileIdx_t fIdx
The file index containing the sample data.
Definition midiPlayer.h:472
void(* songFinishedCbFn)(void)
Callback function used to provide feedback when a song finishes playing.
Definition midiPlayer.h:114
bool ignore
If set, events on this channel will be completely ignored.
Definition midiPlayer.h:714
uint32_t sustain
Bitfield of voices currently in the sustain stage.
Definition midiPlayer.h:660
percussionNote_t
Defines the MIDI note numbers mapped to by the General MIDI percussion note names.
Definition midiPlayer.h:194
@ OPEN_TRIANGLE
This note supersedes any MUTE_TRIANGLE or OPEN_TRIANGLE notes playing.
Definition midiPlayer.h:262
@ COWBELL
Definition midiPlayer.h:229
@ ACOUSTIC_SNARE
Definition midiPlayer.h:208
@ CLOSED_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:213
@ LOW_BONGO
Definition midiPlayer.h:234
@ HIGH_BONGO
Definition midiPlayer.h:233
@ CHINESE_CYMBAL
Definition midiPlayer.h:225
@ RIDE_CYMBAL_2
Definition midiPlayer.h:232
@ LONG_GUIRO
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:251
@ RIDE_BELL
Definition midiPlayer.h:226
@ SHORT_GUIRO
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:249
@ HIGH_TOM
Definition midiPlayer.h:223
@ MUTE_CUICA
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:256
@ CABASA
Definition midiPlayer.h:242
@ CRASH_CYMBAL_2
Definition midiPlayer.h:230
@ CRASH_CYMBAL_1
Definition midiPlayer.h:222
@ LOW_MID_TOM
Definition midiPlayer.h:220
@ LOW_AGOGO
Definition midiPlayer.h:241
@ HIGH_TIMBALE
Definition midiPlayer.h:238
@ SIDE_STICK
Definition midiPlayer.h:207
@ RIDE_CYMBAL_1
Definition midiPlayer.h:224
@ ELECTRIC_SNARE_OR_RIMSHOT
Definition midiPlayer.h:210
@ CLAVES
Definition midiPlayer.h:252
@ OPEN_HIGH_CONGA
Definition midiPlayer.h:236
@ LONG_WHISTLE
This note supersedes any SHORT_WHISTLE or LONG_WHISTLE notes playing.
Definition midiPlayer.h:247
@ LOW_TOM
Definition midiPlayer.h:217
@ HIGH_AGOGO
Definition midiPlayer.h:240
@ TAMBOURINE
Definition midiPlayer.h:227
@ HIGH_MID_TOM
Definition midiPlayer.h:221
@ MUTE_HIGH_CONGA
Definition midiPlayer.h:235
@ SPLASH_CYMBAL
Definition midiPlayer.h:228
@ HIGH_WOODBLOCK
Definition midiPlayer.h:253
@ LOW_FLOOR_TOM
Definition midiPlayer.h:211
@ VIBRASLAP
Definition midiPlayer.h:231
@ SHORT_WHISTLE
This note supersedes any SHORT_WHISTLE or LONG_WHISTLE notes playing.
Definition midiPlayer.h:245
@ PEDAL_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:216
@ LOW_CONGA
Definition midiPlayer.h:237
@ LOW_TIMBALE
Definition midiPlayer.h:239
@ OPEN_CUICA
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:258
@ ELECTRIC_BASS_DRUM_OR_HIGH_BASS_DRUM
Definition midiPlayer.h:206
@ LOW_WOODBLOCK
Definition midiPlayer.h:254
@ HIGH_FLOOR_TOM
Definition midiPlayer.h:214
@ MARACAS
Definition midiPlayer.h:243
@ HAND_CLAP
Definition midiPlayer.h:209
@ MUTE_TRIANGLE
This note supersedes any MUTE_TRIANGLE or OPEN_TRIANGLE notes playing.
Definition midiPlayer.h:260
@ OPEN_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:219
@ ACOUSTIC_BASS_DRUM_OR_LOW_BASS_DRUM
Definition midiPlayer.h:205
uint8_t chorus
The number of chorused voices to mix.
Definition midiPlayer.h:436
void globalMidiPlayerSetVolume(uint8_t trackType, int32_t volumeSetting)
Set the volume using a value from 0 to 13.
Definition midiPlayer.c:2833
void midiPlayerFillBufferMulti(midiPlayer_t *players, uint8_t playerCount, uint8_t *samples, int16_t len)
Fill a buffer with the next set of samples from an array of MIDI players.
Definition midiPlayer.c:1603
size_t count
The length of the sample map.
uint32_t loopsRemaining
The number of loops remaining before the voice will transition to the released state.
midiPlayer_t * globalMidiPlayerGet(uint8_t trackType)
Return a pointer to the system-wide MIDI player for the given track type, either MIDI_SFX or MIDI_BGM...
Definition midiPlayer.c:2894
uint16_t pitchBend
The 14-bit pitch wheel value.
Definition midiPlayer.h:702
bool(* midiStreamingCallback_t)(midiEvent_t *event)
A function to return MIDI events in streaming mode.
Definition midiPlayer.h:463
void midiSetTempo(midiPlayer_t *player, uint32_t tempo)
Change the MIDI playback tempo.
Definition midiPlayer.c:2636
void * globalMidiSave(void)
Stop all MIDI playback and return a pointer containing the full playback state. This state must be pa...
Definition midiFileParser.c:1040
uq8_24 baseNote
The base frequency, at which the sample plays at normal speed.
Definition midiPlayer.h:478
uint32_t voiceTick
The monotonic tick counter for this voice since starting.
Definition midiPlayer.h:572
int8_t(* percussionFunc_t)(percussionNote_t drum, uint32_t idx, bool *done, uint32_t scratch[4], void *data)
A function that returns samples for a percussion timbre rather than a melodic one.
Definition midiPlayer.h:448
int8_t tune
Fine tuning of the note, +/- 100 cents.
Definition midiPlayer.h:481
void midiPlayerReset(midiPlayer_t *player)
Reset the MIDI player state.
Definition midiPlayer.c:1438
voiceType_t type
The method for obtaining the next audio sample.
Definition midiPlayer.h:594
midiStreamingCallback_t streamingCallback
A callback function to retrieve the next event, when in MIDI_STREAMING mode.
Definition midiPlayer.h:754
timbreFlags_t
A bitfield which may contain various flags for a timbre.
Definition midiPlayer.h:151
@ TF_PERCUSSION
This timbre plays percussion sounds (percussionNote_t) rather than melodic notes.
Definition midiPlayer.h:155
@ TF_MONO
This timbre represents a monophonic instrument.
Definition midiPlayer.h:157
@ TF_NONE
No flags.
Definition midiPlayer.h:153
timbreEffects_t effects
Various effects applied to this timbre. May be ignored by percussion timbres.
Definition midiPlayer.h:549
Describes the characteristics of a particular timbre while.
Definition midiPlayer.h:401
Tracks the state of a single MIDI channel.
Definition midiPlayer.h:679
Tracks the state of the entire MIDI apparatus.
Definition midiPlayer.h:721
Defines the sound characteristics of a particular instrument.
Definition midiPlayer.h:505
Tracks the state of a single voice, playing a single note.
Definition midiPlayer.h:561
Definition midiPlayer.h:494
Definition midiPlayer.h:434
Struct that holds information about a sample that can be played.
Definition midiPlayer.h:470
Holds several bitfields that track the state of each voice for fast access. This may be used for dyna...
Definition midiPlayer.h:652
oscillatorShape_t
The different wave shapes that can be generated.
Definition swSynth.h:65
int8_t(* waveFunc_t)(uint16_t idx, void *data)
Function typedef to return a sample from a wave.
Definition swSynth.h:97
A software oscillator with controllable frequency, amplitude, and shape.
Definition swSynth.h:107