Skip to content

Commit

Permalink
Merge pull request janet-lang#53 from greenfork/add-music-from-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin authored Nov 10, 2023
2 parents f62fb0d + 00a3378 commit 82cc98c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ static Janet cfun_LoadMusicStream(int32_t argc, Janet *argv) {
return janet_wrap_abstract(music);
}

static Janet cfun_LoadMusicStreamFromMemory(int32_t argc, Janet *argv) {
janet_fixarity(argc, 3);
const char *fileType = janet_getcstring(argv, 0);
const unsigned char *data = jaylib_getunsignedcstring(argv, 1);
int dataSize = janet_getinteger(argv, 2);
Music *music = janet_abstract(&AT_Music, sizeof(Music));
*music = LoadMusicStreamFromMemory(fileType, data, dataSize);
return janet_wrap_abstract(music);
}

static Janet cfun_IsMusicReady(int32_t argc, Janet *argv) {
janet_fixarity(argc, 1);
Music music = *jaylib_getmusic(argv, 0);
Expand Down Expand Up @@ -446,6 +456,10 @@ static JanetReg audio_cfuns[] = {
"(load-music-stream file-name)\n\n"
"Load music stream from file"
},
{"load-music-stream-from-memory", cfun_LoadMusicStreamFromMemory,
"(load-music-stream-from-memory file-type data data-size)\n\n"
"Load music stream from data"
},
{"music-ready?", cfun_IsMusicReady,
"(music-ready? wave)\n\n"
"Checks if a music stream is ready"
Expand Down
10 changes: 0 additions & 10 deletions src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ static const char *jaylib_getcstring(const Janet *argv, int32_t n) {
return janet_getcstring(argv, n);
}

static const unsigned char *jaylib_getunsignedcstring(const Janet *argv, int32_t n) {
if (janet_checktype(argv[n], JANET_BUFFER)) {
JanetBuffer *buf = janet_unwrap_buffer(argv[n]);
janet_buffer_push_u8(buf, 0);
buf->count--;
return (const unsigned char *)buf->data;
}
return (const unsigned char *)janet_getcstring(argv, n);
}

static Janet cfun_GetFontDefault(int32_t argc, Janet *argv) {
(void) argv;
janet_fixarity(argc, 0);
Expand Down
10 changes: 10 additions & 0 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,13 @@ static Janet jaylib_wrap_raycollision(RayCollision rayCollision) {
janet_table_put(table, janet_wrap_keyword("normal"), jaylib_wrap_vec3(rayCollision.normal));
return janet_wrap_table(table);
}

static const unsigned char *jaylib_getunsignedcstring(const Janet *argv, int32_t n) {
if (janet_checktype(argv[n], JANET_BUFFER)) {
JanetBuffer *buf = janet_unwrap_buffer(argv[n]);
janet_buffer_push_u8(buf, 0);
buf->count--;
return (const unsigned char *)buf->data;
}
return (const unsigned char *)janet_getcstring(argv, n);
}

0 comments on commit 82cc98c

Please sign in to comment.