Skip to content

Commit

Permalink
mix: Add support for the majority of missing & new functions in newer…
Browse files Browse the repository at this point in the history
… SDL_mixer versions (#612)

* mix: Added GetMusicLoopLengthTime and MusicDuration

* mix: Update and add missing documentation links

* mix: Added support for missing and new functions

Including SDL_mixer version 2.0.0, 2.0.2, 2.6.0, and 2.8.0
Added the following functions:

in sdl_mixer.go:
- LinkedVersion
- HasChunkDecoder
- HasMusicDecoder
- GetMusicAlbumTag
- GetMusicArtistTag
- GetMusicCopyrightTag
- GetMusicLoopEndTime
- GetMusicLoopStartTime
- GetMusicPosition
- GetMusicTitle
- GetMusicTitleTag
- GetMusicVolume
- MasterVolume
- ModMusicJumpToOrder
- GetNumTracks
- PauseAudio
- StartTrack

in midi.go:
- SetTimidityCfg

* mix: Fix function name typo in definition
  • Loading branch information
Necklaces authored Dec 5, 2024
1 parent c7c713d commit 83cbc51
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 85 deletions.
42 changes: 34 additions & 8 deletions mix/TODO.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
## 2.8.0

- [x] Mix_GetNumTracks
- [x] Mix_PauseAudio
- [x] Mix_StartTrack

## 2.6.0

- [x] Mix_GetMusicAlbumTag
- [x] Mix_GetMusicArtistTag
- [x] Mix_GetMusicCopyrightTag
- [x] Mix_GetMusicLoopEndTime
- [x] Mix_GetMusicLoopLengthTime
- [x] Mix_GetMusicLoopStartTime
- [x] Mix_GetMusicPosition
- [x] Mix_GetMusicTitle
- [x] Mix_GetMusicTitleTag
- [x] Mix_GetMusicVolume
- [x] Mix_HasMusicDecoder
- [x] Mix_MasterVolume
- [x] Mix_ModMusicJumpToOrder
- [x] Mix_MusicDuration
- [x] Mix_SetTimidityCfg

## 2.0.2

- [ ] OpenAudioDevice()
- [x] OpenAudioDevice()
- [x] Mix_HasChunkDecoder

## 2.0.0

- [ ] UnregisterEffect()
- [ ] SetPostMix()
- [ ] HookMusic()
- [ ] HookMusicFinished()
- [ ] ChannelFinished()
- [ ] RegisterEffect()
- [ ] UnregisterAllEffects()
- [ ] EachSoundFont()
- [x] SetPostMix()
- [x] HookMusic()
- [x] HookMusicFinished()
- [x] ChannelFinished()
- [x] RegisterEffect()
- [x] UnregisterAllEffects()
- [x] EachSoundFont()
- [x] LinkedVersion()
24 changes: 24 additions & 0 deletions mix/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ package mix
//#include <stdlib.h>
//#include "sdl_mixer_wrapper.h"
//extern int callEachSoundFont(char* str, void* udata);
//
//#if !(SDL_MIXER_VERSION_ATLEAST(2,6,0))
//
//#if defined(WARN_OUTDATED)
//#pragma message("Mix_SetTimidityCfg is not supported before SDL 2.6.0")
//#endif
//
//int Mix_SetTimidityCfg(const char *path)
//{
// return 0;
//}
//
//#endif
import "C"
import "unsafe"

Expand All @@ -16,19 +29,30 @@ func callEachSoundFont(str *C.char, udata unsafe.Pointer) C.int {
}

// EachSoundFont iterates over SoundFonts paths to use by supported MIDI backends.
// (https://wiki.libsdl.org/SDL2_mixer/Mix_EachSoundFont)
func EachSoundFont(function func(string) int) int {
eachSoundFontFunc = function
return int(C.Mix_EachSoundFont((*[0]byte)(C.callEachSoundFont), nil))
}

// SetSoundFonts sets SoundFonts paths to use by supported MIDI backends.
// (https://wiki.libsdl.org/SDL2_mixer/Mix_SetSoundFonts)
func SetSoundFonts(paths string) bool {
_paths := C.CString(paths)
defer C.free(unsafe.Pointer(_paths))
return int(C.Mix_SetSoundFonts(_paths)) == 0
}

// GetSoundFonts returns SoundFonts paths to use by supported MIDI backends.
// (https://wiki.libsdl.org/SDL2_mixer/Mix_GetSoundFonts)
func GetSoundFonts() string {
return (string)(C.GoString(C.Mix_GetSoundFonts()))
}

// Set full path of the Timidity config file. Returns true if successful, false on error. This is obviously only useful if SDL_mixer is using Timidity internally to play MIDI files.
// (https://wiki.libsdl.org/SDL2_mixer/Mix_SetTimidityCfg)
func SetTimidityCfg(path string) bool {
_path := C.CString(path)
defer C.free(unsafe.Pointer(_path))
return int(C.Mix_SetTimidityCfg(_path)) == 0
}
Loading

0 comments on commit 83cbc51

Please sign in to comment.