summaryrefslogtreecommitdiff
path: root/source/MrsWatsonOptions.c
blob: 0bfb69791bb70812ee7dc81dc39bece7397a4359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//
// MrsWatsonOptions.c - MrsWatson
// Created by Nik Reiman on 10/23/12.
// Copyright (c) 2012 Teragon Audio. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//

#include <stdio.h>

#include "audio/AudioSettings.h"
#include "base/File.h"

#include "MrsWatsonOptions.h"

ProgramOptions newMrsWatsonOptions(void)
{
    ProgramOptions options = newProgramOptions(NUM_OPTIONS);

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_BLOCKSIZE,
                          "blocksize",
                          "Blocksize in frames to use for processing. If input source is not an even \
multiple of the blocksize, then empty frames will be added to the last block.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetNumber(options, OPTION_BLOCKSIZE, (const float)getBlocksize());

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_CHANNELS,
                          "channels",
                          "Number of channels for output source. If the input source specifies a channel \
count, then that value will override the one set by this option.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetNumber(options, OPTION_CHANNELS, (const float)getNumChannels());

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_COLOR_LOGGING,
                          "color",
                          "Colored logging output. Argument can be 'auto', 'force', or 'none'. If no \
argument given, 'force' is assumed. If attached to a terminal device, color is \
used automatically unless 'none' is given to this option.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeOptional));
    programOptionsSetCString(options, OPTION_COLOR_LOGGING, "auto");

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_COLOR_TEST,
                          "color-test",
                          "Run a test of all color output combinations.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));
    options->options[OPTION_COLOR_TEST]->hideInHelp = true;

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_CONFIG_FILE,
                          "config-file",
                          "Load options from a configuration file. The file will be read *after* other \
options have been parsed, so any options given on the command line will be overriden \
by those from the file. The file should be plain text, and one argument per line, \
like so:\n\n\
\t--plugin-root\n\
\t/path/to/my/plugins\n\
\t--verbose",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_DISPLAY_INFO,
                          "display-info",
                          "Print information about each plugin in the chain.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_ERROR_REPORT,
                          "error-report",
                          "Generate an error report zipfile on the desktop.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_LIST_FILE_TYPES,
                          "list-file-types",
                          "Print a list of supported file types for input/output sources.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_HELP,
                          "help",
                          "With no arguments, prints a summary of options and their default settings. \
Otherwise, extended help can be printed for an individual option given by \
[argument], or use 'full' to print extended help for all options.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeOptional));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_INPUT_SOURCE,
                          "input",
                          "Input source to use for processing, where the file type is determined from \
the extension. Run with --list-file-types to see a list of supported types. Use \
'-' to read from stdin.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_LIST_PLUGINS,
                          "list-plugins",
                          "List available plugins. Useful for determining if a plugin can be 'seen'.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_LOG_FILE,
                          "log-file",
                          "Save logging output to the given file instead of the terminal's standard error.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetCString(options, OPTION_LOG_FILE, "log.txt");

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_LOG_LEVEL,
                          "log-level",
                          "Logging level to use. Options include: debug, info, warn, error. Critical \
errors are always logged to console regardless of this setting.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetCString(options, OPTION_LOG_LEVEL, "info");

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_MAX_TIME,
                          "max-time",
                          "Force processing to stop after <argument> milliseconds, regardless of the \
input source length. Mostly useful when using internal plugins as sources.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_MIDI_SOURCE,
                          "midi-file",
                          "MIDI file to read events from. Required if processing an instrument plugin.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_OUTPUT_SOURCE,
                          "output",
                          "Output source to write processed data to, where the file type is determined \
from the extension. Run with --list-file-types to see a list of supported types. \
Use '-' to write to stdout..",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeOptional));
    programOptionsSetCString(options, OPTION_OUTPUT_SOURCE, "out.wav");

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_PARAMETER,
                          "parameter",
                          "Set a parameter in a plugin. May be specified multiple times, but can only \
set parameters for the first plugin in a chain. Parameter indexes for plugins \
can be found with the --display-info option. Use comma-separated arguments for \
index/value, for example:\n\n\
\t--parameter 1,0.3 --parameter 0,0.75",
                          NO_SHORT_FORM,
                          kProgramOptionTypeList,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_PLUGIN,
                          "plugin",
                          "Plugin(s) to process. Multiple plugins can given in a semicolon-separated \
list, in which case they will be placed into a chain in the order specified. \
Note that if you specify multiple plugins, you will have to put the argument \
in quotes or else the shell may mis-interpret it as multiple commands. \
Instrument plugins must appear first in any chains. Plugins are searched for in \
the --plugin-root directory, the current directory, and the standard locations \
for the OS. File extensions are added automatically to plugin names. Each plugin \
may be followed by a comma with a program to be loaded, which should be of the \
corresponding file format for the respective plugin. For shell plugins (like \
Waves), use --display-info to get a list of sub-plugin ID's and then use a colon \
to indicate which plugin to load. Examples:\n\n\
\t--plugin LFX-1310\n\
\t--plugin 'AutoTune,KayneWest.fxp;Compressor,SoftKnee.fxp;Limiter'\n\
\t--plugin 'WavesShell-VST' --display-info (list shell sub-plugins)\n\
\t--plugin 'WavesShell-VST:IDFX' (load a shell plugins)",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_PLUGIN_ROOT,
                          "plugin-root",
                          "Custom non-system directory to use when searching for plugins. Will be searched \
  before system directories if given.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_QUIET,
                          "quiet",
                          "Only log critical errors.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_REALTIME,
                          "realtime",
                          "Simulate running in realtime by sleeping for any remaining time needed to process \
the given block. Some plugins which are unable to do offline rendering may require this \
option in order to function properly.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_SAMPLE_RATE,
                          "sample-rate",
                          "Sample rate to use when processing. If the input source specifies its own \
sample rate, that value will override the one set by this option. No error checking \
is done for sample rates (other than requiring it to be greater than 0), however \
using unusual sample rates will probably result in weird behavior from plugins.",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetNumber(options, OPTION_SAMPLE_RATE, (const float)getSampleRate());

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_TEMPO,
                          "tempo",
                          "Tempo to use when processing.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetNumber(options, OPTION_TEMPO, getTempo());

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_TIME_SIGNATURE,
                          "time-signature",
                          "Set the global time signature. Should be a string formatted like \"3/4\".",
                          NO_SHORT_FORM,
                          kProgramOptionTypeString,
                          kProgramOptionArgumentTypeRequired));
    // This is kind of cheating, because the default time signature could be
    // anything. Realistically we know it will always be hardcoded to 4/4, so this
    // hardcoded string is also relatively safe.
    programOptionsSetCString(options, OPTION_TIME_SIGNATURE, "4/4");

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_VERBOSE,
                          "verbose",
                          "Verbose logging. Logging output is printed in the following form:\n\
(Level) (Frames processed) (Elapsed time in ms) (Logging message)",
                          HAS_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_VERSION,
                          "version",
                          "Print full program version and copyright information.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeEmpty,
                          kProgramOptionArgumentTypeNone));

    programOptionsAdd(options, newProgramOptionWithName(
                          OPTION_ZEBRA_SIZE,
                          "zebra-size",
                          "Alternate logging output colors every <argument> frames.",
                          NO_SHORT_FORM,
                          kProgramOptionTypeNumber,
                          kProgramOptionArgumentTypeRequired));
    programOptionsSetNumber(options, OPTION_ZEBRA_SIZE, (const float)getSampleRate());

    return options;
}

void printMrsWatsonQuickstart(const char *argvName)
{
    File argvFile = newFileWithPathCString(argvName);
    const char *programBasename = argvFile->absolutePath->data;
    printf("Run with '--help full' to see extended help for all options.\n");
    printf("Quickstart for effects: %s -p <plugin> -i <input file> -o <output>\n", programBasename);
    printf("Quickstart for instruments: %s -p <name> -m <midi file> -o <output>\n", programBasename);
    printf("\n");
    freeFile(argvFile);
}