Architect entering the fifth year of beta

Official support for: loomer.co.uk
Post Reply New Topic
RELATED
PRODUCTS

Post

`There r also self-claimed statements, that u can make all full-blown sequencer in Lua. :arrow:`

I guess it would be possible - there is an OnTick() method in the Lua modules that could be used, but not sure how efficient or performant it would be in comparison to the already built in metronome/clock modules.

`Can one do Lua external equivalent in Arch?`

What do you mean by external equivalent?

Post

Generally, the performance of Lua modules is worse than the "built-ins"; but there is a module count above which it can be as efficient (if not more) to replace "n" modules with a single Lua script. There are way too many factors to give any advice on when to go Lua and when to stick with "native" modules though, other than keeping an eye on the CPU.

But you are correct, @cml: `ontick` is the method you want to use if you want to generate sequenced data with Lua.
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

it also depends on the lua code used. If one goes around allocating memory a lot and copying a lot of data around inside the realtime thread...expect performance problems. best practices regarding what happens in the real time thread need to be followed even when in lua.
MacPro 5,1 12core x 3.46ghz-96gb MacOS 12.2 (opencore), X32+AES16e-50

Post

cmnl wrote: Mon Jan 22, 2024 2:46 pm What do you mean by external equivalent?
I think (guess) M4L have also externals, that u can write in code or w/ modules.
In Plugdata u save Zero-Brane studio file as Pd_lua into Plugdata external file and u can load it - obviously - as object.
I am not sure how this is done in Arch, but inlet initialization looked similar (seems to me]], tough I think it has its script module with already own editor.
You do not have the required permissions to view the files attached to this post.

Post

It also depends on the lua code used. If one goes around allocating memory a lot and copying a lot of data around inside the realtime thread...expect performance problems. best practices regarding what happens in the real time thread need to be followed even when in lua.
I'm a Lua novice, no doubt about that - I wonder if anyone else has hit upon the following error popping up in any scripts `script forcibly terminated because it exceeded it's time allowance` ?

This error doesn't seem to impact the execution of the script and it remains functional despite the message and red mark on the module but I would of course like to track down why it occurs and how to fix it.

Post

Code: Select all

I am not sure how this is done in Arch, but inlet initialization looked similar (seems to me]], tough I think it has its script module with already own editor.
@banned - this code looks like python to me if I'm not mistaken - In any case the number of inlets to a Lua module can be set from the UI parameters - all enter into the script via the function

Code: Select all

arc.module.receive(inlet, object)
method. And you can then choose the inlet by for example...

Code: Select all

function arc.module.receive(inlet, object)
    if (inlet == 1) then
        ProcessMidi(object)
    elseif (inlet == 2) then
        ProcessStop()
    elseif (inlet == 3) then
        ProcessCursor(object)
        ProcessDirection()
    end
end

Post

cmnl wrote: Tue Jan 23, 2024 11:02 am @banned - this code looks like python to me if I'm not mistaken -..
Its Lua mixed with AI in ask for make counter 2 special inlet for tick length and initial value...
(initial value and tick can be set w/ two values inside clock - but I did not make additional two inlets so far) Luai :wink:

Post

Dewdman42 wrote: Mon Jan 22, 2024 8:09 pm it also depends on the lua code used. If one goes around allocating memory a lot and copying a lot of data around inside the realtime thread...expect performance problems.
Absolutely: one of the advantages of the modules is they are coded in such a way as to strictly minimize memory allocations. I think I've mentioned before, but there is some very clever interning going on so that objects are shared and re-used when possible. For examples, there is only ever one `true` object, and every time a module outputs a boolean `true` it will reuse that single object. Same for the most commonly used numbers and strings, and the same applies for extracting elements out of collections.

I also mitigate the performance issue somewhat by having a real-time friendly memory allocator and garbage collector. The memory allocator is shared by instances of Lua scripts and the modules themselves (although Lua has its own native garbage collector.)
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

I've been playing with the beta on and off since it came out, mostly 'off' due to life taking priority, but recently started trying again.

It seems that I should be able to have a number of different patterns/scenes defined, and then sequence the starting of those scenes via the timeline - is that possible ?

I want to create the equivalent of 'pattern lanes' in Reason, where I can draw a clip on the timeline that represents 'play pattern 1' or 'play scene 1' for as long as it's running. I don't want to have to copy the patterns onto the timeline, but have a more non-linear approach, ideally with the different 'players' having different tempos/time-signatures.

Any examples of how to do this would be very welcomed, as It's all I'm missing now.
(I did spend far too long trying to figure out how to get 'out' of mapping mode... was expecting more of an 'Escape' than hiding the utility window - it is easy in hindsight, but I spent ages with a purple transport button)

Post

@colin, can you offer any advice on the error

Code: Select all

script forcibly terminated because it exceeded it's time allowance`
?

As I mentioned, the script itself continues to execute without any issues despite the module being marked with the red error sign but I'd like to know what might be happening and how to resolve it :)

Post

I am looking to Lua since it looks cool for defining vectors, Bezier shapes and may sometimes optimize patch.
..

If anyone can write down this Pd Fibonacci code in Arch it would be great - it looks like this particular sequence/ period is easier to write in Lua than patch it.

Code: Select all

 
[size=85]local tictoc = pd.Class:new():register("tictoc")

function tictoc:initialize(sel, atoms)
   -- inlet 1 takes an on/off flag, inlet 2 the delay time
   self.inlets = 2
   -- bangs are output alternating between the two outlets
   self.outlets = 2
   -- the delay time (optional creation argument, 1000 msec by default)
   self.delay = type(atoms[1]) == "number" and atoms[1] or 1000
   -- we start out on the left outlet
   self.left = true
   -- initialize the clock
   self.clock = pd.Clock:new():register(self, "tictoc")
   return true
end

-- don't forget this, or else...

function tictoc:finalize()
  self.clock:destruct()
end

-- As with the metro object, nonzero, "bang" and "start" start the clock,
-- zero and "stop" stop it.

function tictoc:in_1_float(state)
   if state ~= 0 then
      -- output the first tick immediately
      self:tictoc()
   else
      -- stop the clock
      self.clock:unset()
   end
end

function tictoc:in_1_bang()
   self:in_1_float(1)
end

function tictoc:in_1_start()
   self:in_1_float(1)
end

function tictoc:in_1_stop()
   self:in_1_float(0)
end

-- set the delay (always in msec, we don't convert units)

function tictoc:in_2_float(delay)
   -- this will be picked up the next time the clock reschedules itself
   self.delay = delay >= 1 and delay or 1
end

-- the clock method: tic, toc, tic, toc ...

function tictoc:tictoc()
   -- output a bang, alternate between left and right
   self:outlet(self.left and 1 or 2, "bang", {})
   self.left = not self.left
   -- reschedule
   self.clock:delay(self.delay)
end[/size]
https://agraef.github.io/pd-lua/tutoria ... intro.html
http://sigsaly.xf.cz/coding/ - down the page I did few marks on Fibonacci, which sequence looks more useful in use w/ modulo as Pisano period.

..
New to Matlab i found out it can Lua export transcription (thru Python web https://codingfleet.com/code-converter/matlab/lua/) - Lorenz Attractor patched in Arch already (BTW not patch out in Pd :wink:)

Code: Select all

 
[size=85]
-- MAT 405D: W
-- Demonstration for system of ODEs
-- Dr. Stephen Moore | stephen.moore@ucc.edu.gh
-- Department of Mathematics, University of Cape Coast

-- define the step size for the numerical algorithm
local h = 0.005
-- define given parameters
local sigma = 10
local beta = 8/3
local rho = 28
-- time and initial values [x0,y0,z0]
local tspan = {0, 20}
local y0 = {1.3, 1.2, 1.6}

-- The Lorenz function
local function lorenzo(t, y, sigma, rho, beta)
  -- This is the Lorenz differential equations
  -- dx/dt = sigma(y-x)
  -- dy/dt = rho*x-y-x*z
  -- dz/dt = -beta*z+x*y
  -- sigma, rho, beta are real values
  return {
    sigma * y[2] - sigma * y[1],
    rho * y[1] - y[2] - y[1] * y[3],
    -beta * y[3] + y[1] * y[2]
  }
end

-- call for the function Lorenzo with initial values and parameters
-- there are several solvers for ode, e.g., ode23, ode45, etc.
-- help ode23 will give you more information
local t, y = ode23(lorenzo, tspan, y0, h, sigma, rho, beta)

-- Subplot allows you to plot several figures into one figure.
-- plot x against y
subplot(2, 2, 1)
plot(y[{{}, 1}], y[{{}, 2}], 'b--')
title('Fluid motion against Horizontal Temperature')

-- plot x against z
subplot(2, 2, 2)
plot(y[{{}, 1}], y[{{}, 3}], 'r--')
title('Fluid motion against Vertical Temperature')

-- plot y against z
subplot(2, 2, 3)
plot(y[{{}, 2}], y[{{}, 3}], 'g--')
title('Horizontal Temperature against Vertical Temperature')

-- phase plane plot
subplot(2, 2, 4)
plot3(y[{{}, 1}], y[{{}, 2}], y[{{}, 3}], 'r')
title('3D Phase-plane of Lorenz Equation')
xlabel('x')
ylabel('y')
zlabel('z')
grid()
[/size]

https://sites.google.com/site/albertozin/Home/architect - link to patch.
http://sigsaly.xf.cz/attractors/ - my few marks to Lorenz Attractor per se.


I think this was patched w/ AZZIN and patch looks like having more options in patch than code.
In Lua it use ode particularly ode23, but I was thinking that in patch ordinary differential eq:
dx/dt = σ(y-x)
dy/dt = x*(ρ – z) – y
dz/dt = xz – βz

w/: σ (Sigma, s) = 10
ρ (Rho, r) = 28
B = 8/3

Initial values 1,3, 1,2, 1,6
h (step size] 0.005

I think I ve got the logic behind particular ODE in Arch, I guess in Pd (M4L) one would probably (beside lorenz module in ELSE lib) use Float, or set $1 to prevent stack overflow, use metro to load each steps (I ll put on my web (link above) so one can also compare syntax in Arch and Pd, but I am now really looking for Lua-Arch Lorenz code... any one having idea and willing share is golden.
You do not have the required permissions to view the files attached to this post.

Post

cmnl wrote: Wed Jan 24, 2024 11:26 am @colin, can you offer any advice on the error

Code: Select all

script forcibly terminated because it exceeded it's time allowance`
?
Internally, I restrict the amount of time* that a Lua script can run for, just because audio generation needs to be real-time, The only way this can be accomplished is by setting a boundary.

On the other hand, I don't have an issue with allowing this boundary to be changed, if people need scripts to take longer. I'll just leave the default as is.

Could you post the offending script here (or PM it me?) Thanks.

* Just to clarify, by "time" I actually mean the number of Lua opcodes invoked.
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

Audio generation!?! I was under the impression this was a dedicated MIDI app? :hihi:

To be honest, I haven't even delved into the audio aspects. I'll PM you the script @colin :wink:

I wonder if there could be an option to disable the entire audio thread so that every last bit of juice could be reserved for processing MIDI?

Post

Well, when I say audio generation, I'm actually referring to hosted plug-ins and the like. If you're not using them (or the metronome, or the CV outs) then the audio generation code itself is doing nothing that would register in terms of CPU usage. In order to keep internal MIDI clocks tightly in sync though, the MIDI does run alongside the clock of the audio card, which is why (at the moment) it's not quite so straightforward to disable audio completely. It's on the list, though, as others have requested such a change.

I'll eagerly await the script, thanks!
Architect, the modular MIDI toolkit, beta now available for macOS, Windows, and Linux.

Post

Thanks @colin :)

I'm now in the process of refactoring all my code as I have experienced a couple of hard crashes and although I don't know what exactly caused this I began doing some research into performance optimizations with Lua. As a day job web developer it's really quite a different paradigm. I still slip up forgetting that Lua sets variables by reference and not value but more importantly it looks like I need to use more local functions and variables rather than trying to make things 'easier' to work with. I'm so used to designing applications such that I minimize the number of places things can change - change it in one place and everything else is taken care of (clean and readable code). With Lua it seems like it makes a substantial difference to keep things as scoped as possible so that's what I will try before pestering you with the monstrous task of examining my scripts! :wink:

Post Reply

Return to “Loomer”