Author Topic: AZ Lua MFX plug-in parallel fifths  (Read 7532 times)

Offline F0h

  • Newbie
  • *
  • Posts: 9
AZ Lua MFX plug-in parallel fifths
« on: December 15, 2018, 06:58:22 PM »
Hello Cakewalkers!
I'm starting to learn AZ LUA, I copied and edited the program that "Convert modulation to the Program Change " I donĀ“t Know what does not work my edition
Please help
Regards.

Code: [Select]
--[[parallel fifths]]--

function OnInput(pqIn, pqOut)
  for i,e in ipairs(pqIn) do
    if e.Type == Note then
      local n = MfxEvent.new(Note)
      n.Time = e.Time
      n.Chan = e.Chan
      n.Key  = e.Key + 7
      n.Vel  = e.Vel
      n.VelOff = e.VelOff
      n.Duration = e.Duration
      e = n
    end
    pqOut.add(e)
  end
end

OnEvents = function ( From, To, pqIn, pqOut)
 OnInput(pqIn, pqOut)
end


Offline F0h

  • Newbie
  • *
  • Posts: 9
Re: AZ Lua MFX plug-in parallel fifths
« Reply #1 on: December 15, 2018, 09:00:38 PM »
oh, I see the code process when I play a recorded MIDI event, but I would like add a new note every time I play a key... in realtime of course.

Offline azslow3

  • Administrator
  • Hero Member
  • *****
  • Posts: 1679
Re: AZ Lua MFX plug-in parallel fifths
« Reply #2 on: December 15, 2018, 09:17:19 PM »
You took an example which works with CC. And you need one for Notes. That is a bit tricky, when you play recorded notes they are represented as "Note", with duration. But live they are represented as "NoteOn" and "NoteOff". If you dynamically switch what notes do, check MfxOffNotes.new() documentation and "Transpose everything one octave up during C3 "switch key" engaged" as an example.

But for simple static transformation you can use (untested!!!)
Code: [Select]
function OnInput(pqIn, pqOut)
  for i,e in ipairs(pqIn) do
    if e.Key then
      e.Key = e.Key + 7
    end
    pqOut.add(e)
  end
end
OnEvents = function ( From, To, pqIn, pqOut)
 OnInput(pqIn, pqOut)
end
The trick here is simple, "Note", "NoteOn" and "NoteOff" have the field "Key". Other MIDI events do not have it. So you modify the Key if it exists, for all cases at once...
« Last Edit: December 15, 2018, 09:22:13 PM by azslow3 »

Offline F0h

  • Newbie
  • *
  • Posts: 9
Re: AZ Lua MFX plug-in parallel fifths
« Reply #3 on: December 15, 2018, 10:27:05 PM »
Oh yes!  :-[ Duration is Delta Time from Note Off to Note on.
I will study "Transpose everything one octave up during C3 "switch key"
and MfxOffNotes.new()
Thanks for your time.


Offline F0h

  • Newbie
  • *
  • Posts: 9
Re: AZ Lua MFX plug-in parallel fifths
« Reply #4 on: December 16, 2018, 02:16:29 AM »
F0h

Hello Alexey
This is my "Hello World" for AZ Lua
a Power Chord Plug in

Thanks for the advice

Julio.

F7h

Code: [Select]
--[[ Power Chord
    by Julio Benavides
--]]
local active = MfxOffNotes.new()
local n
function OnInput(pqIn, pqOut)
  for i,e in ipairs(pqIn) do
    if e.Type ~= Note then 
  pqOut.add(e)
end

    e = active.move(e, pqOut )

    if not e then  
elseif e.Vel then
      base = e:copy()  
      n = e.Key
      --Seconde note--  
  e.Key = n + 7
      active.add(base, e)     
      pqOut.add(e)  
      --Third note--
  e.Key = n + 12
      active.add(base, e)     
      pqOut.add(e)       
    end   
  end
end 

OnEvents = function ( From, To, pqIn, pqOut)
 OnInput(pqIn, pqOut)
end


Offline azslow3

  • Administrator
  • Hero Member
  • *****
  • Posts: 1679
Re: AZ Lua MFX plug-in parallel fifths
« Reply #5 on: December 16, 2018, 09:20:47 AM »
Great!  :)

It took just several years till someone has tried to use AZ Lua  ::)

Offline F0h

  • Newbie
  • *
  • Posts: 9
Re: AZ Lua MFX plug-in parallel fifths
« Reply #6 on: December 25, 2018, 07:35:31 PM »
F0h
Hello Alexei
and Merry Christmas!!
This is my second aplication of your fantastic plug-in editor.
The code is not finished yet.
All your white keys is mapping to C Blues Scale
It was based in your drum map plug in.
Code: [Select]
--[[ C Blues Scale white keys
Based on Drum Map like functionality,
AZ, 2016
Julio Benavides, 2018 C blues scale
]]--
local scale = {}
for i = 1, 128 do --mapping
        k = i - 1 --MIDI KEY 0...127---
if k % 12 == 0  or k % 12 == 7 or k % 12 == 3 or k % 12 == 6 or  k % 12 == 10  then scale[i]=i-1
elseif k % 12 == 2 or  k % 12 == 5 or k % 12 == 9 or k % 12 == 1 or k % 12 == 8 or k % 12 == 4 or k % 12 == 5 or k % 12 == 11 then scale[i]=i
end
end
function OnInput(pqIn, pqOut)
  for i,e in ipairs(pqIn) do
    if e.Key then -- Is Note ?
      local newkey = scale[e.Key+1]
      if newkey then -- Mapping exist ?
        e.Key = newkey -- map the note
      end
    end
    pqOut.add(e)
  end
end
OnEvents = function ( From, To, pqIn, pqOut)
 OnInput(pqIn, pqOut)
end

Next version: Scale Root Key change by MIDI Note Numbre 36..47  8)
Regards.

Julio

F0h

Offline azslow3

  • Administrator
  • Hero Member
  • *****
  • Posts: 1679
Re: AZ Lua MFX plug-in parallel fifths
« Reply #7 on: December 26, 2018, 06:00:20 PM »
Merry Christmas!!

I see you have understood how it works  ;)