Skip to content

Commit

Permalink
const-ify WildMidi_OpenBuffer
Browse files Browse the repository at this point in the history
It seems wrong for the library to be able to modify a user-supplied
buffer when it really doesn't ever need to. Besides, it led to issues
like Mindwerks#234 so this kind of behaviour should really be avoided.
  • Loading branch information
Clownacy committed Dec 14, 2022
1 parent f682c6a commit e354fec
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion include/f_hmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef __HMI_H
#define __HMI_H

extern struct _mdi *_WM_ParseNewHmi(uint8_t *hmi_data, uint32_t hmi_size);
extern struct _mdi *_WM_ParseNewHmi(const uint8_t *hmi_data, uint32_t hmi_size);

#endif /* __HMI_H */
2 changes: 1 addition & 1 deletion include/f_hmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef __HMP_H
#define __HMP_H

extern struct _mdi *_WM_ParseNewHmp(uint8_t *hmp_data, uint32_t hmp_size);
extern struct _mdi *_WM_ParseNewHmp(const uint8_t *hmp_data, uint32_t hmp_size);

#endif /* __HMP_H */
2 changes: 1 addition & 1 deletion include/f_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef __MIDI_H
#define __MIDI_H

extern struct _mdi *_WM_ParseNewMidi(uint8_t *midi_data, uint32_t midi_size);
extern struct _mdi *_WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size);
extern int _WM_Event2Midi(struct _mdi *mdi, uint8_t **out, uint32_t *outsize);

#endif /* __MIDI_H */
2 changes: 1 addition & 1 deletion include/f_xmidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef __XMI_H
#define __XMI_H

extern struct _mdi *_WM_ParseNewXmi(uint8_t *xmi_data, uint32_t xmi_size);
extern struct _mdi *_WM_ParseNewXmi(const uint8_t *xmi_data, uint32_t xmi_size);

#endif /* __XMI_H */
2 changes: 1 addition & 1 deletion include/internal_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ extern int _WM_midi_setup_divisions(struct _mdi *mdi, uint32_t divisions);

extern struct _mdi * _WM_initMDI(void);
extern void _WM_freeMDI(struct _mdi *mdi);
extern uint32_t _WM_SetupMidiEvent(struct _mdi *mdi, uint8_t *event_data, uint32_t inlen, uint8_t running_event);
extern uint32_t _WM_SetupMidiEvent(struct _mdi *mdi, const uint8_t *event_data, uint32_t inlen, uint8_t running_event);
extern void _WM_ResetToStart(struct _mdi *mdi);
extern void _WM_do_pan_adjust(struct _mdi *mdi, uint8_t ch);
extern void _WM_do_note_off_extra(struct _note *nte);
Expand Down
2 changes: 1 addition & 1 deletion include/wildmidi_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ WM_SYMBOL int WildMidi_Init (const char *config_file, uint16_t rate, uint16_t mi
WM_SYMBOL int WildMidi_InitVIO(struct _WM_VIO * callbacks, const char *config_file, uint16_t rate, uint16_t mixer_options);
WM_SYMBOL int WildMidi_MasterVolume (uint8_t master_volume);
WM_SYMBOL midi * WildMidi_Open (const char *midifile);
WM_SYMBOL midi * WildMidi_OpenBuffer (uint8_t *midibuffer, uint32_t size);
WM_SYMBOL midi * WildMidi_OpenBuffer (const uint8_t *midibuffer, uint32_t size);
WM_SYMBOL int WildMidi_GetMidiOutput (midi *handle, int8_t **buffer, uint32_t *size);
WM_SYMBOL int WildMidi_GetOutput (midi *handle, int8_t *buffer, uint32_t size);
WM_SYMBOL int WildMidi_SetOption (midi *handle, uint16_t options, uint16_t setting);
Expand Down
8 changes: 4 additions & 4 deletions src/f_hmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
Turns hmp file data into an event stream
*/
struct _mdi *
_WM_ParseNewHmi(uint8_t *hmi_data, uint32_t hmi_size) {
_WM_ParseNewHmi(const uint8_t *hmi_data, uint32_t hmi_size) {
uint32_t hmi_tmp = 0;
uint8_t *hmi_base = hmi_data;
uint8_t *data_end = hmi_data + hmi_size;
const uint8_t *hmi_base = hmi_data;
const uint8_t *data_end = hmi_data + hmi_size;
uint32_t data_size;
uint16_t hmi_bpm = 0;
uint16_t hmi_division = 0;
Expand All @@ -51,7 +51,7 @@ _WM_ParseNewHmi(uint8_t *hmi_data, uint32_t hmi_size) {
uint32_t *hmi_track_offset = NULL;
uint32_t i = 0;
uint32_t j = 0;
uint8_t *hmi_addr = NULL;
const uint8_t *hmi_addr = NULL;
uint32_t *hmi_track_header_length = NULL;
struct _mdi *hmi_mdi = NULL;
float tempo_f = 5000000.0f;
Expand Down
6 changes: 3 additions & 3 deletions src/f_hmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Turns hmp file data into an event stream
*/
struct _mdi *
_WM_ParseNewHmp(uint8_t *hmp_data, uint32_t hmp_size) {
_WM_ParseNewHmp(const uint8_t *hmp_data, uint32_t hmp_size) {
uint8_t is_hmp2 = 0;
uint32_t zero_cnt = 0;
uint32_t i = 0;
Expand All @@ -50,7 +50,7 @@ _WM_ParseNewHmp(uint8_t *hmp_data, uint32_t hmp_size) {
uint32_t hmp_bpm = 0;
uint32_t hmp_song_time = 0;
struct _mdi *hmp_mdi;
uint8_t **hmp_chunk;
const uint8_t **hmp_chunk;
uint32_t *chunk_length;
uint32_t *chunk_ofs;
uint32_t *chunk_delta;
Expand Down Expand Up @@ -190,7 +190,7 @@ _WM_ParseNewHmp(uint8_t *hmp_data, uint32_t hmp_size) {
_WM_midi_setup_divisions(hmp_mdi, hmp_divisions);
_WM_midi_setup_tempo(hmp_mdi, (uint32_t)tempo_f);

hmp_chunk = (uint8_t **) malloc(sizeof(uint8_t *) * hmp_chunks);
hmp_chunk = (const uint8_t **) malloc(sizeof(uint8_t *) * hmp_chunks);
chunk_length = (uint32_t *) malloc(sizeof(uint32_t) * hmp_chunks);
chunk_delta = (uint32_t *) malloc(sizeof(uint32_t) * hmp_chunks);
chunk_ofs = (uint32_t *) malloc(sizeof(uint32_t) * hmp_chunks);
Expand Down
6 changes: 3 additions & 3 deletions src/f_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@


struct _mdi *
_WM_ParseNewMidi(uint8_t *midi_data, uint32_t midi_size) {
_WM_ParseNewMidi(const uint8_t *midi_data, uint32_t midi_size) {
struct _mdi *mdi;

uint32_t tmp_val;
uint32_t midi_type;
uint8_t **tracks;
const uint8_t **tracks;
uint32_t *track_size;
uint32_t end_of_tracks = 0;
uint32_t no_tracks;
Expand Down Expand Up @@ -146,7 +146,7 @@ _WM_ParseNewMidi(uint8_t *midi_data, uint32_t midi_size) {
mdi = _WM_initMDI();
_WM_midi_setup_divisions(mdi,divisions);

tracks = (uint8_t **) malloc(sizeof(uint8_t *) * no_tracks);
tracks = (const uint8_t **) malloc(sizeof(uint8_t *) * no_tracks);
track_size = (uint32_t *) malloc(sizeof(uint32_t) * no_tracks);
track_delta = (uint32_t *) malloc(sizeof(uint32_t) * no_tracks);
track_end = (uint8_t *) malloc(sizeof(uint8_t) * no_tracks);
Expand Down
2 changes: 1 addition & 1 deletion src/f_xmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "f_xmidi.h"


struct _mdi *_WM_ParseNewXmi(uint8_t *xmi_data, uint32_t xmi_size) {
struct _mdi *_WM_ParseNewXmi(const uint8_t *xmi_data, uint32_t xmi_size) {
struct _mdi *xmi_mdi = NULL;
uint32_t xmi_tmpdata = 0;
uint8_t xmi_formcnt = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/internal_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ void _WM_freeMDI(struct _mdi *mdi) {
free(mdi);
}

uint32_t _WM_SetupMidiEvent(struct _mdi *mdi, uint8_t * event_data, uint32_t input_length, uint8_t running_event) {
uint32_t _WM_SetupMidiEvent(struct _mdi *mdi, const uint8_t * event_data, uint32_t input_length, uint8_t running_event) {
/*
Only add standard MIDI and Sysex events in here.
Non-standard events need to be handled by calling function
Expand Down
2 changes: 1 addition & 1 deletion src/wildmidi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ WM_SYMBOL midi *WildMidi_Open(const char *midifile) {
return (ret);
}

WM_SYMBOL midi *WildMidi_OpenBuffer(uint8_t *midibuffer, uint32_t size) {
WM_SYMBOL midi *WildMidi_OpenBuffer(const uint8_t *midibuffer, uint32_t size) {
uint8_t mus_hdr[] = { 'M', 'U', 'S', 0x1A };
uint8_t xmi_hdr[] = { 'F', 'O', 'R', 'M' };
midi * ret = NULL;
Expand Down

0 comments on commit e354fec

Please sign in to comment.