diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-01-21 15:22:27 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-01-21 15:22:27 (GMT) |
commit | dcd973603f916c8f47f908c2fb628e4219c42cb2 (patch) | |
tree | 78806a7bbc6c0c8149b5b9770d133aeeb5ff433d | |
parent | 17778eeb680e7f140bdbe26a2355f0475d1d3bb9 (diff) |
meter levels works now
-rw-r--r-- | src/rhlibrary/app_window.go | 19 | ||||
-rw-r--r-- | src/rhlibrary/main.go | 10 | ||||
-rw-r--r-- | src/rhlibrary/player_widget.go | 43 |
3 files changed, 59 insertions, 13 deletions
diff --git a/src/rhlibrary/app_window.go b/src/rhlibrary/app_window.go index 1062c5f..fe4dda8 100644 --- a/src/rhlibrary/app_window.go +++ b/src/rhlibrary/app_window.go @@ -29,18 +29,15 @@ import ( "github.com/gotk3/gotk3/gtk" ) -func init() { - gtk.Init(nil) -} - type AppWindow struct { win *gtk.Window player *player.PlayerChan } -func (aw *AppWindow) ShowAndRun() { - aw.win.ShowAll() - gtk.Main() +func (aw *AppWindow) dispatchRequests() { + for { + select {} + } } func (aw *AppWindow) drawSelector(grid *gtk.Grid) (err error) { @@ -59,6 +56,14 @@ func (aw *AppWindow) drawPlayer(grid *gtk.Grid) error { return err } +// ********************************************************* +// Public Interface + +func (aw *AppWindow) ShowAndRun() { + go aw.dispatchRequests() + aw.win.ShowAll() +} + func NewAppWindow(player *player.PlayerChan, width, height int) (aw *AppWindow, err error) { aw = &AppWindow{} aw.player = player diff --git a/src/rhlibrary/main.go b/src/rhlibrary/main.go index a6e37c4..4f339b9 100644 --- a/src/rhlibrary/main.go +++ b/src/rhlibrary/main.go @@ -25,13 +25,15 @@ package main import ( - "code.helsinki.at/rhrd-go/player" - "code.helsinki.at/rhrd-go/rddb" "flag" "fmt" "io/ioutil" "log" "os" + + "code.helsinki.at/rhrd-go/player" + "code.helsinki.at/rhrd-go/rddb" + "github.com/gotk3/gotk3/gtk" ) var ( @@ -75,6 +77,8 @@ func main() { return } + gtk.Init(nil) + db, err := rddb.NewDB(rdconf.Get().(string)) if err != nil { rhl.Println("Error initializing Rivdenll DB:", err) @@ -94,4 +98,6 @@ func main() { return } mw.ShowAndRun() + + gtk.Main() } diff --git a/src/rhlibrary/player_widget.go b/src/rhlibrary/player_widget.go index 7581b45..7da5a44 100644 --- a/src/rhlibrary/player_widget.go +++ b/src/rhlibrary/player_widget.go @@ -25,10 +25,18 @@ package main import ( + "time" + "code.helsinki.at/rhrd-go/player" + "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" ) +const ( + meterDBFloor float64 = 72 // -72 db is the lowest VU value + meterSegments float64 = 30 // meter has 30 elements +) + func addPlayButton(grid *gtk.Grid, p *player.PlayerChan) (err error) { var btn *gtk.Button if btn, err = gtk.ButtonNewFromIconName("media-playback-start", gtk.ICON_SIZE_DIALOG); err != nil { @@ -71,6 +79,16 @@ func addStopButton(grid *gtk.Grid, p *player.PlayerChan) (err error) { return } +func calcMeterLevel(valdb float64) (val float64) { + val = valdb + meterDBFloor + if val < 0 { + val = 0 + } else { + val = (val / meterDBFloor) * meterSegments + } + return +} + func addMeter(grid *gtk.Grid, p *player.PlayerChan) (err error) { var mgrid *gtk.Grid if mgrid, err = gtk.GridNew(); err != nil { @@ -80,16 +98,33 @@ func addMeter(grid *gtk.Grid, p *player.PlayerChan) (err error) { mgrid.SetColumnSpacing(3) var left, right *gtk.LevelBar - if left, err = gtk.LevelBarNewForInterval(0, 30); err != nil { + if left, err = gtk.LevelBarNewForInterval(0, meterSegments); err != nil { return } - if right, err = gtk.LevelBarNewForInterval(0, 30); err != nil { + if right, err = gtk.LevelBarNewForInterval(0, meterSegments); err != nil { return } left.SetMode(gtk.LEVEL_BAR_MODE_DISCRETE) right.SetMode(gtk.LEVEL_BAR_MODE_DISCRETE) - left.SetValue(8) - right.SetValue(17) + + p.AddUpdateHandler(func(length time.Duration, pos time.Duration, meter player.Meter, userdata interface{}) bool { + glib.IdleAdd(func() { + ch := len(meter) + lval := float64(0) + rval := float64(0) + if ch >= 2 { + lval = calcMeterLevel(meter[0].Peak) + rval = calcMeterLevel(meter[1].Peak) + } else if ch == 1 { + lval = calcMeterLevel(meter[0].Peak) + rval = lval + } + left.SetValue(lval) + right.SetValue(rval) + }) + return true + }, nil) + mgrid.Add(left) mgrid.Add(right) |