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


dublang plugin

dublang system includes a plugin with same name, the dublang plugin

this plugin doesn't connect to external servives as others plugins but instead it allows to run lua code, the code evaluated by "CTRL + e" is executed by lua 5.1, and it provides access to dublang system api and also to the neovim api

example (using the neovim lua api)

#!dublang

-- set environment variable
vim.env.COLOR = 'blue'

-- get environment variable
return vim.env.COLOR

-- change vim colorsheme
vim.cmd('colorscheme ${COLOR}')

in addition to providing access to the neovim api this dublang plugin allows mixing other languages provided by the others plugins on the same block

plugins functions

any other plugin can be executed through a lua function under the #!dublang region, for example tidalcycles code can be executed through the lua function tidalcycles()

example (combining tidalcycles and mpv)

#!dublang

tidalcycles([[ d1 $ sound "cp" ]])
mpv([[ video mymovie:01 ]])

alert! when running plugins this way, hooks and triggers are not executed

example of others plugins functions:

dublang functions

besides the plugins functions the dublang plugin provides some others useful functions

function: schedule

schedule() function enqueue a sequence of events to be executed over time

the time is defined in seconds and the sequence starts at the second 1

example (schedule 4 events)

#!dublang

schedule({
  [1] = function()
    mpv([[clear]])
    tidalcycles([[hush]])
  end,
  [5] = function()
    mpv([[loadfile "${PWD}/videos/buzz/slice1.mp4"]])
    tidalcycles([[xfadeIn 1 8 $ sound "808bd*8"]])
  end,
  [10] = function()
    mpv([[curves $ pre color_negative]])
    tidalcycles([[xfadeIn 1 4 $ sound "[808bd*8, bd*2]"]])
  end,
  [15] = function()
    mpv([[loadfile "${PWD}/videos/buzz/slice4.mp4"]])
    tidalcycles([[xfadeIn 1 16 $ sound "[~ ~ jazz:7 jazz:7/2]"]])
  end,
})

the example above schedules 4 events to be executed on the time: 1s, 5s, 10s and the final event at the time 15s

see below a video demo created with the function schedule() (video demo source code)

function: cycle

cycle() executes a list of anonymous functions in a infinite loop, the loop length is 1 second by default, the list of functions is spreaded on the loop length

example (the 1st function is executed on time 0 and the 2nd on time 500 ms)

#!dublang

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

it is possible to modify the default length of a cycle using the function length()

see below a video demonstration using the function cycle()

function: length

length() modifies the default cycle length in milliseconds

example (set the cycle length as 10 seconds)

#!dublang

length(10000)

function: hooks

hooks() function register a pipeline of user defined lua functions that will be started by the execution of other plugins

example (executing a lua function when tidalcycles is executed)

#!dublang

hooks('tidalcycles', {
  function(plugin, block)
    if block:match("bd") then
      mpv([[video "videos-dune:12"]])
    elseif block:match("cp") then
      mpv([[video "videos-dune:11"]])
    end
  end,
  function(plugin, block)
    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 "bd*8" # squiz 3

d1 $ sound "cp*2" # squiz 1

the example above execute the mpv() function each time the code under #!tidalcycles region is evaluated

with the hooks() functions it is possible to create custom side effects when code by any plugin is evaluated, in the example some visuals are being produced by the #!tidalcycles evaluation

in order to disable hooks just register a empy list of functions, example

#!dublang

hooks('tidalcycles', {})

don't confuse user defined hooks described here with the plugin hooks described on the manual page here

more examples


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