lv2hostconfig

package module
v0.0.0-...-bc0b2f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2019 License: BSD-3-Clause Imports: 7 Imported by: 2

README

lv2hostconfig

Config parser for LV2 host

If you don't know why you need this, you don't.

However, just in case you're curious how it works, here it is in a nutshell.

This is intended for use with lv2host-go library, to make it easy to configure LV2 plugins without writing loads of code to do it.

At its core, it is a YAML parser. Format is as follows:

plugins:
- pluginUri: <LV2 URI of plugin you want to load>
  parameters:
    <param symbol>: <param value as float string, e.g. "123.45", with quotes>

Example:

plugins:
- pluginUri: myuri
  parameters:
    test1: "123.000000"
    test2: "234.000000"
- pluginUri: myuri2
  parameters:
    test3: "345.000000"
    test4: "456.000000"

You can then use these parameters to load plugins and set their parameters with Go bindings for LV2Host.

However, the config parser is not just a config parser. It also uses govaluate to specify parameters in a declarative manner, for example:

knee: "10 + 5"

This might seem trivial, but the plugin config data also has a value map and a function map, to use with govaluate. For example, you could set value "myvalue" to 10, and rewrite your config as this:

knee: "myvalue + 5"

This, given myvalue's value of 10, will evaluate to 15, and that's the value that will be stored in the LV2 config structure. Keep in mind that standard govaluate escaping rules apply.

But wait, there's more! There is also a number of utility functions provided within the config library. Usage of these functions is done in a similar, declarative way:

knee: "sqrt(9)"

If sqrt was defined as a function that returns a square root of whatever argument supplied, then the value stored in config would be equal to 3.

List of utility functions provided is as follows:

  • decibel(value) - will convert a float value to decibels
  • linear(value) - will convert a decibel value to float
  • min(a, b), max(a, b), abs(a), sqrt(a), pow(a, b) - self-explanatory
  • scale(val, orig_min, orig_max, new_min, new_max) - scale value val from range orig_min-orig_max to fit into the new range new_min-new_max

Keep in mind that while you're allowed to modify values inside the config and even write it out, any formatted values will not have their changed values reflected in the resulting YAML. So, if your initial parameter value was like this:

knee: "10"

and you've overwritten the value, the YAML will have the new value written out. If, however, your initial parameter value was like this:

knee: "myvar + func() - 10"

(or in fact anything that isn't parseable as float32), then the new value will not be written out to the YAML config. If you want to change data in such a field, change its format.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LV2HostConfig

type LV2HostConfig struct {
	Plugins     []LV2PluginConfig
	ValueMap    map[string]interface{}
	FunctionMap map[string]govaluate.ExpressionFunction
}

LV2HostConfig is main config structure containing plugin configuration. In addition, it also contains a parameter map (untyped), as well as govaluate expression function map, to enable evaluating arbitrary functions as part of config parsing.

func NewLV2HostConfig

func NewLV2HostConfig() *LV2HostConfig

NewLV2HostConfig allocate new host config (usually for purposes of setting up its value map parameters)

func (*LV2HostConfig) Evaluate

func (c *LV2HostConfig) Evaluate() error

Evaluate uses govaluate to (re-)parse contents of config structure into actual values.

func (*LV2HostConfig) ReadFile

func (c *LV2HostConfig) ReadFile(file string) error

ReadFile will read a YAML config into an LV2HostConfig data structure. Note that any Data fields will not be initialized until Evaluate is called.

func (*LV2HostConfig) WriteToFile

func (c *LV2HostConfig) WriteToFile(file string) error

WriteToFile will write LV2HostConfig data back into YAML form. Note that Data contents is not dumped into YAML - DataFmt is dumped instead. Therefore, any changes to Data values will not be reflected in the YAML file unless DataFmt was changed accordingly.

type LV2PluginConfig

type LV2PluginConfig struct {
	PluginURI string
	Data      map[string]float32
	DataFmt   map[string]string
}

LV2PluginConfig is plugin config structure. Use LV2 symbols to map parameters to values. Also contains original formatting for data, in case the config would need to be saved back into file form.

func NewLV2PluginConfig

func NewLV2PluginConfig() LV2PluginConfig

NewLV2PluginConfig allocate new plugin config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL