From 022b1d809e743ccacbbe26baefc336c8e0928de3 Mon Sep 17 00:00:00 2001 From: Lele567 <48808663+Lele567@users.noreply.github.com> Date: Sat, 13 Nov 2021 14:26:19 -0500 Subject: [PATCH 1/4] lastframe --- src/betamindy/world/blocks/logic/NotePlayer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/betamindy/world/blocks/logic/NotePlayer.java b/src/betamindy/world/blocks/logic/NotePlayer.java index a4cf9a65..0a01764e 100644 --- a/src/betamindy/world/blocks/logic/NotePlayer.java +++ b/src/betamindy/world/blocks/logic/NotePlayer.java @@ -410,6 +410,7 @@ public void control(LAccess type, double p1, double p2, double p3, double p4){ } rem += 0.5; //forces typecast to work int pitch = whole * 12 + (int)rem; + lastFrame = 0; configure(pitch); } else if(type == LAccess.color){ @@ -431,6 +432,7 @@ else if(type == LAccess.color){ else{ if(v == volume){ //configure pitch + lastFrame = 0; configureP(p); return; } @@ -443,6 +445,7 @@ else if(p == pitch && v == volume){ } //two or more are wrong + lastFrame = 0; configure(new byte[]{(byte) inst, (byte) p, (byte) v, 1}); } else if(type == LAccess.enabled){ From 2cfa1b51e87b81fbb455b3eae087c67ed0728bf6 Mon Sep 17 00:00:00 2001 From: Lele567 <48808663+Lele567@users.noreply.github.com> Date: Sat, 13 Nov 2021 18:39:17 -0500 Subject: [PATCH 2/4] reimplementation --- .../world/blocks/logic/NotePlayer.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/betamindy/world/blocks/logic/NotePlayer.java b/src/betamindy/world/blocks/logic/NotePlayer.java index 0a01764e..30f7a180 100644 --- a/src/betamindy/world/blocks/logic/NotePlayer.java +++ b/src/betamindy/world/blocks/logic/NotePlayer.java @@ -158,6 +158,7 @@ public class NotePlayerBuild extends Building { private int octavePage = sampleOctave; //ui only private long lastFrame; + private boolean[] played = new boolean[octaves * 12]; //sets the instrument safely public void setMode(int m){ @@ -177,14 +178,23 @@ public void testNote(){ //plays a note public void playNote(){ - if(headless || lastFrame == Core.graphics.getFrameId()) return; - lastFrame = Core.graphics.getFrameId(); + if(headless) return; + if (lastFrame != Core.graphics.getFrameId()){ + lastFrame = Core.graphics.getFrameId(); + // I could init a new array instead of doing this + // meh + for (int i = 0; i < played.length; i++){ + played[i] = false; + } + } + if (played[pitch]) return; if(global){ instruments[mode].play(pitch, volume / 10f); } else{ instruments[mode].at(pitch, x, y); } + played[pitch] = true; effects(); } @@ -410,7 +420,6 @@ public void control(LAccess type, double p1, double p2, double p3, double p4){ } rem += 0.5; //forces typecast to work int pitch = whole * 12 + (int)rem; - lastFrame = 0; configure(pitch); } else if(type == LAccess.color){ @@ -432,7 +441,6 @@ else if(type == LAccess.color){ else{ if(v == volume){ //configure pitch - lastFrame = 0; configureP(p); return; } @@ -445,7 +453,6 @@ else if(p == pitch && v == volume){ } //two or more are wrong - lastFrame = 0; configure(new byte[]{(byte) inst, (byte) p, (byte) v, 1}); } else if(type == LAccess.enabled){ From 1147d982edc0900f1a5d6358ec20b7acb5183103 Mon Sep 17 00:00:00 2001 From: Lele567 <48808663+Lele567@users.noreply.github.com> Date: Mon, 15 Nov 2021 10:23:53 -0500 Subject: [PATCH 3/4] toggle --- .../world/blocks/logic/NotePlayer.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/betamindy/world/blocks/logic/NotePlayer.java b/src/betamindy/world/blocks/logic/NotePlayer.java index 30f7a180..5f1f7e3e 100644 --- a/src/betamindy/world/blocks/logic/NotePlayer.java +++ b/src/betamindy/world/blocks/logic/NotePlayer.java @@ -57,6 +57,9 @@ public class NotePlayer extends Block { public final static int[] whiteOffset = {0, 2, 4, 5, 7, 9, 11, 12, 14, 16}; public final static int[] blackOffset = {1, 3, 0, 6, 8, 10, 0, 13, 15}; + //if true, this noteblock can play multiple notes per frame, but not the same note + public boolean multiNote = false; + public NotePlayer(String name){ super(name); @@ -179,15 +182,20 @@ public void testNote(){ //plays a note public void playNote(){ if(headless) return; - if (lastFrame != Core.graphics.getFrameId()){ - lastFrame = Core.graphics.getFrameId(); - // I could init a new array instead of doing this - // meh - for (int i = 0; i < played.length; i++){ - played[i] = false; + if (multiNote){ + if (lastFrame != Core.graphics.getFrameId()){ + lastFrame = Core.graphics.getFrameId(); + for (int i = 0; i < played.length; i++){ + played[i] = false; + } } + if (played[pitch]) return; + } else { + if (lastFrame == Core.graphics.getFrameId()){ + return; + } + lastFrame = Core.graphics.getFrameId(); } - if (played[pitch]) return; if(global){ instruments[mode].play(pitch, volume / 10f); } From d2d924c1aa19f06ac5ef9fd946157b6e3404d32d Mon Sep 17 00:00:00 2001 From: Lele567 <48808663+Lele567@users.noreply.github.com> Date: Mon, 15 Nov 2021 19:47:50 -0500 Subject: [PATCH 4/4] comments --- src/betamindy/world/blocks/logic/NotePlayer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/betamindy/world/blocks/logic/NotePlayer.java b/src/betamindy/world/blocks/logic/NotePlayer.java index 5f1f7e3e..e08ed9e1 100644 --- a/src/betamindy/world/blocks/logic/NotePlayer.java +++ b/src/betamindy/world/blocks/logic/NotePlayer.java @@ -183,6 +183,7 @@ public void testNote(){ public void playNote(){ if(headless) return; if (multiNote){ + //only disable played pitches if (lastFrame != Core.graphics.getFrameId()){ lastFrame = Core.graphics.getFrameId(); for (int i = 0; i < played.length; i++){ @@ -191,6 +192,7 @@ public void playNote(){ } if (played[pitch]) return; } else { + //disable all pitches if one pitch was played if (lastFrame == Core.graphics.getFrameId()){ return; }