Chords are built by stacking scale thirds rather than from a quality table, so the chord follows the degree automatically -- in C major, Alt+3 on C gives C major, on D gives D minor, on B gives B diminished. Toggling delegates to toggleCell, so chord tones inherit hold-mode joining, splitting and trimming unchanged. Velocity keys act on the note under the cursor if there is one, and on the default for new notes otherwise, announcing which. That avoids a mode switch between setting a level to draw at and shaping dynamics after the fact. Also fixes install.ps1 failing to resolve its own directory: $PSScriptRoot is not reliably populated during parameter binding, so it is resolved in the body. Tests cover chord quality per scale degree and range clamping.
20 lines
626 B
Lua
20 lines
626 B
Lua
-- MIDI Grid: toggle a diatonic seventh chord on the cursor pitch
|
|
local dir = ({ reaper.get_action_context() })[2]:match("@?(.*[\\/])")
|
|
local G = dofile(dir .. "midigrid_lib.lua")
|
|
|
|
if not G.isActive() then return end
|
|
|
|
local hwnd, take, err = G.editor()
|
|
if not take then G.say(err) return end
|
|
|
|
local ps = G.chordPitches(G.getPitch(hwnd), 4)
|
|
if not ps then G.say("No room for a chord here") return end
|
|
|
|
local state = G.toggleChord(take, ps)
|
|
|
|
local names = {}
|
|
for _, p in ipairs(ps) do names[#names + 1] = G.noteName(p) end
|
|
G.say("Seventh " .. state .. ", " .. table.concat(names, ", "))
|
|
|
|
if state == "on" then G.preview(ps) end
|