NAME

Synth::Config - Synthesizer settings librarian

VERSION

version 0.0054

SYNOPSIS

use Synth::Config ();

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

# populate the database with patch settings from a YAML file or string
my $patches = $synth->import_yaml(
    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 => '...');

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

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

my $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 $g = $synth->graphviz(
  settings   => $settings,
  model_name => $model,
);
# or
$synth->graphviz(
  settings   => $settings,
  model_name => $model,
  render     => 1,
);

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

my $names = $synth->recall_names;
# [ 'My favorite setting' ]

# declare the possible settings
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);
my $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 save and recall synthesizer control settings in a database.

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-1-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    => $valu2,
  another_setting => $value2,
);

Return all the settings given a search query.

recall_all

my $settings = $synth->recall_all;

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_names

my $names = $synth->recall_names;

Return all the setting names.

remove_setting

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

Remove a setting given an id.

remove_settings

$synth->remove_settings(name => $name);

Remove all settings for a given name.

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_yaml

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

Import a specific set of patches in the settings, by providing them in the options.

Option defaults:

file    = undef
string  = undef
patches = undef

graphviz

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

Visualize a patch of settings with the GraphViz2 module.

Option defaults:

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

SEE ALSO

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

GraphViz2

Moo

Mojo::JSON

Mojo::SQLite

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)