From 3f8dfb7f4c2b31d8783e78d21368deacd052442a Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Thu, 19 May 2022 17:50:04 -0400 Subject: [PATCH] main: fix chord voicings Signed-off-by: Chris Waldon --- go.mod | 2 +- main.go | 74 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 2ac20aa..df51491 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( gioui.org v0.0.0-20220517073035-79f037f983a7 + github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 github.com/hajimehoshi/oto/v2 v2.1.0 github.com/lucasb-eyer/go-colorful v1.2.0 golang.org/x/exp v0.0.0-20220516143420-24438e51023a @@ -13,7 +14,6 @@ require ( gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect gioui.org/shader v1.0.6 // indirect github.com/benoitkugler/textlayout v0.1.1 // indirect - github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 // indirect github.com/gioui/uax v0.2.1-0.20220325163150-e3d987515a12 // indirect github.com/go-text/typesetting v0.0.0-20220411150340-35994bc27a7b // indirect golang.org/x/exp/shiny v0.0.0-20220516143420-24438e51023a // indirect diff --git a/main.go b/main.go index c504b25..2d878af 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "io" "log" "math" + "runtime" "strings" "time" @@ -155,6 +156,14 @@ const ( AS5 = 932.3 BF5 = AS5 B5 = 987.8 + C6 = 1046.5 + CS6 = 1108.7 + DF6 = CS6 + D6 = 1174.7 + DS6 = 1244.5 + EF6 = DS6 + E6 = 1318.5 + F6 = 1396.9 IdxBF4 = IdxAS4 IdxDF5 = IdxCS5 @@ -162,6 +171,8 @@ const ( IdxGF5 = IdxFS5 IdxAF5 = IdxGS5 IdxBF5 = IdxAS5 + IdxDF6 = IdxCS6 + IdxEF6 = IdxDS6 ) const ( @@ -180,6 +191,12 @@ const ( IdxA5 IdxAS5 IdxB5 + IdxC6 + IdxCS6 + IdxD6 + IdxDS6 + IdxE6 + IdxF6 IdxMax ) @@ -199,6 +216,12 @@ var freqs = []float64{ IdxA5: A5, IdxAS5: AS5, IdxB5: B5, + IdxC6: C6, + IdxCS6: CS6, + IdxD6: D6, + IdxDS6: DS6, + IdxE6: E6, + IdxF6: F6, } var notes = [][]int{ @@ -211,38 +234,36 @@ var notes = [][]int{ IdxG5: {IdxG5}, IdxA5: {IdxA5}, IdxB5: {IdxB5}, + IdxC6: {IdxC6}, + IdxD6: {IdxD6}, } -var halfStepUp = [][]int{ - IdxA4: {IdxA4 + 1}, - IdxB4: {IdxB4 + 1}, - IdxC5: {IdxC5 + 1}, - IdxD5: {IdxD5 + 1}, - IdxE5: {IdxE5 + 1}, - IdxF5: {IdxF5 + 1}, - IdxG5: {IdxG5 + 1}, - IdxA5: {IdxA5 + 1}, - IdxB5: {IdxB5 + 1}, -} +var halfStepUp = func() [][]int { + steps := make([][]int, len(notes)) + for i := range notes { + steps[i] = []int{i + 1} + } + return steps +}() var majChords = [][]int{ IdxA4: {IdxA4, IdxC5, IdxE5}, IdxB4: {IdxB4, IdxD5, IdxF5}, IdxC5: {IdxC5, IdxE5, IdxG5}, - IdxD5: {IdxD5, IdxF5, IdxA4}, - IdxE5: {IdxE5, IdxG5, IdxB4}, - IdxF5: {IdxF5, IdxA4, IdxC5}, - IdxG5: {IdxG5, IdxB4, IdxD5}, + IdxD5: {IdxD5, IdxF5, IdxA5}, + IdxE5: {IdxE5, IdxG5, IdxB5}, + IdxF5: {IdxF5, IdxA5, IdxC6}, + IdxG5: {IdxG5, IdxB5, IdxD6}, } var majExtChords = [][]int{ IdxA4: {IdxA4, IdxC5, IdxE5, IdxG5}, - IdxB4: {IdxB4, IdxD5, IdxF5, IdxA4}, - IdxC5: {IdxC5, IdxE5, IdxG5, IdxB4}, - IdxD5: {IdxD5, IdxF5, IdxA4, IdxC5}, - IdxE5: {IdxE5, IdxG5, IdxB4, IdxD5}, - IdxF5: {IdxF5, IdxA4, IdxC5, IdxE5}, - IdxG5: {IdxG5, IdxB4, IdxD5, IdxF5}, + IdxB4: {IdxB4, IdxD5, IdxF5, IdxA5}, + IdxC5: {IdxC5, IdxE5, IdxG5, IdxB5}, + IdxD5: {IdxD5, IdxF5, IdxA5, IdxC6}, + IdxE5: {IdxE5, IdxG5, IdxB5, IdxD6}, + IdxF5: {IdxF5, IdxA5, IdxC6, IdxE6}, + IdxG5: {IdxG5, IdxB5, IdxD6, IdxF6}, } var keyToIdx = map[string]int{ @@ -406,10 +427,13 @@ func run(w *app.Window) error { } // This editor is needed for JS to properly deliver key events // to us. - med := material.Editor(th, &ed, "") - med.Color = color.NRGBA{} - ed.SetText("") - med.Layout(gtx) + if runtime.GOOS == "js" { + med := material.Editor(th, &ed, "") + med.Color = color.NRGBA{} + ed.SetText("") + med.Layout(gtx) + ed.SetText("") + } event.Frame(gtx.Ops) } case <-ready: -- 2.45.2