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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
/* BSE - Better Sound Engine -*-mode: c;-*-
* Copyright (C) 2002 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License should ship along
* with this library; if not, see http://www.gnu.org/copyleft/.
*/
#include "bseplugin.h"
#include "bseprocedure.h"
#include "bsescripthelper.h"
#include "bseserver.h"
#include "bsemath.h" /* bse_temp_freq */
#include "bsemain.h"
#include <string.h> /* strchr */
#include <stdlib.h> /* strtol */
AUTHORS = "Tim Janik <timj@gtk.org>";
LICENSE = "GNU Lesser General Public License";
PROCEDURE (bse-note-to-freq, "Note to Freq") {
HELP = "Retrieve the frequency of a certain note.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = bse_pspec_note_simple ("note", "Note", NULL, SFI_PARAM_STANDARD);
IN = bse_param_spec_fine_tune ("fine_tune", "Fine Tune", NULL);
OUT = sfi_pspec_real ("frequency", "Frequency", NULL,
BSE_KAMMER_FREQUENCY, 0, BSE_MAX_FREQUENCY, 0.1,
SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
int note = sfi_value_get_int (in_values++);
int fine_tune = sfi_value_get_int (in_values++);
BseNoteDescription *info;
gfloat freq;
/* action */
info = bse_note_description (musical_tuning, note, fine_tune);
if (!info->name)
freq = 0;
else
freq = info->freq;
bse_note_description_free (info);
/* set out params */
sfi_value_set_real (out_values++, freq);
return BSE_ERROR_NONE;
}
PROCEDURE (bse-note-from-freq, "Note from Freq") {
HELP = "Retrieve the note of a certain frequency.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = sfi_pspec_real ("frequency", "Frequency", NULL,
BSE_KAMMER_FREQUENCY, 0, BSE_MAX_FREQUENCY, 0.1,
SFI_PARAM_STANDARD);
OUT = sfi_pspec_note ("note", "Note", NULL, SFI_KAMMER_NOTE, SFI_MIN_NOTE, SFI_MAX_NOTE, TRUE, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
float frequency = sfi_value_get_real (in_values++);
/* set out params */
sfi_value_set_int (out_values++, bse_note_from_freq (musical_tuning, frequency));
return BSE_ERROR_NONE;
}
PROCEDURE (bse-note-describe, "Describe Note") {
HELP = "Describe a note, providing information about its octave, semitone, frequency, etc.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = bse_pspec_note_simple ("note", "Note", NULL, SFI_PARAM_STANDARD);
IN = bse_param_spec_fine_tune ("fine_tune", "Fine Tune", NULL);
OUT = bse_param_spec_boxed ("note-description", "Note Description", NULL,
BSE_TYPE_NOTE_DESCRIPTION, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
int note = sfi_value_get_int (in_values++);
int fine_tune = sfi_value_get_int (in_values++);
/* describe note */
bse_value_take_boxed (out_values++, bse_note_description (musical_tuning, note, fine_tune));
return BSE_ERROR_NONE;
}
PROCEDURE (bse-note-describe-from-freq, "Describe Note From Freq") {
HELP = "Describe a note, given its frequency.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = sfi_pspec_real ("freq", "Frequency", NULL,
BSE_KAMMER_FREQUENCY,
0, BSE_MAX_FREQUENCY,
10.0, SFI_PARAM_STANDARD);
OUT = bse_param_spec_boxed ("note-description", "Note Description", NULL,
BSE_TYPE_NOTE_DESCRIPTION, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
float freq = sfi_value_get_real (in_values++);
gint note;
/* describe note */
note = bse_note_from_freq (musical_tuning, freq);
bse_value_take_boxed (out_values++, bse_note_description (musical_tuning, note, 0));
return BSE_ERROR_NONE;
}
PROCEDURE (bse-note-from-string, "Note From String") {
HELP = "Describe a note, given its name and octave offset.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = sfi_pspec_string ("name", "Name", NULL,
"", SFI_PARAM_STANDARD);
OUT = bse_param_spec_boxed ("note-description", "Note Description", NULL,
BSE_TYPE_NOTE_DESCRIPTION, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
char *name = sfi_value_get_string (in_values++);
gint note;
/* describe note */
note = bse_note_from_string (name);
bse_value_take_boxed (out_values++, bse_note_description (musical_tuning, note, 0));
return BSE_ERROR_NONE;
}
PROCEDURE (bse-note-construct, "Note Construction") {
HELP = "Describe a note, given its semitone, octave and fine tune.";
IN = bse_param_spec_enum ("musical_tuning", "Musical Tuning", NULL,
BSE_MUSICAL_TUNING_12_TET, BSE_TYPE_MUSICAL_TUNING_TYPE, SFI_PARAM_STANDARD);
IN = sfi_pspec_int ("semitone", NULL, NULL,
9, 0, 11, 1,
SFI_PARAM_STANDARD);
IN = bse_param_spec_octave ("octave", NULL, NULL);
IN = bse_param_spec_fine_tune ("fine_tune", "Fine Tune", NULL);
OUT = bse_param_spec_boxed ("note-description", "Note Description", NULL,
BSE_TYPE_NOTE_DESCRIPTION, SFI_PARAM_STANDARD);
}
BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
BseMusicalTuningType musical_tuning = g_value_get_enum (in_values++);
guint semitone = sfi_value_get_int (in_values++);
int octave = sfi_value_get_int (in_values++);
int fine_tune = sfi_value_get_int (in_values++);
int note;
/* describe note */
note = BSE_NOTE_GENERIC (octave, semitone);
bse_value_take_boxed (out_values++, bse_note_description (musical_tuning, note, fine_tune));
return BSE_ERROR_NONE;
}
PROCEDURE (bse-type-options, "Type Options") {
HELP = "Retrieve the options of a specific type.";
IN = sfi_pspec_string ("type", NULL, NULL, NULL, SFI_PARAM_STANDARD);
OUT = sfi_pspec_string ("string", NULL, NULL, NULL, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
gchar *stype = sfi_value_get_string (in_values++);
GType type;
/* check parameters */
if (!stype)
return BSE_ERROR_PROC_PARAM_INVAL;
type = g_type_from_name (stype);
/* set out params */
sfi_value_set_string (out_values++, type ? bse_type_get_options (type) : NULL);
return BSE_ERROR_NONE;
}
PROCEDURE (bse-type-blurb, "Type Blurb") {
HELP = "Retrieve the description of a specific type.";
IN = sfi_pspec_string ("type", NULL, NULL, NULL, SFI_PARAM_STANDARD);
OUT = sfi_pspec_string ("string", NULL, NULL, NULL, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
gchar *stype = sfi_value_get_string (in_values++);
GType type;
/* check parameters */
if (!stype)
return BSE_ERROR_PROC_PARAM_INVAL;
type = g_type_from_name (stype);
/* set out params */
sfi_value_set_string (out_values++, type ? bse_type_get_blurb (type) : NULL);
return BSE_ERROR_NONE;
}
PROCEDURE (bse-type-authors, "Type Authors") {
HELP = "Retrieve the authors who implemented a specific type.";
IN = sfi_pspec_string ("type", NULL, NULL, NULL, SFI_PARAM_STANDARD);
OUT = sfi_pspec_string ("string", NULL, NULL, NULL, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
gchar *stype = sfi_value_get_string (in_values++);
GType type;
/* check parameters */
if (!stype)
return BSE_ERROR_PROC_PARAM_INVAL;
type = g_type_from_name (stype);
/* set out params */
sfi_value_set_string (out_values++, type ? bse_type_get_authors (type) : NULL);
return BSE_ERROR_NONE;
}
PROCEDURE (bse-type-license, "Type License") {
HELP = "Retrieve the license of a type impementation.";
IN = sfi_pspec_string ("type", NULL, NULL, NULL, SFI_PARAM_STANDARD);
OUT = sfi_pspec_string ("string", NULL, NULL, NULL, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
gchar *stype = sfi_value_get_string (in_values++);
GType type;
/* check parameters */
if (!stype)
return BSE_ERROR_PROC_PARAM_INVAL;
type = g_type_from_name (stype);
/* set out params */
sfi_value_set_string (out_values++, type ? bse_type_get_license (type) : NULL);
return BSE_ERROR_NONE;
}
static gdouble
str2num (const gchar *str,
guint nth)
{
gchar *num_any = ".0123456789", *num_first = num_any + 1;
while (nth--)
{
/* skip number */
if (*str && strchr (num_first, *str))
do
str++;
while (*str && strchr (num_any, *str));
/* and trailing non-number stuff */
while (*str && !strchr (num_first, *str))
str++;
if (!*str)
return 0; /* no number */
}
if (strchr (num_first, *str))
return g_strtod (str, NULL);
return 0; /* no number */
}
PROCEDURE (bse-string-extract-number, "String Extract Number") {
HELP = "Retrieve numbers from a string.";
IN = sfi_pspec_string ("string", NULL, NULL, NULL, SFI_PARAM_STANDARD);
IN = sfi_pspec_string ("format", NULL, NULL, NULL, SFI_PARAM_STANDARD);
IN = sfi_pspec_real ("aux_base", NULL, NULL, 0, -SFI_MAXNUM, SFI_MAXNUM, 0, SFI_PARAM_STANDARD);
IN = sfi_pspec_real ("dflt", NULL, NULL, 0, -SFI_MAXNUM, SFI_MAXNUM, 0, SFI_PARAM_STANDARD);
OUT = sfi_pspec_real ("number", NULL, NULL, 0, -SFI_MAXNUM, SFI_MAXNUM, 0, SFI_PARAM_STANDARD);
} BODY (BseProcedureClass *proc,
const GValue *in_values,
GValue *out_values)
{
/* extract parameter values */
gchar *string = sfi_value_get_string (in_values++);
gchar *format = sfi_value_get_string (in_values++);
SfiReal aux_base = sfi_value_get_real (in_values++);
SfiReal dflt = sfi_value_get_real (in_values++);
SfiReal number = dflt;
if (string)
{
if (format)
{
gchar *base, *ep = NULL;
switch (*format)
{
glong l;
case '#':
number = str2num (++format, 0);
break;
case 'n':
l = strtol (++format, &ep, 10);
number = str2num (string, l);
break;
case 'b':
l = strtol (++format, &ep, 10);
base = g_path_get_basename (string);
number = str2num (base ? base : string, l);
g_free (base);
break;
case 'c':
format++;
number = aux_base;
if (*format == '*')
{
gdouble factor = g_strtod (++format, &ep);
number *= factor;
}
else
ep = (char*) format;
break;
default:
/* ("Invalid chunk format given: modifier `%c'", *format) */
number = 0;
break;
}
if (ep && *ep)
{
if (*ep == 'm') /* interpret d as midi note and return freq */
number = bse_temp_freq (BSE_CONFIG (kammer_freq),
number - BSE_CONFIG (midi_kammer_note));
else /* ("Invalid chunk format given: postmodifier `%c'", *ep) */
number = 0;
}
}
else
number = str2num (string, 0);
}
sfi_value_set_real (out_values++, number);
return BSE_ERROR_NONE;
}
|