NAME

Synth::Config - Synthesizer settings librarian

VERSION

version 0.0063

SYNOPSIS

use Synth::Config ();

my $model = 'Modular';
my $synth = Synth::Config->new(model => $model, verbose => 1);

# populate the database with patch settings
my $patches = $synth->import_patches(
    file    => "$model.yaml", # or string => '...' # one or the other is required
    patches => ['Simple 001', 'Simple 002'],       # optional
);

# populate the database with individual settings
my $patch = 'My favorite setting';
my $id1 = $synth->make_setting(name => $patch, group => 'filter', etc => '...');
my $id2 = $synth->make_setting(name => $patch, group => 'sequencer', etc => '...');

# update the group key
$synth->make_setting(id => $id1, group => 'envelope');

my $settings = $synth->recall_settings;
# [ { id => 1, group => 'envelope', etc => '...' }, { id => 2, group => 'sequencer', etc => '...' } ]

$settings = $synth->search_settings(name => $patch);
# [ { id => 1, group => 'envelope', etc => '...' }, { id => 2, group => 'sequencer', etc => '...' } ]

$settings = $synth->search_settings(group => 'sequencer');
# [ { id => 2, group => 'sequencer', etc => '...' } ]

my $setting = $synth->recall_setting(id => $id1);
# { id => 1, group => 'envelope', etc => '...' }

my $g = $synth->graphviz(settings => $setting);
# or
$synth->graphviz(
  settings => $setting,
  render   => 1,
);

my $models = $synth->recall_models;
# [ 'moog_matriarch' ]

my $setting_names = $synth->recall_setting_names;
# [ 'My favorite setting' ]

# populate the database with the model specification
my $specs = $synth->import_specs(
    file => "$model.yaml",
    # or string => '...' # one or the other is required
);

# declare the possible setting specifications
my %spec = (
  order      => [qw(group parameter control group_to param_to bottom top value unit is_default)],
  group      => [],
  parameter  => {},
  control    => [qw(knob switch slider patch)],
  group_to   => [],
  param_to   => [],
  bottom     => [qw(off 0 1 7AM 20)],
  top        => [qw(on 3 4 6 7 5PM 20_000 100%)],
  value      => [],
  unit       => [qw(Hz o'clock)],
  is_default => [0, 1],
);
my $spec_id = $synth->make_spec(%spec);
my $spec = $synth->recall_spec(id => $spec_id);
$specs = $synth->recall_specs;
# { order => [ ... ], etc => ... }

# remove stuff!
$synth->remove_spec;                     # remove the current model specification
$synth->remove_setting(id => $id1);      # remove a particular setting
$synth->remove_settings(name => $patch); # remove all settings sharing the same name
$synth->remove_model(model => $model);   # remove the entire model

DESCRIPTION

Synth::Config provides a way to import, save, recall, and visualize synthesizer control settings in a database, and with GraphViz2.

This does not control the synth. It is simply a way to manually record the parameters defined by knob, slider, switch, or patch settings in an SQLite database. It is a "librarian", if you will.

ATTRIBUTES

model

$model = $synth->model;

The model name of the synthesizer.

This is turned into lowercase and all non-alpha-num characters are converted to an underline character (_).

dbname

$dbname = $synth->dbname;

Database name

Default: synth-config.db

verbose

$verbose = $synth->verbose;

Show progress.

METHODS

new

$synth = Synth::Config->new(model => $model);

Create a new Synth::Config object.

This automatically makes an SQLite database with a table named for the given model.

make_setting

my $id = $synth->make_setting(%args);

Save a named setting and return the record id.

The name is required to perform an insert. If an id is given, an update is performed.

The setting is a single JSON field that can contain any key/value pairs. These pairs must include at least a group to be searchable.

Example:

name: 'My Best Setting!'
settings:
  group   parameter control bottom top   value unit is_default
  filters cutoff    knob    20     20000 200   Hz   1

name: 'My Other Best Setting!'
settings:
  group parameter control group_to param_to is_default
  mixer output    patch   filters  vcf-in   0

recall_setting

my $setting = $synth->recall_setting(id => $id);

Return the parameters of a setting for the given id.

search_settings

my $settings = $synth->search_settings(
  some_setting    => $val1,
  another_setting => $val2,
);

Return all the settings given a search query.

recall_settings

my $settings = $synth->recall_settings;

Return all the settings for the synth model.

recall_models

my $models = $synth->recall_models;

Return all the know models. This method can be called without having specified a synth model in the constructor.

recall_setting_names

my $setting_names = $synth->recall_setting_names;

Return all the setting names for the current model.

remove_setting

$synth->remove_setting(id => $id);

Remove a setting given an id.

remove_settings

$synth->remove_settings; # all model settings
$synth->remove_settings(name => $name);

Remove all settings of the current model, or for given named setting.

remove_model

$synth->remove_model;

Remove the database table for the current object model.

make_spec

my $id = $synth->make_spec(%args);

Save a model specification and return the record id.

If an id is given, an update is performed.

The spec is a single JSON field that can contain any key/value pairs that define the configuration - groups, parameters, values, etc. of a model.

recall_specs

my $specs = $synth->recall_specs;

Return the specs for the model.

recall_spec

my $spec = $synth->recall_spec(id => $id);

Return the model configuration specification for the given id.

remove_spec

$synth->remove_spec;

Remove the database table for the current object model configuration specification.

import_specs

Add the specifications defined in a YAML file or string, to the database and return the spec name.

Option defaults:

file   = undef
string = undef

import_patches

Add the settings defined in a YAML file or string, to the database and return the setting (patch) name.

A specific subset of patches can be imported, by providing their names in the options.

YAML format:

model: "Model name"
patches:
  - patch: "Setting name"
    settings:
      - group: "Group name"
        parameters:
          - param: "Patch parameter name"
            control: 'patch'
            group_to: "Connect to group"
            param_to: "Connected group parameter"
          - param: "Control parameter name"
            control: "Named physical control"
            value: "Parameter value"
            unit: "Parameter unit of measure"
  - patch: "Another parameter name"
    ...

Please see the "SEE ALSO" section for examples of configuration files.

Option defaults:

file    = undef
string  = undef
patches = undef

graphviz

$g = $synth->graphviz(%options);

Visualize a patch of settings with the GraphViz2 module.

Option defaults:

settings  = undef (required)
render    = 0
path      = .
extension = png
shape     = oval
color     = grey

model => 'Modular',
patches => [
  {
    patch => 'Simple 000',
    settings => [
      {
        group => 'oscillator',
        parameters => [
          { control => 'patch', group_to => 'mixer', param => 'out', param_to => 'in' },
          { control => 'knob', param => 'range', unit => "'", value => 8 },
          { control => 'switch', param => 'waveform', unit => '', value => 'square' },
        ],
      }, {
        group => 'mixer',
        parameters => [ { control => 'patch', group_to => 'audio', param => 'stereo-out', param_to => 'stereo-in' } ],
      },
    ],
  }

SEE ALSO

The t/01-methods.t and the eg/*.pl files in this distribution

GraphViz2

List::Util

Moo

Mojo::JSON

Mojo::SQLite

YAML

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2023-2024 by Gene Boggs.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)