View Single Post
Old 08-01-2020, 06:22 AM   #6
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 1,201
Default

Code:
-- Meo-Ada Mespotine - GetParmModulation - demomonitoringsccript
-- licensed under MIT-license
dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")
ParmTable={
"AUDIOCONTROL",
"AUDIOCONTROL_ATTACK",
"AUDIOCONTROL_CHAN",
"AUDIOCONTROL_DIRECTION",
"AUDIOCONTROL_MAXVOLUME",
"AUDIOCONTROL_MINVOLUME",
"AUDIOCONTROL_RELEASE",
"AUDIOCONTROL_STEREO",
"AUDIOCONTROL_STRENGTH",
"LFO",
"LFO_DIRECTION",
"LFO_PHASE",
"LFO_PHASERESET",
"LFO_SHAPE",
"LFO_SHAPEOLD",
"LFO_SPEED",
"LFO_STRENGTH",
"LFO_TEMPOSYNC",
"MIDIPLINK",
"PARAM_NR",
"PARAM_TYPE",
"PARAMOD_BASELINE",
"PARAMOD_ENABLE_PARAMETER_MODULATION",
"PARMLINK",
"PARMLINK_LINKEDPARMIDX",
"PARMLINK_LINKEDPLUGIN",
"PARMLINK_OFFSET",
"PARMLINK_SCALE",
"WINDOW_ALTEREDOPEN",
"WINDOW_BOTTOM_READONLY",
"WINDOW_RIGHT_READONLY",
"WINDOW_XPOS",
"WINDOW_YPOS",
"X2",
"Y2"}


InitStateChunk=[[
<TRACK
NAME ""
PEAKCOL 33530462
BEAT -1
AUTOMODE 0
VOLPAN 1 0 -1 -1 1
MUTESOLO 0 0 0
IPHASE 0
PLAYOFFS 0 1
ISBUS 0 0
BUSCOMP 0 0 0 0 0
SHOWINMIX 1 0.6667 0.5 1 0.5 0 0 0
FREEMODE 0
REC 0 0 1 0 0 0 0
VU 2
TRACKHEIGHT 134 0 0
INQ 0 0 0 0.5 100 0 0 100
NCHAN 2
FX 1
TRACKID {4BFA8B9B-8321-4076-953E-F1BAFF093F9C}
PERF 0
MIDIOUT -1
MAINSEND 1 0
<FXCHAIN
WNDRECT 28 56 647 392
SHOW 0
LASTSEL 0
DOCKED 1
BYPASS 0 0 0
<JS loser/3BandEQ ""
24.000000 200.000000 0.000000 2000.000000 0.000000 0.000000 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
>
FLOATPOS 0 0 0 0
FXID {DE7B479A-54F2-43CB-994E-E0F1D8C2D246}
<PROGRAMENV 0 0
PARAMBASE 0
LFO 1
LFOWT 1 1
AUDIOCTL 1
AUDIOCTLWT 1 1
PLINK 1 -1 -1 0
LFOSHAPE 0
LFOSYNC 0 0 0
LFOSPEED 0.124573 0
CHAN -1
STEREO 0
RMS 300 300
DBLO -24
DBHI 0
X2 0.5
Y2 0.5
MODWND 1 358 36 654 1274
>
WAK 0 0
>
>
]]

function ultraschall.GetParmModulationTable(FXStateChunk, index)
  if ultraschall.type(FXStateChunk)~="string" then ultraschall.AddErrorMessage("GetParmModulationTable", "FXStateChunk", "must be a string", -1) return nil end
  if ultraschall.IsValidFXStateChunk(FXStateChunk)==false then ultraschall.AddErrorMessage("GetParmModulationTable", "FXStateChunk", "must be a valid FXStateChunk", -2) return nil end
  if ultraschall.type(index)~="number: integer" then ultraschall.AddErrorMessage("GetParmModulationTable", "index", "must be an integer", -3) return nil end
  if index<1 then ultraschall.AddErrorMessage("GetParmModulationTable", "index", "must be bigger than 0", -4) return nil end
  local count=0
  local found=""
  local ParmModTable={}
  for k in string.gmatch(FXStateChunk, "\n    <PROGRAMENV.-\n    >") do
    count=count+1
    if count==index then found=k break end
  end
  if found=="" then ultraschall.AddErrorMessage("GetParmModulationTable", "index", "no such index", -5) return nil end
  
  
  found=string.gsub(found, "\n", " \n")
  
--  print_update(found)

  -- <PROGRAMENV
  ParmModTable["PARAM_NR"], ParmModTable["PARAMOD_ENABLE_PARAMETER_MODULATION"]=found:match("<PROGRAMENV (.-) (.-) ")
  if tonumber(ParmModTable["PARAM_NR"])~=nil then
    ParmModTable["PARAM_NR"]=tonumber(ParmModTable["PARAM_NR"])
    ParmModTable["PARAM_TYPE"]=""
  else
    ParmModTable["PARAM_TYPE"]=ParmModTable["PARAM_NR"]:match(":(.*)")
    ParmModTable["PARAM_NR"]=tonumber(ParmModTable["PARAM_NR"]:match("(.-):"))
  end
  ParmModTable["PARAM_NR"]=ParmModTable["PARAM_NR"]+1
  ParmModTable["PARAMOD_ENABLE_PARAMETER_MODULATION"]=tonumber(ParmModTable["PARAMOD_ENABLE_PARAMETER_MODULATION"])==0

  -- PARAMBASE
  ParmModTable["PARAMOD_BASELINE"]=tonumber(found:match("PARAMBASE (.-) "))
  
  ParmModTable["LFO"]=tonumber(found:match("LFO (.-) "))==1

  -- LFOWT  
  ParmModTable["LFO_STRENGTH"], 
  ParmModTable["LFO_DIRECTION"]=found:match("LFOWT (.-) (.-) ")
  ParmModTable["LFO_STRENGTH"]=tonumber(ParmModTable["LFO_STRENGTH"])
  ParmModTable["LFO_DIRECTION"]=tonumber(ParmModTable["LFO_DIRECTION"])

  -- AUDIOCTL
  ParmModTable["AUDIOCONTROL"]=tonumber(found:match("AUDIOCTL (.-) "))==1
  
  -- AUDIOCTLWT
  ParmModTable["AUDIOCONTROL_STRENGTH"], 
  ParmModTable["AUDIOCONTROL_DIRECTION"]=found:match("AUDIOCTLWT (.-) (.-) ")
  ParmModTable["AUDIOCONTROL_STRENGTH"]=tonumber(ParmModTable["AUDIOCONTROL_STRENGTH"])
  ParmModTable["AUDIOCONTROL_DIRECTION"]=tonumber(ParmModTable["AUDIOCONTROL_DIRECTION"])
  
  -- PLINK
  ParmModTable["PARMLINK_SCALE"], 
  ParmModTable["PARMLINK_LINKEDPLUGIN"],
  ParmModTable["PARMLINK_LINKEDPARMIDX"],
  ParmModTable["PARMLINK_OFFSET"]
  =found:match(" PLINK (.-) (.-) (.-) (.-) ")
  
  ParmModTable["PARMLINK_SCALE"]=tonumber(ParmModTable["PARMLINK_SCALE"])
  if ParmModTable["PARMLINK_LINKEDPLUGIN"]~=nil then
    if ParmModTable["PARMLINK_LINKEDPLUGIN"]:match(":")~=nil then 
      ParmModTable["PARMLINK_LINKEDPLUGIN"]=tonumber(ParmModTable["PARMLINK_LINKEDPLUGIN"]:match("(.-):"))+1
    else
      ParmModTable["PARMLINK_LINKEDPLUGIN"]=tonumber(ParmModTable["PARMLINK_LINKEDPLUGIN"])
    end
  end
  ParmModTable["PARMLINK_LINKEDPARMIDX"]=tonumber(ParmModTable["PARMLINK_LINKEDPARMIDX"])
  if ParmModTable["PARMLINK_LINKEDPARMIDX"]~=nil and ParmModTable["PARMLINK_LINKEDPARMIDX"]>-1 then ParmModTable["PARMLINK_LINKEDPARMIDX"]=ParmModTable["PARMLINK_LINKEDPARMIDX"]+1 end
  ParmModTable["PARMLINK_OFFSET"]=tonumber(ParmModTable["PARMLINK_OFFSET"])

  ParmModTable["PARMLINK"]=ParmModTable["PARMLINK_SCALE"]~=nil

  -- MIDIPLINK
  ParmModTable["MIDIPLINK_BUS"], 
  ParmModTable["MIDIPLINK_CHANNEL"],
  ParmModTable["MIDIPLINK_MIDICATEGORY"],
  ParmModTable["MIDIPLINK_MIDINOTE"]
  =found:match("MIDIPLINK (.-) (.-) (.-) (.-) ")
  ParmModTable["MIDIPLINK_BUS"]=tonumber(ParmModTable["MIDIPLINK_BUS"])
  ParmModTable["MIDIPLINK_CHANNEL"]=tonumber(ParmModTable["MIDIPLINK_CHANNEL"])
  ParmModTable["MIDIPLINK_MIDICATEGORY"]=tonumber(ParmModTable["MIDIPLINK_MIDICATEGORY"])
  ParmModTable["MIDIPLINK_MIDINOTE"]=tonumber(ParmModTable["MIDIPLINK_MIDINOTE"])

  ParmModTable["MIDIPLINK"]=ParmModTable["MIDIPLINK_MIDINOTE"]~=nil
  
  -- LFOSHAPE
  ParmModTable["LFO_SHAPE"]=tonumber(found:match("LFOSHAPE (.-) "))
  
  -- LFOSYNC
  ParmModTable["LFO_TEMPOSYNC"], 
  ParmModTable["LFO_SHAPEOLD"],
  ParmModTable["LFO_PHASERESET"]
  =found:match("LFOSYNC (.-) (.-) (.-) ")
  ParmModTable["LFO_TEMPOSYNC"] = tonumber(ParmModTable["LFO_TEMPOSYNC"])==1
  ParmModTable["LFO_SHAPEOLD"]  = tonumber(ParmModTable["LFO_SHAPEOLD"])
  ParmModTable["LFO_PHASERESET"]= tonumber(ParmModTable["LFO_PHASERESET"])
  
  -- LFOSPEED
  ParmModTable["LFO_SPEED"], 
  ParmModTable["LFO_PHASE"]
  =found:match("LFOSPEED (.-) (.-) ")
  ParmModTable["LFO_SPEED"]=tonumber(ParmModTable["LFO_SPEED"])
  ParmModTable["LFO_PHASE"]=tonumber(ParmModTable["LFO_PHASE"])
  
  if found:match("CHAN (.-) ")~=nil then
    ParmModTable["AUDIOCONTROL_CHAN"]  =tonumber(found:match("CHAN (.-) "))+1
  end
  ParmModTable["AUDIOCONTROL_STEREO"]=tonumber(found:match("STEREO (.-) "))

  -- RMS
  ParmModTable["AUDIOCONTROL_ATTACK"], 
  ParmModTable["AUDIOCONTROL_RELEASE"]
  =found:match("RMS (.-) (.-) ")
  ParmModTable["AUDIOCONTROL_ATTACK"]=tonumber(ParmModTable["AUDIOCONTROL_ATTACK"])
  ParmModTable["AUDIOCONTROL_RELEASE"]=tonumber(ParmModTable["AUDIOCONTROL_RELEASE"])
  
  --DBLO and DBHI
  ParmModTable["AUDIOCONTROL_MINVOLUME"]=tonumber(found:match("DBLO (.-) "))
  ParmModTable["AUDIOCONTROL_MAXVOLUME"]=tonumber(found:match("DBHI (.-) "))
  
  -- X2, Y2
  ParmModTable["X2"]=tonumber(found:match("X2 (.-) "))
  ParmModTable["Y2"]=tonumber(found:match("Y2 (.-) "))

  -- MODHWND
  ParmModTable["WINDOW_ALTEREDOPEN"], 
  ParmModTable["WINDOW_XPOS"],
  ParmModTable["WINDOW_YPOS"],
  ParmModTable["WINDOW_RIGHT_READONLY"],
  ParmModTable["WINDOW_BOTTOM_READONLY"]
  =found:match("MODWND (.-) (.-) (.-) (.-) (.-) ")
  ParmModTable["WINDOW_ALTEREDOPEN"]=tonumber(ParmModTable["WINDOW_ALTEREDOPEN"])==1
  ParmModTable["WINDOW_XPOS"]  =tonumber(ParmModTable["WINDOW_XPOS"])
  ParmModTable["WINDOW_YPOS"]  =tonumber(ParmModTable["WINDOW_YPOS"])
  ParmModTable["WINDOW_RIGHT"] =tonumber(ParmModTable["WINDOW_RIGHT"])
  ParmModTable["WINDOW_BOTTOM"]=tonumber(ParmModTable["WINDOW_BOTTOM"])
  
  return ParmModTable
end

reaper.Main_OnCommand(40859, 0)
reaper.Main_OnCommand(40001, 0)
ultraschall.SetTrackStateChunk_Tracknumber(1, InitStateChunk)
gfx.init("Testscript", 300, 600)
gfx.setfont(1, "arial", 12,0)

A=ultraschall.IsValidTrackStateChunk(InitStateChunk)

FXStateChunk           = ultraschall.GetFXStateChunk(InitStateChunk)
SLEM()
OldParmModulationTable    = ultraschall.GetParmModulationTable(FXStateChunk, 1)
A=0

function main()
  A=A+1
  if A==15 then
    Reval, TrackStateChunk = ultraschall.GetTrackStateChunk_Tracknumber(1)
    FXStateChunk           = ultraschall.GetFXStateChunk(TrackStateChunk)
    ParmModulationTable    = ultraschall.GetParmModulationTable(FXStateChunk, 1)
--    print_update(FXStateChunk)
    gfx.x=0
    gfx.y=10
    gfx.set(1)
    gfx.drawstr("CURRENT VALUES:\n")
    gfx.y=gfx.y+gfx.texth+3
    for i=1, 35 do
      gfx.x=0
      gfx.y=gfx.y+gfx.texth+3
      if ParmModulationTable~=nil and ParmModulationTable[ParmTable[i]]~=OldParmModulationTable[ParmTable[i]] then
        gfx.set(1,0,1)
      else
        gfx.set(1)
      end
      if ParmModulationTable==nil then CurVal=nil else CurVal=ParmModulationTable[ParmTable[i]] end
      gfx.drawstr(ParmTable[i]..": "..tostring(CurVal))
    end
    if ParmModulationTable~=nil then
      OldParmModulationTable=ParmModulationTable
    end
    A=0
  end  
  P=gfx.getchar()
  if P~=-1 then reaper.defer(main) end
end

main()

SLEM()
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish

Last edited by Meo-Ada Mespotine; 08-02-2020 at 09:59 AM.
Meo-Ada Mespotine is online now   Reply With Quote