home - plugins - tutorials - showcase - history - manual - design


dublang system design

this page documents dublang system design and architectural decisions, user interface proposals, feature proposals, and some work-in-progress ideas

it is used, but not limited, to document software design, language specification and user interface design

the format is inspired by some common formats, like debian enhancement proposals, proposed perl changes, python enhancement proposals and request for comments

each document is identified by "d + $NUMBER", for example: d1, d2, d3, ..., dN, and it has a state among the itens: draft, exploring, ready, obsolete or closed

design-status.png

d1. block annotation

dublang block annotation syntax to modify block evaluation, like dublang triggers but defined on block level instead of on shebang level

example (annotate blocks in any plugin and tell git to tag the commit)

#!echo

@git tag v2
hello world

status

design-d1.png

inspiration

.Net Attributes C#

[Serializable]
public class SampleClass {
}

Python Decorators

@synchronized(lock)
def foo(cls):
    pass

Java Annotation

@Twizzle
public void toggle() {
}

d2. cycle function

dublang cycle() function accepts a list of anonymous function and execute each function on a infinite loop, called cycle

a cycle has a fixed duration (by default defined as 1 second) and the cycle() function executes each anonymous function in a slice of that 1s duration

example (run 1st function on the time 0 and the 2nd function on the time 0.5 second)

#!dublang

cycle({
  function()
    vim.notify("run function 1")
  end,
  function()
    vim.notify("run function 2")
  end,
})

a cycle can be identified by a string, example

#!dublang

cycle("foo", {
  function()
    vim.notify("run function 1")
  end,
  function()
    vim.notify("run function 2")
  end,
})

if cycle function doesn't have and idenfier then it uses a global id and any other later cycle execution overwrites the previous one

status

design-d2.png

see dublang cycle documentation here

inspiration

Sonic Pi - Live Loops

live_loop  do
  play 60
  sleep 1
end

Tidal Cycles - cycles per second (CPS)

d1 $ s "bd hh bd hh"

d3. user defined hooks

dublang hooks are Lua functions defined by user executed by events on other plugins

example (using dublang lua function hook())

#!dublang

-- using function hook() to create one hook function for tidalcycles

hook('tidalcycles', function(plugin, block)
    if block:match("cp") then
      mpv([[video "videos-dune:01"]])
    else if block:match("bd") then
      mpv([[video "videos-dune:02"]])
    end
  end
)

#!tidalcycles

d1 $ sound "cp"

d2 $ sound "bd*2"

example (using dublang lua function hooks())

#!dublang

-- using function hooks() to create a chain of hook functions for tidalcycles

hooks('tidalcycles', {
  function(plugin, block)
    if block:match("cp") then
      mpv([[video "videos-dune:01"]])
    else if block:match("bd") then
      mpv([[video "videos-dune:02"]])
    end
  end,
  function(plugin, block)
    -- hook function for tidalcycles
    if block:match("squiz 0") then
      mpv([[cas 1]])
    elseif block:match("squiz %d") then
      mpv([[edge $ mode wires]])
    else
      mpv([[clr]])
    end
  end,
})

#!tidalcycles

d1 $ sound "cp" # squiz 0

d1 $ sound "cp" # squiz 1

d2 $ sound "bd*2"

status

design-d3.png

see dublang hooks documentation here


home - plugins - tutorials - showcase - history - manual - design