audio_set() -> audio_set_parameter(), with string based convention

This commit is contained in:
veclavtalica
2024-10-22 13:52:24 +03:00
parent 5a08c01208
commit b390e9db23
6 changed files with 25 additions and 38 deletions

View File

@ -35,7 +35,7 @@ void render_queue_clear(void) {
}
void draw_9slice(const char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) {
void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) {
const float bt = (float)border_thickness; /* i know! */
const float bt2 = bt * 2; /* combined size of the two borders in an axis */

View File

@ -191,42 +191,32 @@ void audio_play(const char *path,
}
TWN_API void audio_set(const char *channel, AudioParam param, float value) {
TWN_API void audio_set_parameter(const char *channel, const char *param, float value) {
AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
if (!pair) {
log_warn("No channel by the name of %s to set a parameter for", channel);
return;
}
switch (param) {
case AUDIO_PARAM_REPEAT:
if (SDL_strcmp(param, "repeat") == 0) {
pair->value.repeat = (bool)value;
break;
case AUDIO_PARAM_VOLUME:
if (value > 1.0f) {
} else if (SDL_strcmp(param, "volume") == 0) {
if (value > 1.0f || value < 0.0f) {
log_warn("Out of range volume for channel %s set", channel);
value = 1.0f;
}
if (value < 0.0f) {
log_warn("Out of range volume for channel %s set", channel);
value = 0.0f;
value = clampf(value, 0.0f, 1.0f);
}
pair->value.volume = value;
break;
case AUDIO_PARAM_PANNING:
if (value > 1.0f) {
} else if (SDL_strcmp(param, "panning") == 0) {
if (value > 1.0f || value < -1.0f) {
log_warn("Out of range panning for channel %s set", channel);
value = 1.0f;
}
if (value < -1.0f) {
log_warn("Out of range panning for channel %s set", channel);
value = -1.0f;
value = clampf(value, -1.0f, +1.0f);
}
pair->value.panning = value;
break;
default:
} else
CRY("Audio channel parameter setting failed", "Invalid parameter enum given");
}
}