From 18cfda27f63fd0b1c30591057207697aec957b3a Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Sat, 13 Apr 2024 14:00:31 +0200 Subject: [PATCH] Add Shifter --- lua/liam.lua | 36 +++++++++++++++++---- lua/shifting.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 7 +++++ 3 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 lua/shifting.lua diff --git a/lua/liam.lua b/lua/liam.lua index 886a2e4..94ea742 100755 --- a/lua/liam.lua +++ b/lua/liam.lua @@ -13,6 +13,7 @@ local displaying = require('displaying') local tonewheeling = require('tonewheeling') local pianoteqing = require('pianoteqing') local gatekeeping = require('gatekeeping') +local shifting = require('shifting') local tags = { clock = 'clock', @@ -94,6 +95,31 @@ local tonewheel = tonewheeling.Tonewheel:new { } interface[6] = tonewheel +local shifter1 = shifting.Shifter:new { + channel = 0x0, + interface = interface --FIXME +} +interface[7] = shifter1 + +local shifter2 = shifting.Shifter:new { + channel = 0x1, + interface = interface --FIXME +} +interface[8] = shifter2 + +local shifter3 = shifting.Shifter:new { + channel = 0x2, + interface = interface --FIXME +} +interface[9] = shifter3 + +local shifter4 = shifting.Shifter:new { + channel = 0x3, + interface = interface --FIXME +} +interface[10] = shifter4 +interface.index = 9 --FIXME + local monitor = monitoring.Monitor:new() local pk88 = { @@ -164,23 +190,21 @@ function process(nframes) if gatekeeper1:pass(msg) then local msg = table.pack(table.unpack(msg)) - msg[1] = (msg[1] & 0xf0) | 0x00 -- channel 1 - fh2.writer:write(time, msg) + fh2.writer:write(time, shifter1:shift(msg)) end if gatekeeper2:pass(msg) then local msg = table.pack(table.unpack(msg)) - msg[1] = (msg[1] & 0xf0) | 0x01 -- channel 2 - fh2.writer:write(time, msg) + fh2.writer:write(time, shifter2:shift(msg)) end if not pianoteq.mute and gatekeeper3:pass(msg) then - piano.writer:write(time, msg) + piano.writer:write(time, shifter3:shift(msg)) end if not tonewheel.mute and gatekeeper4:pass(msg) then - bfree.writer:write(time, msg) + bfree.writer:write(time, shifter4:shift(msg)) end elseif source == fh2.reader then monitor:write(time, msg) diff --git a/lua/shifting.lua b/lua/shifting.lua new file mode 100644 index 0000000..d12259b --- /dev/null +++ b/lua/shifting.lua @@ -0,0 +1,81 @@ +-- SPDX-FileCopyrightText: Hanspeter Portner +-- SPDX-License-Identifier: Artistic-2.0 + +local tooling = require('tooling') +local interfacing = require('interfacing') + +local Offset = tooling.Class:new { + color_off = 0x1, + color_act = 0xd, + color_hot = 0x3, + + down = function(self, time) + self.pressed = true + + self.page:set_offset(time, self.offset) + end, + + up = function(self, time) + self.pressed = false + end, + + color = function(self) + if self.pressed then + return self.color_hot + elseif self.offset == self.page.offset then + return self.color_act + else + return self.color_off + end + end +} + +local Shifter = interfacing.Page:new { + channel = 0x0, + offset = 0, + + -- private + octave_offset = 0, + note_offset = 0, + + set_offset = function(self, time, offset) + self.offset = offset + self:refresh(time) + end, + + init = function(self) + interfacing.Page.init(self) + + --FIXME separate block for notes + + for j = 1, 9 do + local offset = j - 5 + local num = 10 + j + + self[num] = Offset:new { + offset = offset, + page = self + } + end + end, + + shift = function(self, msg) + local cmd = msg[1] & 0xf0 + + -- check for matching note range + if cmd == midi.NoteOn + or cmd == midi.NoteOff + or cmd == midi.NotePressure then + return { cmd | self.channel, msg[2] + self.offset, msg[3] } + end + + return msg + end +} + +-- module +local shifting = { + Shifter = Shifter +} + +return shifting diff --git a/meson.build b/meson.build index d4fa2c6..b6eafef 100644 --- a/meson.build +++ b/meson.build @@ -130,6 +130,13 @@ gatekeeping_lua = configure_file( install : true, install_dir : lua_datadir) +shifting_lua = configure_file( + input : join_paths('lua', 'shifting.lua'), + output : 'shifting.lua', + copy : true, + install : true, + install_dir : lua_datadir) + if build_tests if reuse.found() test('REUSE', reuse, args : [ -- 2.45.2