mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(gioui): add buttons to save and load instrument
This commit is contained in:
parent
2a9284473a
commit
485b783341
@ -84,6 +84,46 @@ func (t *Tracker) saveSong(filename string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracker) SaveInstrument() bool {
|
||||||
|
filename, err := dialog.File().Filter("Sointu YAML instrument", "yml").Filter("Sointu JSON song", "json").Title(fmt.Sprintf("Save instrument %v", t.Instrument().Name)).Save()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var extension = filepath.Ext(filename)
|
||||||
|
var contents []byte
|
||||||
|
if extension == "json" {
|
||||||
|
contents, err = json.Marshal(t.Instrument())
|
||||||
|
} else {
|
||||||
|
contents, err = yaml.Marshal(t.Instrument())
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if extension == "" {
|
||||||
|
filename = filename + ".yml"
|
||||||
|
}
|
||||||
|
ioutil.WriteFile(filename, contents, 0644)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracker) LoadInstrument() {
|
||||||
|
filename, err := dialog.File().Filter("Sointu YAML instrument", "yml").Filter("Sointu JSON instrument", "json").Title("Load instrument").Load()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bytes, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var instrument sointu.Instrument
|
||||||
|
if errJSON := json.Unmarshal(bytes, &instrument); errJSON != nil {
|
||||||
|
if errYaml := yaml.Unmarshal(bytes, &instrument); errYaml != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.SetInstrument(instrument)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tracker) exportWav(pcm16 bool) {
|
func (t *Tracker) exportWav(pcm16 bool) {
|
||||||
filename, err := dialog.File().Filter(".wav file", "wav").Title("Export .wav").Save()
|
filename, err := dialog.File().Filter(".wav file", "wav").Title("Export .wav").Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,6 +77,16 @@ func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
|||||||
copyInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
copyInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
copyInstrumentBtnStyle.Color = primaryColor
|
copyInstrumentBtnStyle.Color = primaryColor
|
||||||
|
|
||||||
|
saveInstrumentBtnStyle := material.IconButton(t.Theme, t.SaveInstrumentBtn, widgetForIcon(icons.ContentSave))
|
||||||
|
saveInstrumentBtnStyle.Background = transparent
|
||||||
|
saveInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
|
saveInstrumentBtnStyle.Color = primaryColor
|
||||||
|
|
||||||
|
loadInstrumentBtnStyle := material.IconButton(t.Theme, t.LoadInstrumentBtn, widgetForIcon(icons.FileFolderOpen))
|
||||||
|
loadInstrumentBtnStyle.Background = transparent
|
||||||
|
loadInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
|
loadInstrumentBtnStyle.Color = primaryColor
|
||||||
|
|
||||||
deleteInstrumentBtnStyle := material.IconButton(t.Theme, t.DeleteInstrumentBtn, widgetForIcon(icons.ActionDelete))
|
deleteInstrumentBtnStyle := material.IconButton(t.Theme, t.DeleteInstrumentBtn, widgetForIcon(icons.ActionDelete))
|
||||||
deleteInstrumentBtnStyle.Background = transparent
|
deleteInstrumentBtnStyle.Background = transparent
|
||||||
deleteInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
deleteInstrumentBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
||||||
@ -99,6 +109,8 @@ func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
|||||||
return dims
|
return dims
|
||||||
}),
|
}),
|
||||||
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
|
||||||
|
layout.Rigid(saveInstrumentBtnStyle.Layout),
|
||||||
|
layout.Rigid(loadInstrumentBtnStyle.Layout),
|
||||||
layout.Rigid(copyInstrumentBtnStyle.Layout),
|
layout.Rigid(copyInstrumentBtnStyle.Layout),
|
||||||
layout.Rigid(deleteInstrumentBtnStyle.Layout))
|
layout.Rigid(deleteInstrumentBtnStyle.Layout))
|
||||||
}
|
}
|
||||||
@ -119,6 +131,13 @@ func (t *Tracker) layoutInstrumentHeader(gtx C) D {
|
|||||||
for t.ConfirmInstrDelete.BtnCancel.Clicked() {
|
for t.ConfirmInstrDelete.BtnCancel.Clicked() {
|
||||||
t.ConfirmInstrDelete.Visible = false
|
t.ConfirmInstrDelete.Visible = false
|
||||||
}
|
}
|
||||||
|
for t.SaveInstrumentBtn.Clicked() {
|
||||||
|
t.SaveInstrument()
|
||||||
|
}
|
||||||
|
|
||||||
|
for t.LoadInstrumentBtn.Clicked() {
|
||||||
|
t.LoadInstrument()
|
||||||
|
}
|
||||||
return Surface{Gray: 37, Focus: t.EditMode() == tracker.EditUnits || t.EditMode() == tracker.EditParameters}.Layout(gtx, header)
|
return Surface{Gray: 37, Focus: t.EditMode() == tracker.EditUnits || t.EditMode() == tracker.EditParameters}.Layout(gtx, header)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ type Tracker struct {
|
|||||||
SongLength *NumberInput
|
SongLength *NumberInput
|
||||||
PanicBtn *widget.Clickable
|
PanicBtn *widget.Clickable
|
||||||
CopyInstrumentBtn *widget.Clickable
|
CopyInstrumentBtn *widget.Clickable
|
||||||
|
SaveInstrumentBtn *widget.Clickable
|
||||||
|
LoadInstrumentBtn *widget.Clickable
|
||||||
ParameterList *layout.List
|
ParameterList *layout.List
|
||||||
ParameterScrollBar *ScrollBar
|
ParameterScrollBar *ScrollBar
|
||||||
Parameters []*ParameterWidget
|
Parameters []*ParameterWidget
|
||||||
@ -145,6 +147,8 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService, syn
|
|||||||
ClearUnitBtn: new(widget.Clickable),
|
ClearUnitBtn: new(widget.Clickable),
|
||||||
PanicBtn: new(widget.Clickable),
|
PanicBtn: new(widget.Clickable),
|
||||||
CopyInstrumentBtn: new(widget.Clickable),
|
CopyInstrumentBtn: new(widget.Clickable),
|
||||||
|
SaveInstrumentBtn: new(widget.Clickable),
|
||||||
|
LoadInstrumentBtn: new(widget.Clickable),
|
||||||
TrackHexCheckBox: new(widget.Bool),
|
TrackHexCheckBox: new(widget.Bool),
|
||||||
Menus: make([]Menu, 2),
|
Menus: make([]Menu, 2),
|
||||||
MenuBar: make([]widget.Clickable, 2),
|
MenuBar: make([]widget.Clickable, 2),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user