mirror of
https://github.com/StyledStrike/musical-keyboard.git
synced 2025-03-04 03:13:36 -05:00
Add MIDI transpose
This commit is contained in:
parent
c183d3d465
commit
cfaf83bda6
@ -16,6 +16,7 @@ MKeyboard.Settings = {
|
||||
sheet = 0,
|
||||
velocity = 127,
|
||||
octave = 0,
|
||||
midiTranspose = 0,
|
||||
|
||||
channelInstruments = {},
|
||||
drawKeyLabels = true
|
||||
@ -89,6 +90,11 @@ function MKeyboard:LoadSettings()
|
||||
self.Settings.octave = ValidateInteger(data.octave, -3, 3)
|
||||
end
|
||||
|
||||
-- last transpose that was used with midi
|
||||
if data.midiTranspose then
|
||||
self.Settings.midiTranspose = ValidateInteger(data.midiTranspose, -48, 48)
|
||||
end
|
||||
|
||||
-- links between instruments and MIDI channels
|
||||
if data.channelInstruments and type(data.channelInstruments) == 'table' then
|
||||
for c, i in pairs(data.channelInstruments) do
|
||||
@ -112,6 +118,7 @@ function MKeyboard:SaveSettings()
|
||||
sheet = s.sheet,
|
||||
velocity = s.velocity,
|
||||
octave = s.octave,
|
||||
midiTranspose = s.midiTranspose,
|
||||
channelInstruments = s.channelInstruments,
|
||||
drawKeyLabels = s.drawKeyLabels
|
||||
}, true))
|
||||
@ -183,7 +190,7 @@ function MKeyboard:NoteOn(note, velocity, isMidi, midiChannel)
|
||||
|
||||
self.entity:EmitNote(note, velocity, 80, instrument, isMidi)
|
||||
|
||||
self.noteState[note] = isMidi and 4 or 3 -- see themeColors on cl_hud.lua
|
||||
self.noteState[note] = isMidi and 4 or 3 -- see themeColors on cl_interface.lua
|
||||
self.lastNoteWasAutomated = isMidi
|
||||
|
||||
-- remember when we started putting notes
|
||||
@ -206,6 +213,12 @@ function MKeyboard:NoteOff(note)
|
||||
self.noteState[note] = nil
|
||||
end
|
||||
|
||||
function MKeyboard:NoteOffAll()
|
||||
for k, _ in pairs(self.noteState) do
|
||||
self.noteState[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function MKeyboard:ReproduceQueue()
|
||||
local t = SysTime()
|
||||
|
||||
|
@ -355,6 +355,7 @@ function HUD:Init()
|
||||
end
|
||||
|
||||
MKeyboard:SaveSettings()
|
||||
MKeyboard:NoteOffAll()
|
||||
end
|
||||
|
||||
local rDevices = propertyPanel:CreateRow('MIDI', langGet('mk.midi.device'))
|
||||
@ -376,6 +377,16 @@ function HUD:Init()
|
||||
rDevices:SetValue(langGet('mk.midi.nodevices'))
|
||||
rDevices:SetEnabled(false)
|
||||
end
|
||||
|
||||
local midiTranspose = propertyPanel:CreateRow('MIDI', langGet('mk.vkeys.transpose'))
|
||||
midiTranspose:Setup('Int', {min = -48, max = 48})
|
||||
midiTranspose:SetValue(MKeyboard.Settings.midiTranspose)
|
||||
|
||||
midiTranspose.DataChanged = function(_, val)
|
||||
MKeyboard.Settings.midiTranspose = math.Round(val)
|
||||
MKeyboard:SaveSettings()
|
||||
MKeyboard:NoteOffAll()
|
||||
end
|
||||
else
|
||||
rDevices:SetValue(langGet('mk.midi.nomodule'))
|
||||
rDevices:SetEnabled(false)
|
||||
|
@ -77,12 +77,13 @@ hook.Add('MIDI', 'mkeyboard_MIDI', function(_, code, p1, p2)
|
||||
if not code then return end
|
||||
|
||||
local midiCmd = midi.GetCommandName(code)
|
||||
local transpose = MKeyboard.Settings.midiTranspose
|
||||
|
||||
if midiCmd == 'NOTE_ON' and p2 > 0 then
|
||||
local midiChannel = midi.GetCommandChannel(code)
|
||||
MKeyboard:NoteOn(p1, p2, true, midiChannel)
|
||||
MKeyboard:NoteOn(p1 + transpose, p2, true, midiChannel)
|
||||
|
||||
elseif midiCmd == 'NOTE_OFF' then
|
||||
MKeyboard:NoteOff(p1)
|
||||
MKeyboard:NoteOff(p1 + transpose)
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue
Block a user