DirectMusic 0.0.1
An incomplete re-implementation of DirectMusic, Microsoft's adaptive soundtrack API for games delivered as part of Direct3D and DirectX
Loading...
Searching...
No Matches
dmusic.h
1// Copyright © 2024. GothicKit Contributors
2// SPDX-License-Identifier: MIT-Modern-Variant
3#pragma once
4#include <stddef.h>
5#include <stdint.h>
6
8#ifdef __cplusplus
9 #define DM_EXTERN extern "C"
10#else
11 #define DM_EXTERN
12#endif
13
14#if defined(_WIN32) || defined(__CYGWIN__)
15 #ifdef DM_BUILD
16 #ifdef __GNUC__
17 #define DMAPI DM_EXTERN __attribute__((dllexport))
18 #else
19 #define DMAPI DM_EXTERN __declspec(dllexport)
20 #endif
21 #else
22 #ifdef __GNUC__
23 #define DMAPI DM_EXTERN __attribute__((dllimport))
24 #else
25 #define DMAPI DM_EXTERN __declspec(dllimport)
26 #endif
27 #endif
28 #define DMINT
29#else
30 #define DMAPI DM_EXTERN __attribute__((visibility("default")))
31 #define DMINT DM_EXTERN __attribute__((visibility("hidden")))
32#endif
34
38
62
74typedef struct DmGuid {
76 uint8_t data[16];
78
88DMAPI size_t DmGuid_toString(DmGuid const* slf, char* out, size_t len);
89
105typedef void* DmMemoryAlloc(void* ctx, size_t len);
106
119typedef void DmMemoryFree(void* ctx, void* ptr);
120
140
151typedef uint32_t DmRng(void* ctx);
152
167DMAPI void Dm_setRandomNumberGenerator(DmRng* rng, void* ctx);
168
189
190typedef void DmLogHandler(void* ctx, DmLogLevel lvl, char const* msg);
191
204DMAPI void Dm_setLogger(DmLogLevel lvl, DmLogHandler* log, void* ctx);
205
214
218
220
283
286typedef struct DmSegment DmSegment;
287
290
293typedef struct DmLoader DmLoader;
294
297
301
304
309
317
333
338DMAPI DmGuid const* DmSegment_getGuid(DmSegment const* slf);
339
344DMAPI char const* DmSegment_getName(DmSegment const* slf);
345
355DMAPI double DmSegment_getLength(DmSegment const* slf);
356
360DMAPI uint32_t DmSegment_getRepeats(DmSegment const* slf);
361
363
366
376
392typedef void* DmLoaderResolverCallback(void* ctx, char const* file, size_t* len);
393
406
411
418DMAPI void DmLoader_release(DmLoader* slf);
419
435
455DMAPI DmResult DmLoader_getSegment(DmLoader* slf, char const* name, DmSegment** segment);
456
458
461
462typedef enum DmRenderOptions {
465
468
472
486
512
521DMAPI DmResult DmPerformance_create(DmPerformance** slf, uint32_t rate);
522
527
535
558
582 DmSegment* sgt,
583 DmEmbellishmentType embellishment,
584 DmTiming timing);
585
609DMAPI DmResult DmPerformance_renderPcm(DmPerformance* slf, void* buf, size_t num, DmRenderOptions opts);
610
615DMAPI void DmPerformance_setVolume(DmPerformance* slf, float vol);
616
size_t DmGuid_toString(DmGuid const *slf, char *out, size_t len)
Convert the given GUID to a string.
void Dm_setLogger(DmLogLevel lvl, DmLogHandler *log, void *ctx)
Set a callback to send log messages to.
DmResult
Possible operation result values.
Definition dmusic.h:40
DmLogLevel
The set of message levels supported by the logging facilities.
Definition dmusic.h:170
void DmMemoryFree(void *ctx, void *ptr)
A free-like memory de-allocation function.
Definition dmusic.h:119
void * DmMemoryAlloc(void *ctx, size_t len)
A malloc-like memory allocation function.
Definition dmusic.h:105
uint32_t DmRng(void *ctx)
A rand_r-like random number generation function.
Definition dmusic.h:151
void Dm_setRandomNumberGenerator(DmRng *rng, void *ctx)
Set the random number generator to use internally.
DmResult Dm_setHeapAllocator(DmMemoryAlloc *alloc, DmMemoryFree *free, void *ctx)
Set the memory allocator to use internally.
void Dm_setLoggerDefault(DmLogLevel lvl)
Set a default logging function.
void Dm_setLoggerLevel(DmLogLevel lvl)
Set the log level of the library.
@ DmResult_NOT_FOUND
A resource was not found.
Definition dmusic.h:54
@ DmResult_INVALID_ARGUMENT
An invalid argument was provided.
Definition dmusic.h:45
@ DmResult_INVALID_STATE
The operation could not be completed because the system is in an invalid state.
Definition dmusic.h:48
@ DmResult_SUCCESS
The operation completed successfully.
Definition dmusic.h:42
@ DmResult_MEMORY_EXHAUSTED
A memory allocation failed.
Definition dmusic.h:51
@ DmResult_FILE_CORRUPT
A resource file could not be parsed.
Definition dmusic.h:57
@ DmResult_MUTEX_ERROR
A mutex could not be locked.
Definition dmusic.h:60
@ DmLogLevel_TRACE
The log message is a tracing message.
Definition dmusic.h:187
@ DmLogLevel_DEBUG
The log message is a debug message.
Definition dmusic.h:184
@ DmLogLevel_WARN
The log message indicates a warning.
Definition dmusic.h:178
@ DmLogLevel_FATAL
The log message indicates a fatal error.
Definition dmusic.h:172
@ DmLogLevel_INFO
The log message is informational.
Definition dmusic.h:181
@ DmLogLevel_ERROR
The log message indicates an error.
Definition dmusic.h:175
DmLoaderOptions
Configuration flags for DirectMusic Loaders.
Definition dmusic.h:369
struct DmLoader DmLoader
Represents a DirectMusic Loader.
Definition dmusic.h:293
DmResult DmLoader_create(DmLoader **slf, DmLoaderOptions opt)
Create a new DirectMusic Loader object.
void * DmLoaderResolverCallback(void *ctx, char const *file, size_t *len)
A function used to look up and read in DirectMusic objects by file name.
Definition dmusic.h:392
DmResult DmLoader_getSegment(DmLoader *slf, char const *name, DmSegment **segment)
Get a segment from the loader's cache or load it by file name.
void DmLoader_release(DmLoader *slf)
Subtract one from the reference count of a loader.
DmResult DmLoader_addResolver(DmLoader *slf, DmLoaderResolverCallback *resolve, void *ctx)
Add a resolver to the loader.
DmLoader * DmLoader_retain(DmLoader *slf)
Add one to the reference count of a loader.
@ DmLoader_DOWNLOAD
Automatically download references.
Definition dmusic.h:371
@ DmLoader_DEFAULT
Default options for loader objects.
Definition dmusic.h:374
DmResult DmPerformance_playSegment(DmPerformance *slf, DmSegment *sgt, DmTiming timing)
Schedule a new segment to be played by the given performance.
void DmPerformance_release(DmPerformance *slf)
Subtract one from the reference count of a performance.
struct DmPerformance DmPerformance
Represents a DirectMusic Performance.
Definition dmusic.h:300
DmResult DmPerformance_playTransition(DmPerformance *slf, DmSegment *sgt, DmEmbellishmentType embellishment, DmTiming timing)
Schedule a new segment to play by the given performance with a transition.
DmResult DmPerformance_renderPcm(DmPerformance *slf, void *buf, size_t num, DmRenderOptions opts)
Render a given number of PCM samples from a performance.
DmPerformance * DmPerformance_retain(DmPerformance *slf)
Add one to the reference count of a performance.
DmResult DmPerformance_create(DmPerformance **slf, uint32_t rate)
Create a new DirectMusic Performance object.
DmTiming
Definition dmusic.h:473
void DmPerformance_setVolume(DmPerformance *slf, float vol)
Set the playback volume of a performance.
DmRenderOptions
Definition dmusic.h:462
DmEmbellishmentType
Embellishment types for choosing transition patterns.
Definition dmusic.h:488
@ DmTiming_INSTANT
Timing flag indicating start at the next possible tick.
Definition dmusic.h:475
@ DmTiming_MEASURE
Timing flag indicating start at the next possible measure boundary.
Definition dmusic.h:484
@ DmTiming_BEAT
Timing flag indicating start at the next possible beat boundary.
Definition dmusic.h:481
@ DmTiming_GRID
Timing flag indicating start at the next possible grid boundary.
Definition dmusic.h:478
@ DmRender_STEREO
Render flags to request stereo PCM rendering.
Definition dmusic.h:470
@ DmRender_SHORT
Render format flag to request rendering of int16_t samples.
Definition dmusic.h:464
@ DmRender_FLOAT
Render format flag to request rendering of float samples.
Definition dmusic.h:467
@ DmEmbellishment_NONE
Don't choose a pattern.
Definition dmusic.h:490
@ DmEmbellishment_END
Only choose patterns with the 'end' embellishment.
Definition dmusic.h:505
@ DmEmbellishment_GROOVE
Only choose patterns with the default 'groove' embellishment.
Definition dmusic.h:493
@ DmEmbellishment_BREAK
Only choose patterns with the 'break' embellishment.
Definition dmusic.h:502
@ DmEmbellishment_INTRO
Only choose patterns with the 'intro' embellishment.
Definition dmusic.h:499
@ DmEmbellishment_END_AND_INTRO
Choose two patterns, one with the 'end' embellishment from the playing segment and one with the 'intr...
Definition dmusic.h:510
@ DmEmbellishment_FILL
Only choose patterns with the 'fill' embellishment.
Definition dmusic.h:496
DmSegment * DmSegment_retain(DmSegment *slf)
Add one to the reference count of a segment.
DmResult DmSegment_download(DmSegment *slf, DmLoader *loader)
Download all resources needed by the segment.
DmGuid const * DmSegment_getGuid(DmSegment const *slf)
Get the GUID of the given segment.
char const * DmSegment_getName(DmSegment const *slf)
Get the name of the given segment.
struct DmSegment DmSegment
Represents a DirectMusic Segment.
Definition dmusic.h:286
void DmSegment_release(DmSegment *slf)
Subtract one from the reference count of a segment.
uint32_t DmSegment_getRepeats(DmSegment const *slf)
Get the number of times the segment repeats.
double DmSegment_getLength(DmSegment const *slf)
Get the length of the given segment in seconds.
Contains a 128-bit GUID (aka UUID) value.
Definition dmusic.h:74
uint8_t data[16]
The bytes representing the GUID's value.
Definition dmusic.h:76