Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 104 lines (79 sloc) 3.175 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/*
A binding of SDL_mixer.

The binding works pretty much the same as the original, although a few
functions have been changed to be in a more object-oriented style
(eg. Rather than mixer.FreeMusic(song) it's song.Free() )
*/
package mixer

// #cgo pkg-config: sdl
// #cgo LDFLAGS: -lSDL_mixer
// #include "SDL_mixer.h"
import "C"
import "unsafe"

// A music file.
type Music struct {
cmusic *C.Mix_Music
}

// Initializes SDL_mixer. Return 0 if successful and -1 if there were
// initialization errors.
func OpenAudio(frequency int, format uint16, channels, chunksize int) int {
return int(C.Mix_OpenAudio(C.int(frequency), C.Uint16(format),
C.int(channels), C.int(chunksize)))
}

// Shuts down SDL_mixer.
func CloseAudio() { C.Mix_CloseAudio() }

// Loads a music file to use.
func LoadMUS(file string) *Music {
cfile := C.CString(file)
cmusic := C.Mix_LoadMUS(cfile)
C.free(unsafe.Pointer(cfile))

if cmusic == nil {
return nil
}

return &Music{cmusic}
}

// Frees the loaded music file.
func (m *Music) Free() { C.Mix_FreeMusic(m.cmusic) }

// Play the music and loop a specified number of times. Passing -1 makes
// the music loop continuously.
func (m *Music) PlayMusic(loops int) int {
return int(C.Mix_PlayMusic(m.cmusic, C.int(loops)))
}

// Play the music and loop a specified number of times. During the first loop,
// fade in for the milliseconds specified. Passing -1 makes the music loop
// continuously. The fade-in effect only occurs during the first loop.
func (m *Music) FadeInMusic(loops, ms int) int {
return int(C.Mix_FadeInMusic(m.cmusic, C.int(loops), C.int(ms)))
}

// Same as FadeInMusic, only with a specified position to start the music at.
func (m *Music) FadeInMusicPos(loops, ms int, position float32) int {
return int(C.Mix_FadeInMusicPos(m.cmusic, C.int(loops), C.int(ms),
C.double(position)))
}

// Sets the volume to the value specified.
func VolumeMusic(volume int) int { return int(C.Mix_VolumeMusic(C.int(volume))) }

// Pauses the music playback.
func PauseMusic() { C.Mix_PauseMusic() }

// Unpauses the music.
func ResumeMusic() { C.Mix_ResumeMusic() }

// Rewinds music to the start.
func RewindMusic() { C.Mix_RewindMusic() }

// Sets the position of the currently playing music.
func SetMusicPosition(position float32) int {
return int(C.Mix_SetMusicPosition(C.double(position)))
}

// Halt playback of music.
func HaltMusic() { C.Mix_HaltMusic() }

// Fades out music over the milliseconds specified. Music is halted after
// the fade out is completed.
func FadeOutMusic(ms int) int { return int(C.Mix_FadeOutMusic(C.int(ms))) }

// Returns the type of the currently playing music.
func GetMusicType() int { return int(C.Mix_GetMusicType(nil)) }

// Returns the type of the music.
func (m *Music) GetMusicType() int { return int(C.Mix_GetMusicType(m.cmusic)) }

// Returns 1 if music is currently playing and 0 if not.
func PlayingMusic() int { return int(C.Mix_PlayingMusic()) }

// Returns 1 if music is paused and 0 if not.
func PausedMusic() int { return int(C.Mix_PausedMusic()) }

// Tells you whether music is fading in, out, or not at all.
func FadingMusic() int { return int(C.Mix_FadingMusic()) }
Something went wrong with that request. Please try again.