Example #1
0
func link(elements ...*gst.Element) {
	var src *gst.Element
	for _, sink := range elements {
		if err == nil && src != nil {
			if !src.Link(sink) {
				err = fmt.Errorf("Failed to link %s:%s -> %s:%s", src.Type(), src.GetName(), sink.Type(), sink.GetName())
			}
		}
		src = sink
	}
}
Example #2
0
func setProperty(element *gst.Element, name string, value interface{}) {
	if err == nil {
		element.SetProperty(name, value)
	}
}
Example #3
0
File: main.go Project: Depado/gofip
// Initializes the GUI. Function is passed to ui.Do.
func initGui() {
	var cs, ps, ns song
	var player *gst.Element
	var playing bool

	// Creates the initial songs that will be used as long as the program runs.
	cs = song{api: &current.Current.songAPIType}
	ps = song{api: &current.Previous1.songAPIType}
	// ps2 := song{api: &current.Previous2.songAPIType}
	ns = song{api: &current.Next1.songAPIType}
	// ns2 := song{api: &current.Next2.songAPIType}

	// Creates the player and the controls for the player (as well as label).
	player = initPlayer()
	playing = true
	psl := ui.NewLabel("Currently Playing")
	ppbtn := ui.NewButton("Pause")
	ppbtn.OnClicked(func() {
		if playing {
			ppbtn.SetText("Play")
			player.SetState(gst.STATE_PAUSED)
			psl.SetText("Currently Paused")
		} else {
			ppbtn.SetText("Pause")
			psl.SetText("Currently Playing")
			player.SetState(gst.STATE_PLAYING)
		}
		playing = !playing
	})

	// Creates the notification system
	nt := notificator.New(notificator.Options{
		DefaultIcon: "icon/default.png",
		AppName:     "GoFip",
	})

	// Notification settings. Will be passed to the updateGui goroutine to Check
	// whether or not to send a system notification when the music changes.
	ntc := ui.NewCheckbox("Notifications")
	ntc.SetChecked(true)
	// Defines a closableTicker that is used in the updateGui goroutine
	// This allows to close the ticker when the setting button is unchecked.
	ct := closableTicker{
		ticker: time.NewTicker(1 * time.Minute),
		halt:   make(chan bool, 1),
	}
	prc := ui.NewCheckbox("Periodic Check")
	prc.SetChecked(true)
	prc.OnToggled(func() {
		if !prc.Checked() {
			ct.stop()
		} else {
			ct = closableTicker{
				ticker: time.NewTicker(1 * time.Minute),
				halt:   make(chan bool, 1),
			}
			go updateGui(ct, nt, ntc, &cs, &ps, &ns)
		}
	})

	// Start the goroutine to update the GUI every minute (default behaviour)
	// Uses the closableTicker defined earlier so the goroutine can be stopped.
	go updateGui(ct, nt, ntc, &cs, &ps, &ns)

	// Creating the tabs with the songs as well as settings and credits.
	createTabs(&cs, &ps, &ns)
	ts := ui.NewTab()
	ts.Append("Current", cs.stack)
	ts.Append("Previous", ps.stack)
	ts.Append("Next", ns.stack)
	ts.Append("Settings", ui.NewVerticalStack(ntc, prc))
	ts.Append("Credits", ui.NewLabel("Depado 2015"))

	// Creates the main vertical stack that is passed to the main window.
	mvs := ui.NewVerticalStack(ts, ppbtn, psl)
	// The tab control must be set to stretchy otherwise it won't display the content.
	mvs.SetStretchy(0)

	// Creates the main window and the behaviour on close event.
	window = ui.NewWindow("GoFIP", width, height, mvs)
	window.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	window.Show()

	// Starts the player once the window is shown.
	player.SetState(gst.STATE_PLAYING)
}