Skip to content

Commit

Permalink
sfont~
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Aug 27, 2024
1 parent 1bd1668 commit b6ca6de
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 91 deletions.
43 changes: 24 additions & 19 deletions Code_source/Compiled/audio/sfont~/sfont~.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static void sfont_float(t_sfont *x, t_float f);

static void sfont_getversion(void){
post("[sfont~] is using fluidlite 1.2.2");
post("\n");
}

static void sfont_verbose(t_sfont *x, t_floatarg f){
Expand Down Expand Up @@ -247,16 +246,15 @@ static void sfont_sel_tuning(t_sfont *x, t_float bank, t_float pgm, t_float ch){
static void set_key_tuning(t_sfont *x, double *pitches){
int ch = x->x_tune_ch, bank = x->x_tune_bank, pgm = x->x_tune_prog;
const char* name = x->x_tune_name->s_name;

int key[128];
for(int i = 0; i < 128; i++) key[i] = i;

for(int i = 0; i < 128; i++)
key[i] = i;
fluid_synth_tune_notes(x->x_synth, bank, pgm, 128, key, pitches, 1, name);

if(ch > 0)
fluid_synth_activate_tuning(x->x_synth, ch-1, bank, pgm, 1);
else if(!ch) for(int i = 0; i < x->x_ch; i++)
fluid_synth_activate_tuning(x->x_synth, i, bank, pgm, 1);
else if(!ch)
for(int i = 0; i < x->x_ch; i++)
fluid_synth_activate_tuning(x->x_synth, i, bank, pgm, 1);
}

static void sfont_set_tuning(t_sfont *x, t_symbol *s, int ac, t_atom *av){
Expand All @@ -270,7 +268,6 @@ static void sfont_set_tuning(t_sfont *x, t_symbol *s, int ac, t_atom *av){
x->x_tune_name = atom_getsymbolarg(3, ac, av);
else
x->x_tune_name = gensym("Custom-tuning");

}

static void sfont_remap(t_sfont *x, t_symbol *s, int ac, t_atom *av){
Expand All @@ -282,21 +279,29 @@ static void sfont_remap(t_sfont *x, t_symbol *s, int ac, t_atom *av){
set_key_tuning(x, pitches);
}
else
post("[sinfo~]: remap needs 128 key values");
post("[sfont~]: remap needs 128 key values");
}

static void sfont_scale(t_sfont *x, t_symbol *s, int ac, t_atom *av){
s = NULL;
if(!ac){
set_key_tuning(x, NULL);
return;
int i, div, n1, n_m1;
double *scale;
if(!ac){ // default, equal temperament
scale = calloc(sizeof(double), 13);
for(i = 0; i < 13; i++){
scale[i] = i * 100;
post("def scale[%d] = %d", i, (int)scale[i]);
}
}
else{
scale = calloc(sizeof(double), ac);
for(i = 0; i < ac; i++){
scale[i] = atom_getfloatarg(i, ac, av);
post("scale[%d] = %d", i, (int)scale[i]);
}
}
double* scale = calloc(sizeof(double), ac);
int n_m1 = ac-1;
int i;
for(i = 0; i < ac; i++) // set array{
scale[i] = atom_getfloatarg(i, ac, av);
int n1 = -(int)x->x_base, div;
n_m1 = ac-1;
n1 = -(int)x->x_base;
n1 -= (n_m1-1);
div = n1 / n_m1;
float shift_down = div * scale[n_m1] + x->x_base * 100.;
Expand Down Expand Up @@ -545,7 +550,7 @@ static void fluid_do_load(t_sfont *x, t_symbol *name){
const char* pname = fluid_preset_get_name(preset);
t_atom at[1];
SETSYMBOL(&at[0], gensym(pname));
outlet_anything(x->x_info_out, gensym("pname"), 1, at);
outlet_anything(x->x_info_out, gensym("preset"), 1, at);
}
}
else
Expand Down
145 changes: 73 additions & 72 deletions Documentation/Help-files/sfont~-help.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 537 58 561 603 10;
#N canvas 486 43 561 603 10;
#X obj 306 4 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc 0;
#N canvas 382 141 749 319 (subpatch) 0;
#X coords 0 -1 1 1 252 42 2 0 0;
Expand Down Expand Up @@ -80,15 +80,15 @@
#X obj 362 261 else/display;
#X obj 232 269 else/display;
#X obj 375 365 print info;
#X obj 232 360 else/sfont~ -v -ch 32 sf/waves.sf2, f 21;
#X msg 246 305 dump;
#X text 528 220 If the verbosity flag is given (-v) \, [sfont~] prints the version as in the 'version' message when loading the object. When loading a file \, it prints the soundfont name \, its banks \, programs and preset names (which also given by the "info" message on Pd's window or by the 'dump' message in the 'info' outlet). In verbosity mode \, the terminal window also prints bank \, program and preset name when you load a program or if it fails. Verbosity is also set by the "verbose" message. The preset name is also output as a 'preset' message in the rightmost "info" outlet when loading a program., f 67;
#X obj 232 360 else/sfont~ -v -ch 32 sf/waves.sf2, f 21;
#X connect 0 0 2 0;
#X connect 1 0 0 0;
#X connect 2 0 3 1;
#X connect 3 0 5 0;
#X connect 4 0 3 0;
#X connect 5 0 51 0;
#X connect 5 0 53 0;
#X connect 6 0 40 1;
#X connect 7 0 6 0;
#X connect 8 0 40 2;
Expand All @@ -99,23 +99,23 @@
#X connect 14 0 41 2;
#X connect 15 0 16 0;
#X connect 16 0 14 0;
#X connect 22 0 51 0;
#X connect 22 0 53 0;
#X connect 23 0 24 0;
#X connect 24 0 51 0;
#X connect 26 0 51 0;
#X connect 31 0 51 0;
#X connect 24 0 53 0;
#X connect 26 0 53 0;
#X connect 31 0 53 0;
#X connect 32 0 31 0;
#X connect 39 0 47 0;
#X connect 40 0 49 0;
#X connect 41 0 48 0;
#X connect 45 0 4 0;
#X connect 48 0 51 0;
#X connect 49 0 51 0;
#X connect 51 0 46 0;
#X connect 51 1 46 1;
#X connect 51 2 39 0;
#X connect 51 2 50 0;
#X connect 52 0 51 0;
#X connect 48 0 53 0;
#X connect 49 0 53 0;
#X connect 51 0 53 0;
#X connect 53 0 46 0;
#X connect 53 1 46 1;
#X connect 53 2 39 0;
#X connect 53 2 50 0;
#X restore 493 297 pd basic;
#N canvas 623 71 417 561 MIDI-in 0;
#N canvas 396 60 637 710 MIDI-input 0;
Expand Down Expand Up @@ -324,7 +324,7 @@
#X text 127 494 -v: set to verbosity mode, f 61;
#X text 127 509 -ch <float>: set number of channels from 16 (default) to 256, f 61;
#X text 127 523 -g <float>: overall gain from 0.1 to 1 (default 0.4), f 61;
#N canvas 530 583 550 433 ALL 0;
#N canvas 443 419 550 433 ALL 0;
#X text 44 161 bank <float \, float> -;
#X text 38 119 touch <float \, float> -;
#X text 44 133 polytouch <f \, f \, f> -;
Expand Down Expand Up @@ -377,7 +377,7 @@
#X text 134 264 dump -;
#X text 178 264 outputs soundfont information on rightmost outlet, f 51;
#X restore 238 395 pd ALL Messages;
#N canvas 360 197 760 568 tuning_&_more 0;
#N canvas 413 196 760 568 tuning_&_more 0;
#X msg 70 243 panic;
#X floatatom 167 374 10 0 0 0 - - - 0;
#X msg 167 397 pan \$1;
Expand All @@ -393,34 +393,30 @@
#X obj 105 186 + 1;
#X obj 105 163 hradio 15 1 0 8 empty empty empty 0 -8 0 10 #dfdfdf #000000 #000000 0;
#X text 231 163 channel;
#N canvas 638 133 604 694 tuning 0;
#N canvas 693 123 584 715 tuning 0;
#X text 113 94 bohlen-pierce;
#X text 126 115 quarter tones;
#X obj 67 31 loadbang;
#X msg 206 198 base 57;
#X msg 258 211 base 57;
#X text 136 143 equal temperament;
#X obj 206 252 s \$0-tuning;
#X msg 128 342 scale 0 180 350 500 700 850 1030 1200;
#X obj 128 460 s \$0-tuning;
#X msg 216 223 base 60;
#X obj 258 265 s \$0-tuning;
#X msg 59 304 scale 0 180 350 500 700 850 1030 1200;
#X obj 93 481 s \$0-tuning;
#X msg 268 236 base 60;
#X obj 67 232 s \$0-tuning;
#X text 103 57 eighth tones;
#X text 268 223 (default);
#X obj 52 646 s \$0-tuning;
#X msg 62 547 sel-tuning 0 0 2;
#X text 172 541 select bank 0 \, pgm 0 in ch 2, f 14;
#X obj 322 575 r \$0-tuning;
#X obj 299 608 outlet;
#X text 201 48 Initially loading an eighth note scale into bank 0 \, program 0 \, channel 1 by default., f 43;
#X text 208 177 Set fundamental;
#X text 366 341 an arbitrary scale;
#X text 80 291 set: bank 1 \, pgm 1 \, ch 2 and scale name;
#X msg 79 312 set-tuning 1 1 2 arbitrary;
#X text 152 506 select bank 1 \, pgm 1 in ch 1, f 14;
#X msg 42 510 sel-tuning 1 1 1;
#X msg 146 370 scale;
#X text 192 370 default (12 tone scale);
#X obj 299 511 bng 17 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000;
#X obj 91 675 s \$0-tuning;
#X msg 101 576 sel-tuning 0 0 2;
#X text 211 570 select bank 0 \, pgm 0 in ch 2, f 14;
#X obj 361 604 r \$0-tuning;
#X obj 338 637 outlet;
#X text 297 303 an arbitrary scale;
#X msg 93 353 set-tuning 1 1 2 arbitrary;
#X text 191 535 select bank 1 \, pgm 1 in ch 1, f 14;
#X msg 81 539 sel-tuning 1 1 1;
#X msg 111 391 scale;
#X text 157 391 default (12 tone scale);
#X obj 338 540 bng 17 250 50 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000;
#X msg 67 57 48 2;
#X msg 79 93 13 3;
#X msg 90 116 24 2;
Expand Down Expand Up @@ -464,10 +460,10 @@
#X connect 16 0 17 0;
#X connect 17 0 4 0;
#X connect 17 0 6 0;
#X restore 299 542 pd scale-generator;
#X text 419 541 <-- open;
#X text 323 512 generate scale;
#X obj 368 165 s \$0-tuning;
#X restore 338 571 pd scale-generator;
#X text 458 570 <-- open;
#X text 362 541 generate scale;
#X obj 368 138 s \$0-tuning;
#N canvas 342 235 477 288 remap 0;
#X obj 75 237 outlet;
#X obj 114 207 print;
Expand All @@ -485,41 +481,46 @@
#X connect 7 0 8 0;
#X connect 8 0 0 0;
#X connect 8 0 1 0;
#X restore 368 128 pd remap;
#X text 312 108 open to see 'remap' example, f 11;
#X text 276 392 set bank 0 \, pgm 0 in all channels, f 17;
#X msg 159 399 set-tuning 0 0 0;
#X msg 170 428 set-tuning 0 0 -1;
#X text 284 422 don't load in a channel (only store in a bank/pgm), f 26;
#X msg 75 579 unsel-tuning 1;
#X msg 84 610 unsel-tuning;
#X text 170 573 unselect tuning in channel 1, f 15;
#X text 168 604 unselect in all channels, f 12;
#X text 261 198 (decimal values allowed);
#X restore 368 111 pd remap;
#X text 312 91 open to see 'remap' example, f 11;
#X text 241 413 set bank 0 \, pgm 0 in all channels, f 17;
#X msg 124 420 set-tuning 0 0 0;
#X msg 135 449 set-tuning 0 0 -1;
#X text 249 443 don't load in a channel (only store in a bank/pgm), f 26;
#X msg 114 608 unsel-tuning 1;
#X msg 123 639 unsel-tuning;
#X text 209 602 unselect tuning in channel 1, f 15;
#X text 207 633 unselect in all channels, f 12;
#X text 313 211 (decimal values allowed);
#X obj 67 173 else/eqdiv;
#X obj 67 201 else/insert scale;
#X connect 2 0 27 0;
#X text 197 25 There are banks and programs just for tunings. You can load a tuning with the 'scale' message followed by a list of intervals in cents. Here we're initially loading an eighth note scale (by default \, it goes into bank 0 \, program 0 and channel 1).;
#X text 242 176 Set fundamental (starting point of the scale in MIDI Pitch), f 31;
#X text 320 236 (default \, middle C);
#X text 97 331 sets tuning <bank \, program \, channel & name> for a scale;
#X text 259 353 sets to bank 1 \, pgm 1 \, ch 2 and scale name;
#X connect 2 0 23 0;
#X connect 3 0 5 0;
#X connect 6 0 7 0;
#X connect 8 0 5 0;
#X connect 13 0 12 0;
#X connect 15 0 16 0;
#X connect 21 0 7 0;
#X connect 23 0 12 0;
#X connect 24 0 7 0;
#X connect 26 0 31 0;
#X connect 27 0 46 0;
#X connect 28 0 46 0;
#X connect 29 0 46 0;
#X connect 30 0 46 0;
#X connect 31 0 16 0;
#X connect 35 0 34 0;
#X connect 38 0 7 0;
#X connect 39 0 7 0;
#X connect 41 0 12 0;
#X connect 42 0 12 0;
#X connect 46 0 47 0;
#X connect 47 0 9 0;
#X connect 12 0 11 0;
#X connect 14 0 15 0;
#X connect 17 0 7 0;
#X connect 19 0 11 0;
#X connect 20 0 7 0;
#X connect 22 0 27 0;
#X connect 23 0 42 0;
#X connect 24 0 42 0;
#X connect 25 0 42 0;
#X connect 26 0 42 0;
#X connect 27 0 15 0;
#X connect 31 0 30 0;
#X connect 34 0 7 0;
#X connect 35 0 7 0;
#X connect 37 0 11 0;
#X connect 38 0 11 0;
#X connect 42 0 43 0;
#X connect 43 0 9 0;
#X restore 178 424 pd tuning;
#X text 360 325 Open [pd tuning] for more details. Note that this example uses the [eqdiv] object to generate scales with equal divisions and starts with an eighth tone scale., f 62;
#X text 324 375 The 'set-tuning' message sets a tuning bank \, a program number (both from 0-127) \, a MIDI channel and a tuning name - default values are (0 \, 0 \, 0 \, custom-tuning). The 'scale' message then sets the tuning into the bank/program and loads it into the channel for use. If you don't want to load the scale into any channel and just set it into a bank/program \, use '0' \, while '-1' loads it into all channels., f 68;
Expand Down

0 comments on commit b6ca6de

Please sign in to comment.