Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/naivesound/glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
zserge committed Nov 18, 2017
2 parents 1dd8544 + bebb2e3 commit 6cd6545
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
38 changes: 22 additions & 16 deletions cmd/glitch/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -30,7 +31,7 @@ type App struct {
}

func NewApp(config *Config) (app *App, err error) {
app = &App{Config: config}
app = &App{Config: config, AudioDevices: []audio.Device{}, MIDIDevices: []audio.MIDIDevice{}}

loader := &sampleLoader{}
go loader.poll()
Expand Down Expand Up @@ -67,13 +68,28 @@ func NewApp(config *Config) (app *App, err error) {
Height: windowHeight,
Resizable: true,
URL: url,
ExternalInvokeCallback: func(w webview.WebView, data string) {
if data == "__app_js_loaded__" {
app.sync, err = app.webview.Bind("app", app)
if err != nil {
log.Println(err)
} else {
w.Eval(`init()`)
go func() {
for range app.notify {
app.webview.Dispatch(func() {
app.AudioDevice = app.audio.Current().ID
app.AudioDevices = app.audio.Devices()
app.MIDIDevices = app.midi.Devices()
app.sync()
})
}
}()
}
}
},
})

if app.sync, err = app.webview.Bind("app", app); err != nil {
app.Destroy()
return nil, err
}

for midi, connect := range config.MIDI {
app.SelectMIDI(midi, connect)
}
Expand All @@ -83,16 +99,6 @@ func NewApp(config *Config) (app *App, err error) {
}

func (app *App) Run() {
go func() {
for range app.notify {
app.webview.Dispatch(func() {
app.AudioDevice = app.audio.Current().ID
app.AudioDevices = app.audio.Devices()
app.MIDIDevices = app.midi.Devices()
app.sync()
})
}
}()
app.webview.Run()
}

Expand Down
Loading

0 comments on commit 6cd6545

Please sign in to comment.