Skip to content

Commit

Permalink
Removed features not for release
Browse files Browse the repository at this point in the history
  • Loading branch information
vlcoo committed Nov 25, 2022
1 parent 8100fd9 commit 3a1e9ad
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 227 deletions.
64 changes: 23 additions & 41 deletions Channel.pde
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import processing.sound.*;
import java.util.Stack;
import java.util.ConcurrentModificationException;


public class ChannelOsc {
int id;
HashMap<Integer, RTSoundObject> current_notes; // Pairs <note midi code, oscillator object>
HashMap<Integer, SoundObject> current_notes; // Pairs <note midi code, oscillator object>
float curr_global_amp = 1.0; // channel volume (0.0 to 1.0)
float amp_multiplier = 1.0; // basically expression
float curr_global_bend = 0.0; // channel pitch bend (-curr_bend_range to curr_bend_range semitones)
Expand Down Expand Up @@ -33,40 +32,29 @@ public class ChannelOsc {


ChannelOsc() {
current_notes = new HashMap<Integer, RTSoundObject>();
current_notes = new HashMap<Integer, SoundObject>();
curr_holding = new ArrayList();
curr_sostenuting = new ArrayList();
}


ChannelOsc(int osc_type) {
current_notes = new HashMap<Integer, RTSoundObject>();
current_notes = new HashMap<Integer, SoundObject>();
curr_holding = new ArrayList();
curr_sostenuting = new ArrayList();
set_osc_type(osc_type);
}


void create_display(int x, int y, int id) {
ChannelDisplay d;
if (demo_ui) d = new ChannelDisplayDemo(x, y, id, this);
else d = new ChannelDisplay(x, y, id, this);
ChannelDisplay d = new ChannelDisplay(x, y, id, this);
this.disp = d;
this.id = id;
}


void redraw_playing() {
this.disp.redraw(true); // draw meters with updated values
try {
for (RTSoundObject s : current_notes.values()) {
s.tick();
}
}
catch (ConcurrentModificationException cme) {
print("cme");
return;
}
}


Expand All @@ -91,21 +79,21 @@ public class ChannelOsc {
}
stop_note(note_code);

float mod_note_code = 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(note_code, 0, 127, 0.0, 1.0);
float amp = map(velocity, 0, 127, 0.0, 1.0);

RTSoundObject s = current_notes.get(note_code);
Oscillator s = (Oscillator) current_notes.get(note_code);
if (s == null) {
s = new RTSoundObject(get_new_osc(this.osc_type));
s = get_new_osc(this.osc_type);
s.freq((freq + curr_freqDetune) * bend_freq_ratio);
current_notes.put(note_code, s);
}
s.pan(curr_global_pan);
s.amp(amp * (osc_type == 1 || osc_type == 2 ? 0.12 : 0.05) * curr_global_amp * amp_multiplier * (soft_pedal ? 0.5 : 1)); // give a volume boost to TRI and SIN
if (osc_type == 0) ((Pulse) s.osc).width(pulse_width);
if (osc_type == 0) ((Pulse) s).width(pulse_width);

if (!demo_ui) s.play();
s.play();

last_amp = amp;
last_freq = freq;
Expand All @@ -119,11 +107,11 @@ public class ChannelOsc {
int sample_code = note_code_to_percussion(note_code);
SoundFile s = (SoundFile) samples[sample_code-1];
if (s == null) return;
if (s.isPlaying()) s.stop();
if (s.isPlaying()) stop_note(note_code);

s.pan(curr_global_pan);
s.amp(amp * 0.2 * curr_global_amp * amp_multiplier * (soft_pedal ? 0.5 : 1));
if (!demo_ui) s.play();
s.amp(amp * 0.32 * curr_global_amp * amp_multiplier * (soft_pedal ? 0.5 : 1));
s.play();

last_amp = amp;
last_freq = sample_code;
Expand All @@ -132,11 +120,6 @@ public class ChannelOsc {


void stop_note(int note_code) {
stop_note(note_code, false);
}


void stop_note(int note_code, boolean force) {
/* if (hold_pedal) {
curr_holding.add(note_code);
return;
Expand All @@ -146,9 +129,9 @@ public class ChannelOsc {
} */ // really disliking how this sounds lol

if (osc_type != 4) {
RTSoundObject s = current_notes.get(note_code);
SoundObject s = current_notes.get(note_code);
if (s == null) return;
s.stop(force);
s.stop();
}

last_amp = 0.0;
Expand All @@ -173,8 +156,8 @@ public class ChannelOsc {
if (osc_type == 4) return;
sostenuto_pedal = value < 63 ? false : true;
if (sostenuto_pedal) {
for (Entry<Integer, RTSoundObject> s : this.current_notes.entrySet()) {
if (s.getValue().osc.isPlaying()) {
for (Entry<Integer, SoundObject> s : this.current_notes.entrySet()) {
if (((Oscillator) s.getValue()).isPlaying()) {
curr_sostenuting.add(s.getKey());
}
}
Expand Down Expand Up @@ -234,8 +217,8 @@ public class ChannelOsc {


void set_all_oscs_amp() {
for (RTSoundObject s : current_notes.values()) {
s.amp((osc_type == 1 || osc_type == 2 ? 0.12 : 0.05) * curr_global_amp * amp_multiplier * (soft_pedal ? 0.5 : 1) * last_amp);
for (SoundObject s : current_notes.values()) {
((Oscillator) s).amp((osc_type == 1 || osc_type == 2 ? 0.12 : 0.05) * curr_global_amp * amp_multiplier * (soft_pedal ? 0.5 : 1) * last_amp);
}
}

Expand All @@ -247,9 +230,9 @@ public class ChannelOsc {
curr_global_bend = map(value, 0, 16383, -1.0, 1.0) * curr_bend_range;
bend_freq_ratio = (float) Math.pow(2, curr_global_bend / 12.0);

for (Entry<Integer, RTSoundObject> s_pair : current_notes.entrySet()) {
for (Entry<Integer, SoundObject> s_pair : current_notes.entrySet()) {
float new_freq = midi_to_freq(s_pair.getKey() + curr_noteDetune) * bend_freq_ratio;
s_pair.getValue().freq(new_freq + curr_freqDetune);
((Oscillator) s_pair.getValue()).freq(new_freq + curr_freqDetune);
last_freq = new_freq;
}
}
Expand All @@ -258,7 +241,7 @@ public class ChannelOsc {
void set_pan(int value) {
curr_global_pan = map(value, 0, 127, -1.0, 1.0);

for (RTSoundObject s : current_notes.values()) {
for (SoundObject s : current_notes.values()) {
s.pan(curr_global_pan);
}
}
Expand All @@ -268,15 +251,14 @@ public class ChannelOsc {
if (how) shut_up();
disp.button_mute.set_pressed(how);
silenced = how;

}


void shut_up() {
set_hold(0);
set_sostenuto(0);
set_soft(0);
for (int note_code : current_notes.keySet()) stop_note(note_code, true);
for (int note_code : current_notes.keySet()) stop_note(note_code);
}


Expand Down
60 changes: 4 additions & 56 deletions LabsModule.pde
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class LabsModule extends PApplet {


public void settings() {
if (osname.contains("Windows")) this.size(210, 404);
else this.size(210, 360);
if (osname.contains("Windows")) this.size(210, 324);
else this.size(210, 280);
}


Expand Down Expand Up @@ -45,11 +45,7 @@ public class LabsModule extends PApplet {
b4.show_label = false;
Button b6 = new Button("midiIn", "midiIn");
b6.show_label = false;
Button b8 = new Button("rtEngine", "rtEngine");
b8.show_label = false;
Button b9 = new Button("demoUi", "demoUi");
b9.show_label = false;
Button[] bs = new Button[] {b1, b2, b3, b7, b4, b6, b8, b9};
Button[] bs = new Button[] {b1, b2, b3, b7, b4, b6};
all_buttons = new ButtonToolbar(8, 45, 0, 1.4, bs);

}
Expand Down Expand Up @@ -138,51 +134,6 @@ public class LabsModule extends PApplet {
if (!player.midi_in_mode) player.start_midi_in();
else player.stop_midi_in();
}

else if (all_buttons.collided("rtEngine", this)) {
player.shut_up_all();
NO_REALTIME = !NO_REALTIME;
}

else if (all_buttons.collided("demoUi", this)) {
Form form = ui.createForm("Customize demo UI")
.addText("Title")
.addTextArea("Description")
.addText("Format")
.addSelection(
"Pulse 1 width",
Arrays.asList("Unchanged", "0.125", "0.25", "0.5", "0.75")
)
.addSelection(
"Pulse 2 width",
Arrays.asList("Unchanged", "0.125", "0.25", "0.5", "0.75")
)
.addButton("Toggle demo UI", new Runnable() { public void run() {
ui.showInfoDialog("Setting will take effect on next program restart.");
config_map.put("demoable uiserver", demo_ui ? "0" : "1");
save_config();
}})
.setCloseListener(new FormCloseListener() { public void onClose(Form form) {
String t = form.getByIndex(0).asString();
String d = form.getByIndex(1).asString();
String f = form.getByIndex(2).asString();
String w1 = (String) form.getByIndex(3).getValue();
String w2 = (String) form.getByIndex(4).getValue();

if (!t.equals("")) demo_title = t;
if (!d.equals("")) demo_description = d;
if (!f.equals("")) demo_layout = f;
if (!w1.equals("Unchanged")) player.channels[0].set_osc_type(Float.parseFloat(w1));
if (!w2.equals("Unchanged")) player.channels[1].set_osc_type(Float.parseFloat(w2));
}})
.run();

form.getByIndex(0).setValue(demo_title);
form.getByIndex(1).setValue(demo_description);
form.getByIndex(2).setValue(demo_layout);

form.getWindow().setSize(240, 520);
}
}

//this.redraw_all();
Expand All @@ -195,9 +146,7 @@ public class LabsModule extends PApplet {
all_buttons.collided("tempo", this) ||
all_buttons.collided("overrideOscs", this) ||
all_buttons.collided("transform", this) ||
all_buttons.collided("midiIn", this) ||
all_buttons.collided("rtEngine", this) ||
all_buttons.collided("demoUi", this)
all_buttons.collided("midiIn", this)
) {
this.cursor(HAND);
}
Expand Down Expand Up @@ -229,7 +178,6 @@ public class LabsModule extends PApplet {
//this.text("x", 179, 177);
this.text(curr_transform, 179, 216);
this.text((player.midi_in_mode ? "On" : "Off"), 179, 255);
this.text((NO_REALTIME ? "Off" : "On"), 179, 294);

all_buttons.redraw(this);
}
Expand Down
11 changes: 7 additions & 4 deletions P3synth.pde
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PFont[] fonts;
SoundFile[] samples;
ThemeEngine t;
boolean showed_sf_tip = false;
boolean is_newbie = false;
ButtonToolbar media_buttons;
ButtonToolbar setting_buttons;
Button b_meta_msgs;
Expand Down Expand Up @@ -147,11 +148,12 @@ void load_config(boolean just_opened) {
}
catch (FileNotFoundException fnfe) {
println("load fnfe");
is_newbie = true;
ui.showInfoDialog(
"Welcome! Please check your audio levels.\n\n" +

"For help on advanced usage, check the HELP button or\n" +
"the project's website at https://vlcoo.github.io/p3synth\n"
"the project's website at https://vlcoo.net/p3synth\n"
);
save_config();
}
Expand Down Expand Up @@ -342,10 +344,11 @@ void mouseReleased() {
"Drag and drop a new MIDI file to play.\n" +
"REPLAY: skip back to the beginning of the song.\n" +
"PAUSE: pause any playing music or resume if paused.\n" +
"EXIT: safely close the program.\n\n" +
"STOP: unload the file.\n\n" +

"The Labs menu has experimental playback/tinkering options!\n" +
"The buttons on the other side provide some info and configs.\n\n" +
"The buttons on the other side provide some info and configs.\n" +
"Try loading a soundfont file by dropping it into the upper right box!\n\n" +

"Left click the X on any channel to mute it, or right click it to solo.\n" +
"You can use the lower left rectangle to control the song's position.\n" +
Expand Down Expand Up @@ -420,7 +423,7 @@ void mouseReleased() {
}

else if (player.disp.collided_sfload_rect()) {
if (!player.system_synth && player.sf_filename.equals("Default") && !showed_sf_tip) {
if (is_newbie && !showed_sf_tip && !player.system_synth && player.sf_filename.equals("Default")) {
ui.showWarningDialog(
"Bonus: drag and drop SF2/DLS file in that box to load it!\n",
"Switching modes"
Expand Down
10 changes: 7 additions & 3 deletions Player.pde
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class Player {


String play_file(String filename) {
return play_file(filename, false);
}


String play_file(String filename, boolean keep_paused) {
if (midi_in_mode) stop_midi_in();
File file = new File(filename);
if (system_synth) try_match_soundfont(filename);
Expand All @@ -174,7 +179,7 @@ class Player {
midi_resolution = mid.getResolution();
curr_filename = filename;
setTicks(0);
set_playing_state(1);
set_playing_state(keep_paused ? 0 : 1);
}
catch(InvalidMidiDataException imde) {
return "Invalid MIDI data!";
Expand Down Expand Up @@ -287,9 +292,8 @@ class Player {

if (playing_state_before >= 0) {
prep_javax_midi();
play_file(prev_filename);
play_file(prev_filename, playing_state_before == 0); // keep paused if it was
setTicks(prev_ticks);
if (playing_state_before == 0) set_playing_state(0); // keep paused if it was
}
}

Expand Down
Loading

0 comments on commit 3a1e9ad

Please sign in to comment.