Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dylwhich committed Aug 24, 2024
1 parent 25e4158 commit 080ef60
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 69 deletions.
4 changes: 3 additions & 1 deletion emulator/idf-inc/class/midi/midi_device_emu.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
void setMidiClientName(const char* name);
#pragma once

void setMidiClientName(const char* name);
1 change: 0 additions & 1 deletion emulator/src/components/hdw-nvs/hdw-nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ bool readNamespaceNvs32(const char* namespace, const char* key, int32_t* outVal)

if (!json)
{
fclose(nvsFile);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions emulator/src/emu_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ bool makeDirs(const char* path)
// Ugh. Whatever.
char tmp[1024];
strncpy(tmp, buffer, sizeof(tmp));
tmp[sizeof(tmp) - 1] = '\0';
readlink(tmp, buffer, sizeof(buffer) - strlen(buffer) - 1);
// printf("Symbolic Link: %s --> %s\n", tmp, buffer);
}
Expand Down
1 change: 1 addition & 0 deletions emulator/src/extensions/tools/ext_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ void startScreenRecording(const char* name)
else
{
strncpy(recordingFilename, name, sizeof(recordingFilename));
recordingFilename[sizeof(recordingFilename) - 1] = '\0';
}
}
else
Expand Down
1 change: 1 addition & 0 deletions emulator/src/idf/esp_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdio.h>

#include <esp_random.h>
#include <esp_random_emu.h>
#include "ext_replay.h"
#include "esp_timer.h"

Expand Down
1 change: 1 addition & 0 deletions emulator/src/idf/esp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "esp_timer.h"
#include "esp_log.h"
#include "esp_timer_emu.h"

//==============================================================================
// Variables
Expand Down
2 changes: 1 addition & 1 deletion main/menu/menu_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void menuSavePosition(const char** out, int len, const menu_t* menu)
// Zero out the rest of the array if we won't be setting it
if (depth + 1 < len)
{
memset(out + depth + 1, 0, sizeof(out) * (len - depth - 1));
memset(out + depth + 1, 0, sizeof(char*) * (len - depth - 1));
}

const char** curOut = (out + depth);
Expand Down
5 changes: 3 additions & 2 deletions main/midi/drums.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ static int16_t linearAttackExpDecay(uint32_t tick, uint32_t attackTime, uint32_t
}
else if ((tick - attackTime) / halfLife < 32)
{
// The condition is to make sure we don't do (1<<32) which is UB
// The condition is to make sure we don't do (1<<32) which is UB
// And (n / UINT32_MAX)) is 0 for all reasonable inputs
return 256 * attackLevel / (1 << ((tick - attackTime) / halfLife)) / 256;
// And (1<<31) is UB for signed values, so make sure it's unsigned!
return 256 * attackLevel / (1u << ((tick - attackTime) / halfLife)) / 256;
}
else
{
Expand Down
94 changes: 30 additions & 64 deletions main/modes/music/usbsynth/mode_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ typedef struct
};

const char* label;
bool dynamicLabel;
char shortLabel[4];

} midiMenuItemInfo_t;
Expand Down Expand Up @@ -1552,8 +1551,6 @@ static void synthEnterMode(void)
sd->wheelTextArea.width = TFT_WIDTH - 30;
sd->wheelTextArea.height = sd->betterFont.height + 2;

//synthSetupMenu();

// Use smol font for menu items, there might be a lot
sd->renderer = initMenuManiaRenderer(NULL, NULL, &sd->font);
sd->wheelMenu = initWheelMenu(&sd->betterFont, 90, &sd->wheelTextArea);
Expand Down Expand Up @@ -1669,16 +1666,7 @@ static void synthExitMode(void)
hashIterator_t iter = {0};
while (hashIterate(&sd->menuMap, &iter))
{
midiMenuItemInfo_t* info = (midiMenuItemInfo_t*)iter.value;

hashIterRemove(&sd->menuMap, &iter);

if (info->dynamicLabel)
{
free((char*)info->label);
info->label = NULL;
info->dynamicLabel = false;
}
}

hashDeinit(&sd->menuMap);
Expand Down Expand Up @@ -2122,11 +2110,10 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
{
midiMenuItemInfo_t* itemInfo = &sd->itemInfos[sd->itemInfoCount++];

itemInfo->type = SMT_PROGRAM;
itemInfo->bank = 0;
itemInfo->program = gmProg;
itemInfo->label = gmProgramNames[gmProg];
itemInfo->dynamicLabel = false;
itemInfo->type = SMT_PROGRAM;
itemInfo->bank = 0;
itemInfo->program = gmProg;
itemInfo->label = gmProgramNames[gmProg];
writeShortName(itemInfo->shortLabel, sizeof(itemInfo->shortLabel), itemInfo->label);
wheelMenuSetItemInfo(sd->wheelMenu, itemInfo->label, NULL, gmProg % 8, NO_SCROLL);
wheelMenuSetItemTextIcon(sd->wheelMenu, itemInfo->label, itemInfo->shortLabel);
Expand All @@ -2147,11 +2134,10 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
{
midiMenuItemInfo_t* itemInfo = &sd->itemInfos[sd->itemInfoCount++];

itemInfo->type = SMT_PROGRAM;
itemInfo->bank = 1;
itemInfo->program = magProg;
itemInfo->label = magfestTimbres[magProg]->name;
itemInfo->dynamicLabel = false;
itemInfo->type = SMT_PROGRAM;
itemInfo->bank = 1;
itemInfo->program = magProg;
itemInfo->label = magfestTimbres[magProg]->name;
writeShortName(itemInfo->shortLabel, sizeof(itemInfo->shortLabel), itemInfo->label);
wheelMenuSetItemInfo(sd->wheelMenu, itemInfo->label, NULL, magProg, NO_SCROLL);
wheelMenuSetItemTextIcon(sd->wheelMenu, itemInfo->label, itemInfo->shortLabel);
Expand All @@ -2161,8 +2147,7 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
}

// Controllers are pretty complicated so just do those the first time with the rest of their logic
bool controllersSetUp = false;
int totalControls = 0;
int totalControls = 0;

addSettingsOptionsItemToMenu(menu, menuItemSelectChan, menuItemChannelsOptions, menuItemChannelsValues,
ARRAY_SIZE(menuItemChannelsValues), &menuItemChannelsBounds, sd->menuSelectedChannel);
Expand All @@ -2177,7 +2162,6 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
itemInfo->type = SMT_CHANNEL;
itemInfo->channel = chIdx;
itemInfo->label = channelLabels[chIdx];
itemInfo->dynamicLabel = false;
hashPut(&sd->menuMap, channelLabels[chIdx], itemInfo);

// Ignore Item & Option Settings
Expand Down Expand Up @@ -2286,16 +2270,13 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
const midiControllerDesc_t* controller = &controllerDefs[ctrlIdx];
if (synthIsControlSupported(controller))
{
const char* labelStr = controller->desc;
bool dynamicLabel = false;

switch (controller->type)
{
case CTRL_SWITCH:
{
// Options menu item, on/off
addSettingsOptionsItemToMenu(
menu, labelStr, menuItemOffOnOptions, menuItemControlSwitchValues,
menu, controller->desc, menuItemOffOnOptions, menuItemControlSwitchValues,
ARRAY_SIZE(menuItemControlSwitchValues), &menuItemControl7bitBounds,
synthGetControl(
chIdx, controller->control,
Expand All @@ -2307,7 +2288,7 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
{
// Settings value item
addSettingsItemToMenu(
menu, labelStr, &menuItemControl14bitBounds,
menu, controller->desc, &menuItemControl14bitBounds,
synthGetControl14bit(
chIdx, controller->control,
midiGetControlValue14bit(&sd->midiPlayer, chIdx, (midiControl_t)controller->control)));
Expand All @@ -2324,7 +2305,7 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
case CTRL_UNDEFINED:
{
// Settings value item, 0-127
addSettingsItemToMenu(menu, labelStr, &menuItemControl7bitBounds,
addSettingsItemToMenu(menu, controller->desc, &menuItemControl7bitBounds,
synthGetControl(chIdx, controller->control,
midiGetControlValue(&sd->midiPlayer, chIdx,
(midiControl_t)controller->control)));
Expand All @@ -2334,33 +2315,27 @@ static void addChannelsMenu(menu_t* menu, const synthConfig_t* config)
case CTRL_NO_DATA:
{
// Single menu item, A just triggers it
addSingleItemToMenu(menu, labelStr);
addSingleItemToMenu(menu, controller->desc);
break;
}
}

if (!controllersSetUp || dynamicLabel)
{
itemInfo = &sd->itemInfos[sd->itemInfoCount++];
itemInfo->type = SMT_CONTROLLER;
itemInfo->controller = controller;
itemInfo->label = labelStr;
itemInfo->dynamicLabel = dynamicLabel;
wheelMenuSetItemInfo(sd->wheelMenu, labelStr, NULL, totalControls++, NO_SCROLL);
// Use rounded rectangle, stretched to fit
wheelMenuSetItemSize(sd->wheelMenu, labelStr, -1, -1, WM_SHAPE_ROUNDED_RECT);
writeShortName(itemInfo->shortLabel, sizeof(itemInfo->shortLabel), labelStr);
wheelMenuSetItemTextIcon(sd->wheelMenu, labelStr, itemInfo->shortLabel);

// If the label IS dynamic, we don't actually change it without resetting the menu
// So, don't worry about the hash key getting out of sync here
hashPut(&sd->menuMap, labelStr, itemInfo);
}
itemInfo = &sd->itemInfos[sd->itemInfoCount++];
itemInfo->type = SMT_CONTROLLER;
itemInfo->controller = controller;
itemInfo->label = controller->desc;
wheelMenuSetItemInfo(sd->wheelMenu, controller->desc, NULL, totalControls++, NO_SCROLL);
// Use rounded rectangle, stretched to fit
wheelMenuSetItemSize(sd->wheelMenu, controller->desc, -1, -1, WM_SHAPE_ROUNDED_RECT);
writeShortName(itemInfo->shortLabel, sizeof(itemInfo->shortLabel), controller->desc);
wheelMenuSetItemTextIcon(sd->wheelMenu, controller->desc, itemInfo->shortLabel);

// If the label IS dynamic, we don't actually change it without resetting the menu
// So, don't worry about the hash key getting out of sync here
hashPut(&sd->menuMap, controller->desc, itemInfo);
}
}

controllersSetUp = true;

// End controls submenu
menu = endSubMenu(menu);

Expand Down Expand Up @@ -2394,16 +2369,7 @@ static void synthSetupMenu(bool forceReset)
hashIterator_t iter = {0};
while (hashIterate(&sd->menuMap, &iter))
{
midiMenuItemInfo_t* info = (midiMenuItemInfo_t*)iter.value;

hashIterRemove(&sd->menuMap, &iter);

if (info->dynamicLabel)
{
free((char*)info->label);
info->label = NULL;
info->dynamicLabel = false;
}
}

sd->itemInfoCount = 0;
Expand Down Expand Up @@ -3072,7 +3038,7 @@ static void drawKaraokeLyrics(uint32_t ticks, karaokeInfo_t* karInfo)
// Lyric is older than 1 note

// Add a newline between measures, for files without KAR-style formatting
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages))
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages) - 1)
{
textMessages[msgLen++] = '\n';
textMessages[msgLen] = '\0';
Expand All @@ -3095,7 +3061,7 @@ static void drawKaraokeLyrics(uint32_t ticks, karaokeInfo_t* karInfo)
// NEXT lyric is also in the past

// Add a newline between measures, for files without KAR-style formatting
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages))
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages) - 1)
{
textMessages[msgLen++] = '\n';
textMessages[msgLen] = '\0';
Expand All @@ -3121,7 +3087,7 @@ static void drawKaraokeLyrics(uint32_t ticks, karaokeInfo_t* karInfo)
FLUSH();

// Add a newline between measures, for files without KAR-style formatting
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages))
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages) - 1)
{
textMessages[msgLen++] = '\n';
textMessages[msgLen] = '\0';
Expand Down Expand Up @@ -3200,7 +3166,7 @@ static void drawKaraokeLyrics(uint32_t ticks, karaokeInfo_t* karInfo)
// Note is less than (3 bars - 1 tick) in the future

// Add a newline between measures, for files without KAR-style formatting
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages))
if (!karInfo->karFormat && lastLyricBar != curLyricBar && msgLen < sizeof(textMessages) - 1)
{
textMessages[msgLen++] = '\n';
textMessages[msgLen] = '\0';
Expand Down

0 comments on commit 080ef60

Please sign in to comment.