Skip to content

Commit 57a77f3

Browse files
committed
paint: add sounds tab
1 parent 054677a commit 57a77f3

24 files changed

Lines changed: 419 additions & 81 deletions

base/sources/engine.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ any_map_t *data_cached_materials = NULL;
18151815
any_map_t *data_cached_worlds = NULL;
18161816
any_map_t *data_cached_shaders = NULL;
18171817
any_map_t *data_cached_blobs = NULL;
1818-
any_map_t *data_cached_textures = NULL;
1818+
any_map_t *data_cached_textures = NULL;
18191819
any_map_t *data_cached_videos = NULL;
18201820
any_map_t *data_cached_fonts = NULL;
18211821
any_map_t *data_cached_sounds = NULL;
@@ -2013,7 +2013,6 @@ draw_font_t *data_get_font(char *file) {
20132013
return b;
20142014
}
20152015

2016-
#ifdef IRON_AUDIO
20172016
sound_t *data_get_sound(char *file) {
20182017
if (data_cached_sounds == NULL) {
20192018
data_cached_sounds = any_map_create();
@@ -2023,8 +2022,7 @@ sound_t *data_get_sound(char *file) {
20232022
if (cached != NULL) {
20242023
return cached;
20252024
}
2026-
sound_t *b = gc_alloc(sizeof(sound_t));
2027-
b->sound_ = iron_load_sound(data_resolve_path(file));
2025+
sound_t *b = iron_load_sound(data_resolve_path(file));
20282026
any_map_set(data_cached_sounds, file, b);
20292027
data_assets_loaded++;
20302028
return b;
@@ -2038,10 +2036,11 @@ void data_delete_sound(char *handle) {
20382036
if (sound == NULL) {
20392037
return;
20402038
}
2041-
iron_a1_sound_destroy(sound->sound_);
2039+
#ifdef IRON_AUDIO
2040+
iron_a1_sound_destroy(sound);
2041+
#endif
20422042
map_delete(data_cached_sounds, handle);
20432043
}
2044-
#endif
20452044

20462045
void data_delete_mesh(char *handle) {
20472046
if (data_cached_meshes == NULL) {

base/sources/engine.h

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,7 @@ void uniforms_set_material_const(i32 location, shader_const_t *shade
536536
// ██████╔╝██║ ██║ ██║ ██║ ██║
537537
// ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
538538

539-
typedef struct sound {
540-
void *sound_;
541-
} sound_t;
539+
typedef void sound_t;
542540

543541
extern any_map_t *data_cached_scene_raws;
544542
extern any_map_t *data_cached_meshes;
@@ -550,10 +548,8 @@ extern any_map_t *data_cached_blobs;
550548
extern any_map_t *data_cached_textures;
551549
extern any_map_t *data_cached_videos;
552550
extern any_map_t *data_cached_fonts;
553-
#ifdef IRON_AUDIO
554551
extern any_map_t *data_cached_sounds;
555-
#endif
556-
extern i32 data_assets_loaded;
552+
extern i32 data_assets_loaded;
557553

558554
mesh_data_t *data_get_mesh(char *file, char *name);
559555
camera_data_t *data_get_camera(char *file, char *name);
@@ -565,21 +561,17 @@ gpu_texture_t *data_get_texture(char *file);
565561
buffer_t *data_get_blob(char *file);
566562
video_t *data_get_video(char *file);
567563
draw_font_t *data_get_font(char *file);
568-
#ifdef IRON_AUDIO
569-
sound_t *data_get_sound(char *file);
570-
#endif
571-
void data_delete_mesh(char *handle);
572-
void data_delete_blob(char *handle);
573-
void data_delete_texture(char *handle);
574-
void data_delete_video(char *handle);
575-
void data_delete_font(char *handle);
576-
#ifdef IRON_AUDIO
577-
void data_delete_sound(char *handle);
578-
#endif
579-
bool data_is_abs(char *file);
580-
bool data_is_up(char *file);
581-
char *data_resolve_path(char *file);
582-
char *data_path(void);
564+
sound_t *data_get_sound(char *file);
565+
void data_delete_mesh(char *handle);
566+
void data_delete_blob(char *handle);
567+
void data_delete_texture(char *handle);
568+
void data_delete_video(char *handle);
569+
void data_delete_font(char *handle);
570+
void data_delete_sound(char *handle);
571+
bool data_is_abs(char *file);
572+
bool data_is_up(char *file);
573+
char *data_resolve_path(char *file);
574+
char *data_path(void);
583575

584576
// ███████╗ ██████╗███████╗███╗ ██╗███████╗
585577
// ██╔════╝██╔════╝██╔════╝████╗ ██║██╔════╝

base/sources/iron.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,14 @@ gpu_texture_t *iron_load_texture(char *file) {
867867
return gpu_create_texture_from_encoded_bytes(&buf, file);
868868
}
869869

870-
#ifdef IRON_AUDIO
871870
void *iron_load_sound(char *file) {
871+
#ifdef IRON_AUDIO
872872
iron_a1_init();
873873
iron_a1_sound_t *sound = iron_a1_sound_create(file);
874874
return sound;
875-
}
876875
#endif
876+
return NULL;
877+
}
877878

878879
buffer_t *iron_load_blob(char *file) {
879880
#ifdef WITH_EMBED

base/sources/iron_audio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#include <stdlib.h>
1818
#include <string.h>
1919

20+
void iron_a2_init(void);
21+
void iron_a2_set_callback(void (*iron_a2_audio_callback)(iron_a2_buffer_t *buffer, uint32_t samples, void *userdata), void *userdata);
22+
uint32_t iron_a2_samples_per_second(void);
23+
void iron_a2_set_sample_rate_callback(void (*iron_a2_sample_rate_callback)(void *userdata), void *userdata);
24+
void iron_a2_internal_sample_rate_callback(void);
25+
2026
struct iron_a1_channel {
2127
iron_a1_sound_t *sound;
2228
float position;
@@ -143,7 +149,9 @@ void iron_a1_init(void) {
143149
iron_a2_set_callback(iron_a2_on_a1_mix, NULL);
144150
}
145151

146-
iron_a1_channel_t *iron_a1_play_sound(iron_a1_sound_t *sound, bool loop, float pitch, bool unique) {
152+
iron_a1_channel_t *audio_play(iron_a1_sound_t *sound, bool loop) {
153+
float pitch = 1.0;
154+
bool unique = false;
147155
iron_a1_channel_t *channel = NULL;
148156
iron_mutex_lock(&mutex);
149157
bool found = false;

base/sources/iron_audio.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct iron_a1_stream_channel;
4747
typedef struct iron_a1_stream_channel iron_a1_stream_channel_t;
4848

4949
void iron_a1_init(void);
50-
iron_a1_channel_t *iron_a1_play_sound(iron_a1_sound_t *sound, bool loop, float pitch, bool unique);
50+
iron_a1_channel_t *audio_play(iron_a1_sound_t *sound, bool loop);
5151
void iron_a1_stop_sound(iron_a1_sound_t *sound);
5252
void iron_a1_play_sound_stream(iron_a1_sound_stream_t *stream);
5353
void iron_a1_stop_sound_stream(iron_a1_sound_stream_t *stream);
@@ -71,15 +71,9 @@ float iron_a1_sound_stream_position(iron_a1_sound_stream_t *st
7171
void iron_a1_sound_stream_reset(iron_a1_sound_stream_t *stream);
7272
float iron_a1_sound_stream_volume(iron_a1_sound_stream_t *stream);
7373
void iron_a1_sound_stream_set_volume(iron_a1_sound_stream_t *stream, float value);
74-
75-
void iron_a2_init(void);
76-
void iron_a2_set_callback(void (*iron_a2_audio_callback)(iron_a2_buffer_t *buffer, uint32_t samples, void *userdata), void *userdata);
77-
uint32_t iron_a2_samples_per_second(void);
78-
void iron_a2_set_sample_rate_callback(void (*iron_a2_sample_rate_callback)(void *userdata), void *userdata);
79-
void iron_a2_shutdown(void);
80-
void iron_a2_internal_init(void);
81-
bool iron_a2_internal_callback(iron_a2_buffer_t *buffer, int samples);
82-
void iron_a2_internal_sample_rate_callback(void);
74+
void iron_a2_internal_init(void);
75+
void iron_a2_shutdown(void);
76+
bool iron_a2_internal_callback(iron_a2_buffer_t *buffer, int samples);
8377

8478
// struct iron_internal_video_channel;
8579
// typedef struct iron_internal_video_channel iron_internal_video_channel_t;

base/sources/iron_path.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool path_is_protected_linux = false;
1414

1515
string_array_t *_path_mesh_formats = NULL;
1616
string_array_t *_path_texture_formats = NULL;
17-
string_array_t *_path_audio_formats = NULL;
17+
string_array_t *_path_sound_formats = NULL;
1818
static string_array_t *_path_base_color_ext = NULL;
1919
static string_array_t *_path_opacity_ext = NULL;
2020
static string_array_t *_path_normal_map_ext = NULL;
@@ -50,14 +50,14 @@ string_array_t *path_texture_formats(void) {
5050
return _path_texture_formats;
5151
}
5252

53-
string_array_t *path_audio_formats(void) {
54-
if (_path_audio_formats == NULL) {
55-
_path_audio_formats = string_array_create(0);
56-
gc_root(_path_audio_formats);
57-
string_array_push(_path_audio_formats, "wav");
58-
string_array_push(_path_audio_formats, "ogg");
53+
string_array_t *path_sound_formats(void) {
54+
if (_path_sound_formats == NULL) {
55+
_path_sound_formats = string_array_create(0);
56+
gc_root(_path_sound_formats);
57+
string_array_push(_path_sound_formats, "wav");
58+
string_array_push(_path_sound_formats, "ogg");
5959
}
60-
return _path_audio_formats;
60+
return _path_sound_formats;
6161
}
6262

6363
string_array_t *path_base_color_ext(void) {
@@ -251,9 +251,9 @@ bool path_is_texture(char *path) {
251251
return false;
252252
}
253253

254-
bool path_is_audio(char *path) {
254+
bool path_is_sound(char *path) {
255255
char *p = to_lower_case(path);
256-
string_array_t *formats = path_audio_formats();
256+
string_array_t *formats = path_sound_formats();
257257
for (uint32_t i = 0; i < formats->length; ++i) {
258258
char *s = formats->buffer[i];
259259
char *ext = string(".%s", s);
@@ -300,7 +300,7 @@ bool path_is_lut(char *path) {
300300
}
301301

302302
bool path_is_known(char *path) {
303-
return path_is_mesh(path) || path_is_texture(path) || path_is_audio(path) || path_is_font(path) || path_is_project(path) || path_is_plugin(path) ||
303+
return path_is_mesh(path) || path_is_texture(path) || path_is_sound(path) || path_is_font(path) || path_is_project(path) || path_is_plugin(path) ||
304304
path_is_text(path) || path_is_ext_format(path) || path_is_lut(path);
305305
}
306306

base/sources/iron_path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ char *path_base_dir(char *path);
2525
char *path_base_name(char *path);
2626
bool path_is_mesh(char *path);
2727
bool path_is_texture(char *path);
28-
bool path_is_audio(char *path);
28+
bool path_is_sound(char *path);
2929
bool path_is_font(char *path);
3030
bool path_is_project(char *path);
3131
bool path_is_plugin(char *path);

paint/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ flags.with_plugins = true;
1414
flags.with_kong = true;
1515
flags.with_raytrace = true;
1616
flags.with_bc7 = true;
17-
flags.with_audio = false; // platform == "linux";
17+
flags.with_audio = platform == "linux";
1818
flags.idle_sleep = true;
1919
flags.export_version_info = true;
2020
flags.export_data_list = platform == "android"; // .apk contents

paint/sources/context.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ void context_select_font(i32 i) {
243243
context_set_font(g_project->_->fonts->buffer[i]);
244244
}
245245

246+
void context_set_sound(slot_sound_t *s) {
247+
if (array_index_of(g_project->_->sounds, s) == -1) {
248+
return;
249+
}
250+
g_context->sound = s;
251+
ui_base_hwnds->buffer[TAB_AREA_STATUS]->redraws = 2;
252+
ui_view2d_hwnd->redraws = 2;
253+
}
254+
255+
void context_select_sound(i32 i) {
256+
if (g_project->_->sounds->length <= i) {
257+
return;
258+
}
259+
context_set_sound(g_project->_->sounds->buffer[i]);
260+
}
261+
246262
void context_select_layer(i32 i) {
247263
if (g_project->_->layers->length <= i) {
248264
return;

paint/sources/functions.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void layers_on_resized();
8282
void layers_create_filter();
8383
void layers_create_image_layer(asset_t *asset);
8484
slot_font_t *slot_font_create(char *name, draw_font_t *font, char *file);
85+
slot_sound_t *slot_sound_create(char *name, sound_t *sound, char *file);
8586
scene_t *startup_get_scene(void);
8687
buffer_t *util_encode_scene(scene_t *raw);
8788
buffer_t *util_encode_project(project_t *raw);
@@ -229,7 +230,10 @@ void context_select_material(i32 i);
229230
void context_set_material(slot_material_t *m);
230231
void context_select_brush(i32 i);
231232
void context_set_brush(slot_brush_t *b);
233+
void context_set_font(slot_font_t *f);
232234
void context_select_font(i32 i);
235+
void context_set_sound(slot_sound_t *s);
236+
void context_select_sound(i32 i);
233237
void context_select_layer(i32 i);
234238
void context_set_layer(slot_layer_t *l);
235239
void context_select_tool(i32 i);
@@ -335,7 +339,7 @@ void render_path_preview_commands_decal();
335339
node_shader_context_t *make_paint_run(material_t *data, material_context_t *matcon);
336340
node_shader_context_t *make_mesh_preview_run(material_t *data, material_context_t *matcon, bool viewport);
337341
material_data_t *make_mesh_preview_viewport(slot_material_t *slot);
338-
void import_audio_run(char *path);
342+
void import_sound_run(char *path);
339343
void import_mesh_run(char *path, bool _clear_layers, bool replace_existing, bool keep_camera);
340344
void import_mesh_finish_import(void *_);
341345
void import_mesh_make_mesh(raw_mesh_t *mesh);
@@ -377,6 +381,7 @@ void viewport_save_texture(gpu_texture_t *screenshot);
377381
void viewport_capture_video_begin();
378382
void viewport_capture_video_end();
379383
void tab_fonts_draw(ui_handle_t *htab);
384+
void tab_sounds_draw(ui_handle_t *htab);
380385
physics_world_t *physics_world_create();
381386
void physics_world_update(physics_world_t *world);
382387
physics_pair_t_array_t *physics_world_get_contact_pairs(physics_world_t *world, physics_body_t *body);

0 commit comments

Comments
 (0)