Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix: Add support for the majority of missing & new functions in newer SDL_mixer versions #612

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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