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#ifndef DM_STATIC
15 #if defined(_WIN32) || defined(__CYGWIN__)
16 #ifdef DM_BUILD
17 #ifdef __GNUC__
18 #define DMAPI DM_EXTERN __attribute__((dllexport))
19 #else
20 #define DMAPI DM_EXTERN __declspec(dllexport)
21 #endif
22 #else
23 #ifdef __GNUC__
24 #define DMAPI DM_EXTERN __attribute__((dllimport))
25 #else
26 #define DMAPI DM_EXTERN __declspec(dllimport)
27 #endif
28 #endif
29 #define DMINT
30 #else
31 #define DMAPI DM_EXTERN __attribute__((visibility("default")))
32 #define DMINT DM_EXTERN __attribute__((visibility("hidden")))
33 #endif
34#else
35 #define DMAPI DM_EXTERN
36 #define DMINT DM_EXTERN
37#endif
38
40
44
68
80typedef struct DmGuid {
82 uint8_t data[16];
84
94DMAPI size_t DmGuid_toString(DmGuid const* slf, char* out, size_t len);
95
111typedef void* DmMemoryAlloc(void* ctx, size_t len);
112
125typedef void DmMemoryFree(void* ctx, void* ptr);
126
146
157typedef uint32_t DmRng(void* ctx);
158
173DMAPI void Dm_setRandomNumberGenerator(DmRng* rng, void* ctx);
174
195
196typedef void DmLogHandler(void* ctx, DmLogLevel lvl, char const* msg);
197
210DMAPI void Dm_setLogger(DmLogLevel lvl, DmLogHandler* log, void* ctx);
211
220
224
226
289
292typedef struct DmSegment DmSegment;
293
296
299typedef struct DmLoader DmLoader;
300
303
307
310
315
323
339
344DMAPI DmGuid const* DmSegment_getGuid(DmSegment const* slf);
345
350DMAPI char const* DmSegment_getName(DmSegment const* slf);
351
361DMAPI double DmSegment_getLength(DmSegment const* slf);
362
366DMAPI uint32_t DmSegment_getRepeats(DmSegment const* slf);
367
369
372
382
398typedef void* DmLoaderResolverCallback(void* ctx, char const* file, size_t* len);
399
412
417
424DMAPI void DmLoader_release(DmLoader* slf);
425
441
461DMAPI DmResult DmLoader_getSegment(DmLoader* slf, char const* name, DmSegment** segment);
462
464
467
468typedef enum DmRenderOptions {
471
474
478
492
518
527DMAPI DmResult DmPerformance_create(DmPerformance** slf, uint32_t rate);
528
533
541
564
588 DmSegment* sgt,
589 DmEmbellishmentType embellishment,
590 DmTiming timing);
591
615DMAPI DmResult DmPerformance_renderPcm(DmPerformance* slf, void* buf, size_t num, DmRenderOptions opts);
616
621DMAPI void DmPerformance_setVolume(DmPerformance* slf, float vol);
622
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:46
DmLogLevel
The set of message levels supported by the logging facilities.
Definition dmusic.h:176
void DmMemoryFree(void *ctx, void *ptr)
A free-like memory de-allocation function.
Definition dmusic.h:125
void * DmMemoryAlloc(void *ctx, size_t len)
A malloc-like memory allocation function.
Definition dmusic.h:111
uint32_t DmRng(void *ctx)
A rand_r-like random number generation function.
Definition dmusic.h:157
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:60
@ DmResult_INVALID_ARGUMENT
An invalid argument was provided.
Definition dmusic.h:51
@ DmResult_INVALID_STATE
The operation could not be completed because the system is in an invalid state.
Definition dmusic.h:54
@ DmResult_SUCCESS
The operation completed successfully.
Definition dmusic.h:48
@ DmResult_MEMORY_EXHAUSTED
A memory allocation failed.
Definition dmusic.h:57
@ DmResult_FILE_CORRUPT
A resource file could not be parsed.
Definition dmusic.h:63
@ DmResult_MUTEX_ERROR
A mutex could not be locked.
Definition dmusic.h:66
@ DmLogLevel_TRACE
The log message is a tracing message.
Definition dmusic.h:193
@ DmLogLevel_DEBUG
The log message is a debug message.
Definition dmusic.h:190
@ DmLogLevel_WARN
The log message indicates a warning.
Definition dmusic.h:184
@ DmLogLevel_FATAL
The log message indicates a fatal error.
Definition dmusic.h:178
@ DmLogLevel_INFO
The log message is informational.
Definition dmusic.h:187
@ DmLogLevel_ERROR
The log message indicates an error.
Definition dmusic.h:181
DmLoaderOptions
Configuration flags for DirectMusic Loaders.
Definition dmusic.h:375
struct DmLoader DmLoader
Represents a DirectMusic Loader.
Definition dmusic.h:299
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:398
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:377
@ DmLoader_DEFAULT
Default options for loader objects.
Definition dmusic.h:380
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:306
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:479
void DmPerformance_setVolume(DmPerformance *slf, float vol)
Set the playback volume of a performance.
DmRenderOptions
Definition dmusic.h:468
DmEmbellishmentType
Embellishment types for choosing transition patterns.
Definition dmusic.h:494
@ DmTiming_INSTANT
Timing flag indicating start at the next possible tick.
Definition dmusic.h:481
@ DmTiming_MEASURE
Timing flag indicating start at the next possible measure boundary.
Definition dmusic.h:490
@ DmTiming_BEAT
Timing flag indicating start at the next possible beat boundary.
Definition dmusic.h:487
@ DmTiming_GRID
Timing flag indicating start at the next possible grid boundary.
Definition dmusic.h:484
@ DmRender_STEREO
Render flags to request stereo PCM rendering.
Definition dmusic.h:476
@ DmRender_SHORT
Render format flag to request rendering of int16_t samples.
Definition dmusic.h:470
@ DmRender_FLOAT
Render format flag to request rendering of float samples.
Definition dmusic.h:473
@ DmEmbellishment_NONE
Don't choose a pattern.
Definition dmusic.h:496
@ DmEmbellishment_END
Only choose patterns with the 'end' embellishment.
Definition dmusic.h:511
@ DmEmbellishment_GROOVE
Only choose patterns with the default 'groove' embellishment.
Definition dmusic.h:499
@ DmEmbellishment_BREAK
Only choose patterns with the 'break' embellishment.
Definition dmusic.h:508
@ DmEmbellishment_INTRO
Only choose patterns with the 'intro' embellishment.
Definition dmusic.h:505
@ DmEmbellishment_END_AND_INTRO
Choose two patterns, one with the 'end' embellishment from the playing segment and one with the 'intr...
Definition dmusic.h:516
@ DmEmbellishment_FILL
Only choose patterns with the 'fill' embellishment.
Definition dmusic.h:502
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:292
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:80
uint8_t data[16]
The bytes representing the GUID's value.
Definition dmusic.h:82