Skip to content

Commit

Permalink
Osc assignment revisions ; UI revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
vlcoo authored May 4, 2022
1 parent 397d020 commit ba34e73
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 126 deletions.
121 changes: 38 additions & 83 deletions Channel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import java.util.Stack;

public class ChannelOsc {
HashMap<Integer, SoundObject> current_notes; // Pairs <note midi code, oscillator object>
Env[] circular_array_envs;
int curr_env_index = 0;
float curr_global_amp = 1.0; // channel volume (0.0 to 1.0)
float amp_multiplier = 1.0; // basically expression
float amp_multiplier = 1.0; // basically expression
float curr_global_bend = 0.0; // channel pitch bend (-curr_bend_range to curr_bend_range semitones)
float curr_global_pan = 0.0; // channel stereo panning (-1.0 to 1.0)
float curr_bend_range = 2.0; // channel pitch bend range +/- semitones... uh, sure.
Expand All @@ -16,7 +14,6 @@ public class ChannelOsc {
String please_how_many_midi_params_are_there = "dw, around 100+"; // darn.
boolean silenced = false; // mute button
int osc_type;
float[] env_values;
Oscillator osc;
float pulse_width = 0.5;
ChannelDisplay disp;
Expand All @@ -27,17 +24,16 @@ public class ChannelOsc {
float last_amp = 0.0;
float last_freq = 0;
int last_notecode = -1;
int midi_program = 0;


ChannelOsc() {
current_notes = new HashMap<Integer, SoundObject>();
circular_array_envs = new Env[CIRCULAR_ARR_SIZE];
}


ChannelOsc(int osc_type) {
current_notes = new HashMap<Integer, SoundObject>();
circular_array_envs = new Env[CIRCULAR_ARR_SIZE];
set_osc_type(osc_type);
}

Expand All @@ -64,9 +60,13 @@ public class ChannelOsc {

void play_note(int note_code, int velocity) {
if (curr_global_amp <= 0 || silenced) return;
if (osc_type == 4) {
play_drum(note_code, velocity);
return;
}
stop_note(note_code);

int mod_note_code = floor( note_code + curr_noteDetune + player.ktrans.transform[(note_code - 2 + player.mid_rootnote) % 12] );
float mod_note_code = note_code + curr_noteDetune + player.ktrans.transform[(note_code - 2 + player.mid_rootnote) % 12];
float freq = midi_to_freq(mod_note_code);
float amp = map(velocity, 0, 127, 0.0, 1.0);

Expand All @@ -78,32 +78,38 @@ public class ChannelOsc {
}
s.pan(curr_global_pan);
s.amp(amp * (osc_type == 1 || osc_type == 2 ? 0.12 : 0.05) * curr_global_amp * amp_multiplier); // give a volume boost to TRI and SIN

/*Env e = circular_array_envs[curr_env_index];
if (e == null) {
e = new Env(PARENT);
circular_array_envs[curr_env_index] = e;
}*/
if (osc_type == 0) ((Pulse) s).width(pulse_width);

if (env_values != null && env_values.length == 4) {
Env e = new Env(PARENT);
e.play(s, env_values[0], env_values[1], env_values[2], env_values[3]); // will come back to envelopes... great potential but buggy :(
}
else s.play();
s.play();

last_amp = amp;
last_freq = freq;
last_notecode = mod_note_code;
/*curr_env_index++;
if (curr_env_index >= CIRCULAR_ARR_SIZE) curr_env_index = 0;*/
last_notecode = floor(mod_note_code);
}


void play_drum(int note_code, int velocity) {
float amp = map(velocity, 0, 127, 0.0, 1.0);

int sample_code = note_code_to_percussion(note_code);
SoundFile s = (SoundFile) samples[sample_code-1];
if (s == null || s.isPlaying()) return;

s.amp(amp * 0.32 * curr_global_amp * amp_multiplier);
s.play();

last_amp = amp;
last_freq = sample_code;
last_notecode = note_code;
}


void stop_note(int note_code) {
SoundObject s = current_notes.get(note_code);
if (s == null) return;
s.stop();
if (osc_type != 4) {
SoundObject s = current_notes.get(note_code);
if (s == null) return;
s.stop();
}

last_amp = 0.0;
last_freq = 0.0;
Expand All @@ -122,20 +128,16 @@ public class ChannelOsc {
else this.osc_type = int(osc_type);
}

void set_env_values(float[] env_values) {
this.env_values = env_values;
}


void set_expression(int value) {
amp_multiplier = map(value, 0, 127, 0.0, 1.0);
set_all_oscs_amp();
if (osc_type != 4) set_all_oscs_amp();
}


void set_volume(int value) {
curr_global_amp = map(value, 0, 127, 0.0, 1.0);
set_all_oscs_amp();
if (osc_type != 4) set_all_oscs_amp();
}


Expand All @@ -160,7 +162,8 @@ public class ChannelOsc {


void set_bend(int bits_lsb, int bits_msb) {
// i can't believe i finally achieved this...
if (osc_type == -1) return; // no bend for drums...

int value = (bits_msb << 7) + bits_lsb;
curr_global_bend = map(value, 0, 16383, -1.0, 1.0) * curr_bend_range;
float freq_ratio = (float) Math.pow(2, curr_global_bend / 12.0);
Expand All @@ -184,8 +187,8 @@ public class ChannelOsc {

void set_muted(boolean how) {
if (how) shut_up();
silenced = how;
disp.button_mute.set_pressed(how);
silenced = how;
}


Expand All @@ -211,56 +214,6 @@ public class ChannelOsc {



class ChannelOscDrum extends ChannelOsc {
SoundFile[] samples;


ChannelOscDrum() {
super();

// preloading samples...
samples = new SoundFile[4];
for (int i = 1; i <= samples.length; i++) {
samples[i-1] = new SoundFile(PARENT, "samples/" + i + ".wav");
}
}


void play_note(int note_code, int velocity) {
if (curr_global_amp <= 0 || silenced) return;

float amp = map(velocity, 0, 127, 0.0, 1.0);

int sample_code = note_code_to_percussion(note_code);
SoundFile s = (SoundFile) samples[sample_code-1];
if (s == null || s.isPlaying()) return;

s.amp(amp * 0.22 * curr_global_amp);
s.play();

last_amp = amp;
last_freq = sample_code;
last_notecode = note_code;
}


void stop_note(int note_code) {
last_amp = 0.0;
last_freq = 0;
last_notecode = -1;
}


void set_volume(int volume) {
curr_global_amp = map(volume, 0, 127, 0.0, 1.0);
}


void set_bend(int bits_lsb, int bits_msb) {} // no bend for drums!!
}



Oscillator get_new_osc(int osc_type) {
// This notation will be used
switch (osc_type) {
Expand All @@ -270,7 +223,9 @@ Oscillator get_new_osc(int osc_type) {
return new TriOsc(PARENT);
case 2:
return new SinOsc(PARENT);
default:
case 3:
return new SawOsc(PARENT);
default:
return null;
}
}
41 changes: 32 additions & 9 deletions LabsModule.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class LabsModule extends PApplet {


public void settings() {
this.size(210, 300);
if (osname.contains("Windows")) this.size(210, 356);
else this.size(210, 330);
}


Expand Down Expand Up @@ -38,13 +39,15 @@ public class LabsModule extends PApplet {
b2.show_label = false;
Button b3 = new Button("tempo", "tempo");
b3.show_label = false;
Button b7 = new Button("overrideOscs", "overrideOscs");
b7.show_label = false;
Button b4 = new Button("transform", "transform");
b4.show_label = false;
Button b5 = new Button("sysSynth", "sysSynth");
b5.show_label = false;
Button b6 = new Button("midiIn", "midiIn");
b6.show_label = false;
Button[] bs = new Button[] {b1, b2, b3, b4, b5, b6};
Button[] bs = new Button[] {b1, b2, b3, b7, b4, b5, b6};
all_buttons = new ButtonToolbar(8, 45, 0, 1.3, bs);

}
Expand All @@ -66,7 +69,7 @@ public class LabsModule extends PApplet {
player.set_all_freqDetune(val);
}
catch (NumberFormatException nfe) {
ui.showErrorDialog("Invalid value. Examples: 10, -90.2, 0, 167.74", "Can't");
ui.showErrorDialog("Invalid value. Examples: 3, -10.2, 0, 67.74", "Can't");
}
catch (NullPointerException npe) {}
}
Expand All @@ -77,7 +80,7 @@ public class LabsModule extends PApplet {
player.set_all_noteDetune(val);
}
catch (NumberFormatException nfe) {
ui.showErrorDialog("Invalid value. Examples: 4, -10.2, 0, 8.74", "Can't");
ui.showErrorDialog("Invalid value. Examples: 4, -1.2, 0, 8.74", "Can't");
}
catch (NullPointerException npe) {}
}
Expand All @@ -94,6 +97,24 @@ public class LabsModule extends PApplet {
catch (NullPointerException npe) {}
}

else if (all_buttons.collided("overrideOscs", this)) {
String selection = ui.showSelectionDialog(
"Override all channels with which oscillator?",
"LabsModule",
Arrays.asList("Pulse W0.125", "Pulse W0.25", "Pulse W0.5", "Pulse W0.75", "Triangle", "Sine", "Saw")
);

if (selection != null) {
if (selection.equals("Pulse W0.125")) player.set_all_osc_types(0.125);
if (selection.equals("Pulse W0.25")) player.set_all_osc_types(0.25);
if (selection.equals("Pulse W0.5")) player.set_all_osc_types(0.5);
if (selection.equals("Pulse W0.75")) player.set_all_osc_types(0.75);
if (selection.equals("Triangle")) player.set_all_osc_types(1);
if (selection.equals("Sine")) player.set_all_osc_types(2);
if (selection.equals("Saw")) player.set_all_osc_types(3);
}
}

else if (all_buttons.collided("transform", this)) {
String selection = new UiBooster().showSelectionDialog(
"New key/chord mode?",
Expand Down Expand Up @@ -135,7 +156,8 @@ public class LabsModule extends PApplet {
void mouseMoved() {
if (all_buttons.collided("freqDetune", this) ||
all_buttons.collided("noteDetune", this) ||
all_buttons.collided("tempo", this) ||
all_buttons.collided("tempo", this) ||
all_buttons.collided("overrideOscs", this) ||
all_buttons.collided("transform", this) ||
all_buttons.collided("sysSynth", this) ||
all_buttons.collided("midiIn", this)
Expand All @@ -161,15 +183,16 @@ public class LabsModule extends PApplet {
this.textFont(fonts[2]);
this.fill(t.theme[0]);
this.textAlign(CENTER, CENTER);
this.text("Experimental options!\nUse at own risk.", this.width/2, 22);
this.text("Experimental options!\nUse at your own risk.", this.width/2, 22);

this.textFont(fonts[1]);
this.text(player.last_freqDetune, 179, 60);
this.text(player.last_noteDetune, 179, 99);
this.text("x" + player.seq.getTempoFactor(), 179, 138);
this.text(curr_transform, 179, 177);
this.text((player.system_synth ? "On" : "Off"), 179, 216);
this.text((player.midi_in_mode ? "On" : "Off"), 179, 255);
//this.text("x", 179, 177);
this.text(curr_transform, 179, 216);
this.text((player.system_synth ? "On" : "Off"), 179, 255);
this.text((player.midi_in_mode ? "On" : "Off"), 179, 294);

all_buttons.redraw(this);
}
Expand Down
16 changes: 14 additions & 2 deletions P3synth.pde
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import java.awt.*;
import processing.awt.PSurfaceAWT;

final processing.core.PApplet PARENT = this;
final float VERCODE = 22.99;
final float VERCODE = 23.11;
final float OVERALL_VOL = 0.7;

Frame frame;
String osname;
Player player;
LabsModule win_labs;
DnDListener dnd_listener;
PImage[] logo_anim;
PImage[] osc_type_textures;
PImage logo_icon;
PFont[] fonts;
SoundFile[] samples;
ThemeEngine t;
ButtonToolbar media_buttons;
ButtonToolbar setting_buttons;
Expand All @@ -27,7 +29,9 @@ WaitingDialog dialog_meta_msgs;
HashMap<String, String> config_map;

void settings() {
size(724, 436);
osname = System.getProperty("os.name");
if (osname.contains("Windows")) size(724, 460);
else size(724, 430);
}


Expand All @@ -49,6 +53,7 @@ void setup() {
setup_fonts();
setup_buttons();
setup_config();
setup_samples();
t.set_theme(config_map.get("theme name"));

player = new Player();
Expand Down Expand Up @@ -157,6 +162,13 @@ void redraw_all() {
}


void setup_samples() {
samples = new SoundFile[4];
for (int i = 1; i <= samples.length; i++) {
samples[i-1] = new SoundFile(PARENT, "samples/" + i + ".wav");
}
}


void setup_images() {
logo_anim = new PImage[8];
Expand Down
Loading

0 comments on commit ba34e73

Please sign in to comment.