add comments
This commit is contained in:
parent
3981512edb
commit
9e01387460
13
cmd/root.go
13
cmd/root.go
|
@ -27,6 +27,9 @@ import (
|
||||||
var presets []string
|
var presets []string
|
||||||
var transition bool
|
var transition bool
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handleWindowEvent handles window events like resizing.
|
||||||
|
*/
|
||||||
func handleWindowEvent(event *sdl.WindowEvent, m *milkDropWindow) {
|
func handleWindowEvent(event *sdl.WindowEvent, m *milkDropWindow) {
|
||||||
switch event.Event {
|
switch event.Event {
|
||||||
case sdl.WINDOWEVENT_RESIZED:
|
case sdl.WINDOWEVENT_RESIZED:
|
||||||
|
@ -35,6 +38,9 @@ func handleWindowEvent(event *sdl.WindowEvent, m *milkDropWindow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handleKeyboardEvent handles keyboard inputs.
|
||||||
|
*/
|
||||||
func handleKeyboardEvent(event *sdl.KeyboardEvent, m *milkDropWindow) {
|
func handleKeyboardEvent(event *sdl.KeyboardEvent, m *milkDropWindow) {
|
||||||
scancode := event.Keysym.Scancode
|
scancode := event.Keysym.Scancode
|
||||||
if event.Type == sdl.KEYDOWN && scancode == sdl.SCANCODE_RIGHT && event.Repeat == 0 {
|
if event.Type == sdl.KEYDOWN && scancode == sdl.SCANCODE_RIGHT && event.Repeat == 0 {
|
||||||
|
@ -44,6 +50,10 @@ func handleKeyboardEvent(event *sdl.KeyboardEvent, m *milkDropWindow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handleEvent passes the event to a more specific function based on its type.
|
||||||
|
* It returns false if the program should quit, true otherwise.
|
||||||
|
*/
|
||||||
func handleEvent(event sdl.Event, m *milkDropWindow) bool {
|
func handleEvent(event sdl.Event, m *milkDropWindow) bool {
|
||||||
switch event.(type) {
|
switch event.(type) {
|
||||||
case *sdl.QuitEvent:
|
case *sdl.QuitEvent:
|
||||||
|
@ -59,6 +69,9 @@ func handleEvent(event sdl.Event, m *milkDropWindow) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* milkbucket sets up the program and starts a rendering loop.
|
||||||
|
*/
|
||||||
func milkbucket(cmd *cobra.Command, args []string) {
|
func milkbucket(cmd *cobra.Command, args []string) {
|
||||||
stat, err := os.Stdin.Stat()
|
stat, err := os.Stdin.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -34,8 +34,11 @@ import (
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// bufSize is the size of the buffer to store data from stdin. NOTE: this might
|
||||||
|
// need tuning.
|
||||||
const bufSize uint = 2048
|
const bufSize uint = 2048
|
||||||
|
|
||||||
|
// milkDropWindow represents the window projectm will render visualizations in.
|
||||||
type milkDropWindow struct {
|
type milkDropWindow struct {
|
||||||
window *sdl.Window
|
window *sdl.Window
|
||||||
context sdl.GLContext
|
context sdl.GLContext
|
||||||
|
@ -43,6 +46,9 @@ type milkDropWindow struct {
|
||||||
preset *ring.Ring
|
preset *ring.Ring
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* setupPresets initializes a ring to store the passed presets in.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) setupPresets(presets []string) {
|
func (m *milkDropWindow) setupPresets(presets []string) {
|
||||||
m.preset = ring.New(len(presets))
|
m.preset = ring.New(len(presets))
|
||||||
for _, preset := range presets {
|
for _, preset := range presets {
|
||||||
|
@ -51,16 +57,28 @@ func (m *milkDropWindow) setupPresets(presets []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevPreset sets the milkDropWindow's preset to the one after the current
|
||||||
|
* preset.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) nextPreset(smooth bool) {
|
func (m *milkDropWindow) nextPreset(smooth bool) {
|
||||||
m.preset = m.preset.Next()
|
m.preset = m.preset.Next()
|
||||||
m.loadPreset(smooth)
|
m.loadPreset(smooth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevPreset sets the milkDropWindow's preset to the one before the current
|
||||||
|
* preset.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) prevPreset(smooth bool) {
|
func (m *milkDropWindow) prevPreset(smooth bool) {
|
||||||
m.preset = m.preset.Prev()
|
m.preset = m.preset.Prev()
|
||||||
m.loadPreset(smooth)
|
m.loadPreset(smooth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* newMilkDropWindow returns a new milkDropWindow with the given width and
|
||||||
|
* height, and sets presets available to the window.
|
||||||
|
*/
|
||||||
func newMilkDropWindow(width, height int32, presets []string) (*milkDropWindow, error) {
|
func newMilkDropWindow(width, height int32, presets []string) (*milkDropWindow, error) {
|
||||||
var m milkDropWindow
|
var m milkDropWindow
|
||||||
var err error
|
var err error
|
||||||
|
@ -87,12 +105,20 @@ func newMilkDropWindow(width, height int32, presets []string) (*milkDropWindow,
|
||||||
return &m, nil
|
return &m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* destroy handles cleanup of the milkDropWindow.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) destroy() {
|
func (m *milkDropWindow) destroy() {
|
||||||
C.projectm_destroy(m.handle)
|
C.projectm_destroy(m.handle)
|
||||||
sdl.GLDeleteContext(m.context)
|
sdl.GLDeleteContext(m.context)
|
||||||
m.window.Destroy()
|
m.window.Destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* loadPreset loads the preset file currently pointed to by m.preset. smooth
|
||||||
|
* determines whether there is a smooth transition between the current preset
|
||||||
|
* and the new preset.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) loadPreset(smooth bool) {
|
func (m *milkDropWindow) loadPreset(smooth bool) {
|
||||||
preset := m.preset.Value.(string)
|
preset := m.preset.Value.(string)
|
||||||
cPreset := C.CString(preset)
|
cPreset := C.CString(preset)
|
||||||
|
@ -100,6 +126,10 @@ func (m *milkDropWindow) loadPreset(smooth bool) {
|
||||||
C.projectm_load_preset_file(m.handle, cPreset, C.bool(smooth))
|
C.projectm_load_preset_file(m.handle, cPreset, C.bool(smooth))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* render reads data from stdin and passes the data to projectm for rendering.
|
||||||
|
* It returns a bool for if the program should keep running and an error.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) render() (bool, error) {
|
func (m *milkDropWindow) render() (bool, error) {
|
||||||
var audioData [bufSize]int16
|
var audioData [bufSize]int16
|
||||||
|
|
||||||
|
@ -118,6 +148,9 @@ func (m *milkDropWindow) render() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* resize informs projectm of the new window size.
|
||||||
|
*/
|
||||||
func (m *milkDropWindow) resize(w, h int32) {
|
func (m *milkDropWindow) resize(w, h int32) {
|
||||||
C.projectm_set_window_size(m.handle, C.ulong(w), C.ulong(h))
|
C.projectm_set_window_size(m.handle, C.ulong(w), C.ulong(h))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue