From c585c4402e73b32e6a707ed3bc5d1aeedd639053 Mon Sep 17 00:00:00 2001 From: Robert Hargreaves Date: Thu, 18 Jul 2024 21:25:40 +0100 Subject: [PATCH] Simplify struct declarations --- src/comm.c | 6 ++---- src/comm.h | 3 +-- src/log.h | 10 +++------- src/midi.c | 11 ++++------- src/midi.h | 12 ++++-------- src/midi_fm.c | 6 ++---- src/midi_fm.h | 6 ++---- src/midi_fm_sm.c | 8 +++----- src/midi_psg.c | 13 +++++-------- src/pcm_sample.h | 6 ++---- src/synth.h | 22 +++++++--------------- 11 files changed, 35 insertions(+), 68 deletions(-) diff --git a/src/comm.c b/src/comm.c index b94dfbb..5f39674 100644 --- a/src/comm.c +++ b/src/comm.c @@ -17,15 +17,13 @@ static const u16 MAX_COMM_BUSY = 0x28F; static bool countsInBounds(void); -typedef struct CommVTable CommVTable; - -struct CommVTable { +typedef struct CommVTable { void (*init)(void); u8 (*read_ready)(void); u8 (*read)(void); u8 (*write_ready)(void); void (*write)(u8 data); -}; +} CommVTable; static const CommVTable Demo_VTable = { comm_demo_init, comm_demo_read_ready, comm_demo_read, comm_demo_write_ready, comm_demo_write }; diff --git a/src/comm.h b/src/comm.h index 72bd400..272902f 100644 --- a/src/comm.h +++ b/src/comm.h @@ -1,8 +1,7 @@ #pragma once #include "types.h" -enum CommMode { Discovery, Everdrive, EverdrivePro, Serial, MegaWiFi, Demo }; -typedef enum CommMode CommMode; +typedef enum CommMode { Discovery, Everdrive, EverdrivePro, Serial, MegaWiFi, Demo } CommMode; void comm_init(void); void comm_write(u8 data); diff --git a/src/log.h b/src/log.h index fe39f54..80ec1c4 100644 --- a/src/log.h +++ b/src/log.h @@ -4,17 +4,13 @@ #define MSG_MAX_LEN 40 -typedef enum LogLevel LogLevel; +typedef enum LogLevel { Info, Warn } LogLevel; -enum LogLevel { Info, Warn }; - -typedef struct Log Log; - -struct Log { +typedef struct Log { LogLevel level; u16 msgLen; char msg[MSG_MAX_LEN]; -}; +} Log; void log_init(void); void log_info(const char* fmt, ...) __attribute__((format(printf, 1, 2))); diff --git a/src/midi.c b/src/midi.c index e8da66c..97f2db9 100644 --- a/src/midi.c +++ b/src/midi.c @@ -17,11 +17,9 @@ #define CHANNEL_UNASSIGNED 0xFF #define LENGTH_OF(x) (sizeof(x) / sizeof(x[0])) -typedef enum DeviceSelect DeviceSelect; -enum DeviceSelect { Auto, FM, PSG_Tone, PSG_Noise }; +typedef enum DeviceSelect { Auto, FM, PSG_Tone, PSG_Noise } DeviceSelect; -typedef struct MidiChannel MidiChannel; -struct MidiChannel { +typedef struct MidiChannel { u8 volume; u8 program; u8 pan; @@ -29,10 +27,9 @@ struct MidiChannel { u8 prevVelocity; NotePriorityStack notePriority; DeviceSelect deviceSelect; -}; +} MidiChannel; -typedef enum MappingMode MappingMode; -enum MappingMode { MappingMode_Static, MappingMode_Dynamic, MappingMode_Auto }; +typedef enum MappingMode { MappingMode_Static, MappingMode_Dynamic, MappingMode_Auto } MappingMode; static const VTable PSG_VTable = { midi_psg_note_on, midi_psg_note_off, midi_psg_channel_volume, midi_psg_pitch_bend, midi_psg_program, midi_psg_all_notes_off, midi_psg_pan }; diff --git a/src/midi.h b/src/midi.h index eb9fb22..0cb0117 100644 --- a/src/midi.h +++ b/src/midi.h @@ -118,9 +118,7 @@ #define SYSEX_COMMAND_WRITE_YM2612_REG_PART_0 0x08 #define SYSEX_COMMAND_WRITE_YM2612_REG_PART_1 0x09 -typedef struct VTable VTable; - -struct VTable { +typedef struct VTable { void (*noteOn)(u8 chan, u8 pitch, u8 velocity); void (*noteOff)(u8 chan, u8 pitch); void (*channelVolume)(u8 chan, u8 volume); @@ -128,11 +126,9 @@ struct VTable { void (*program)(u8 chan, u8 program); void (*allNotesOff)(u8 chan); void (*pan)(u8 chan, u8 pan); -}; - -typedef struct DeviceChannel DeviceChannel; +} VTable; -struct DeviceChannel { +typedef struct DeviceChannel { u8 number; const VTable* ops; bool noteOn; @@ -142,7 +138,7 @@ struct DeviceChannel { u8 volume; u8 pan; u16 pitchBend; -}; +} DeviceChannel; void midi_init(const FmChannel** defaultPresets, const PercussionPreset** defaultPercussionPresets, const u8** defaultEnvelopes); diff --git a/src/midi_fm.c b/src/midi_fm.c index 1c46a9a..0d0b2da 100644 --- a/src/midi_fm.c +++ b/src/midi_fm.c @@ -15,16 +15,14 @@ static const u16 FREQS[] = { }; static const u8 FREQ_NORMAL_RANGE_OFFSET = 2; -typedef struct MidiFmChannel MidiFmChannel; - -struct MidiFmChannel { +typedef struct MidiFmChannel { u8 pitch; u8 volume; u8 velocity; u8 pan; bool percussive; u16 pitchBend; -}; +} MidiFmChannel; static MidiFmChannel fmChannels[MAX_FM_CHANS]; diff --git a/src/midi_fm.h b/src/midi_fm.h index 3ac516b..1381682 100644 --- a/src/midi_fm.h +++ b/src/midi_fm.h @@ -6,12 +6,10 @@ #define MIN_MIDI_PITCH 11 #define MAX_MIDI_PITCH 106 -typedef struct PercussionPreset PercussionPreset; - -struct PercussionPreset { +typedef struct PercussionPreset { FmChannel channel; u8 key; -}; +} PercussionPreset; void midi_fm_init( const FmChannel** defaultPresets, const PercussionPreset** defaultPercussionPresets); diff --git a/src/midi_fm_sm.c b/src/midi_fm_sm.c index 6de8691..e56e929 100644 --- a/src/midi_fm_sm.c +++ b/src/midi_fm_sm.c @@ -4,12 +4,10 @@ #define SM_OP_LEN 3 -typedef struct SpecialModeOperator SpecialModeOperator; - -struct SpecialModeOperator { +typedef struct SpecialModeOperator { u8 pitch; u16 pitchBend; -}; +} SpecialModeOperator; static SpecialModeOperator smOperators[SM_OP_LEN]; @@ -58,4 +56,4 @@ void midi_fm_sm_program(u8 chan, u8 program) void midi_fm_sm_all_notes_off(u8 chan) { -} \ No newline at end of file +} diff --git a/src/midi_psg.c b/src/midi_psg.c index 5bf2b8e..cf2d6d2 100644 --- a/src/midi_psg.c +++ b/src/midi_psg.c @@ -34,13 +34,7 @@ static const u8 ATTENUATIONS[] = { 15, 14, 14, 14, 13, 13, 13, 13, 12, 12, 12, 1 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -typedef struct MidiPsgChannel MidiPsgChannel; - -static u8 userDefinedEnvelope[256]; -static u8* userDefinedEnvelopePtr; -static const u8** envelopes; - -struct MidiPsgChannel { +typedef struct MidiPsgChannel { u8 chanNum; u8 key; u8 attenuation; @@ -53,8 +47,11 @@ struct MidiPsgChannel { const u8* envelopeLoopStart; bool noteReleased; u16 pitchBend; -}; +} MidiPsgChannel; +static u8 userDefinedEnvelope[256]; +static u8* userDefinedEnvelopePtr; +static const u8** envelopes; static u8 audible; static MidiPsgChannel psgChannels[MAX_PSG_CHANS]; diff --git a/src/pcm_sample.h b/src/pcm_sample.h index 7b17361..e4452ef 100644 --- a/src/pcm_sample.h +++ b/src/pcm_sample.h @@ -1,12 +1,10 @@ #include "types.h" #include "samples.h" -typedef struct PcmSample PcmSample; - -struct PcmSample { +typedef struct PcmSample { const u8* data; u32 length; u8 rate; -}; +} PcmSample; extern const PcmSample* percussionPcmSample[128]; diff --git a/src/synth.h b/src/synth.h index 52c0d45..4831ec2 100644 --- a/src/synth.h +++ b/src/synth.h @@ -11,9 +11,7 @@ #define STEREO_MODE_RIGHT 1 #define STEREO_MODE_LEFT 2 -typedef struct Operator Operator; - -struct Operator { +typedef struct Operator { u8 multiple; u8 detune; u8 attackRate; @@ -25,11 +23,9 @@ struct Operator { u8 releaseRate; u8 totalLevel; u8 ssgEg; -}; - -typedef struct FmChannel FmChannel; +} Operator; -struct FmChannel { +typedef struct FmChannel { u8 algorithm; u8 feedback; u8 stereo; @@ -38,19 +34,15 @@ struct FmChannel { u8 octave; u16 freqNumber; Operator operators[MAX_FM_OPERATORS]; -}; +} FmChannel; -typedef struct Global Global; - -struct Global { +typedef struct Global { u8 lfoEnable; u8 lfoFrequency; bool specialMode; -}; - -typedef enum ParameterUpdated ParameterUpdated; +} Global; -enum ParameterUpdated { Channel, Lfo, SpecialMode }; +typedef enum ParameterUpdated { Channel, Lfo, SpecialMode } ParameterUpdated; typedef void ParameterUpdatedCallback(u8 fmChan, ParameterUpdated parameterUpdated);