Skip to content

Commit

Permalink
Make builtin piano rolls more extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Apr 1, 2022
1 parent 598a8ab commit d303c38
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public static int getDuration(ItemStack stack) {
@Override
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks) {
if (group == this.getGroup() || group == ItemGroup.SEARCH) {
var chopsticks = this.create(BuiltinPianoRolls.CHOPSTICKS);
chopsticks.setCustomName(new TranslatableText(getTranslationKey() + ".chopsticks").styled(style -> style.withItalic(false)));
stacks.add(chopsticks);
BuiltinPianoRolls.forEach((name, roll) -> {
var stack = this.create(roll);
stack.setCustomName(new TranslatableText(getTranslationKey() + "." + name).styled(style -> style.withItalic(false)));
stacks.add(stack);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@

import io.github.foundationgames.phonos.util.PhonosUtil;

import java.sql.Date;
import java.time.Instant;
import java.time.Month;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

public final class BuiltinPianoRolls {
private static final Map<String, PianoRoll> REGISTRY = new HashMap<>();

private BuiltinPianoRolls() {}

public static final PianoRoll CHOPSTICKS;
public static final PianoRoll CHOPSTICKS = register("chopsticks", chopsticks());
private static final int CHOPSTICKS_SPEED = 5;

private static void chopsticksCommonSection(List<PianoRoll.Stage> stages) {
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(11), // F4
PhonosUtil.pitchFromNote(13) // G4
}, 5));
}
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(10), // E4
PhonosUtil.pitchFromNote(13) // G4
}, 5));
}
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(8), // D4
PhonosUtil.pitchFromNote(17) // B5
}, 5));
}
public static PianoRoll register(String name, PianoRoll roll) {
REGISTRY.put(name, roll);

return roll;
}

static {
public static void forEach(BiConsumer<String, PianoRoll> action) {
REGISTRY.forEach(action);
}

private static PianoRoll chopsticks() {
var stages = new ArrayList<PianoRoll.Stage>();

chopsticksCommonSection(stages);
Expand All @@ -40,33 +39,93 @@ private static void chopsticksCommonSection(List<PianoRoll.Stage> stages) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), // C4
PhonosUtil.pitchFromNote(18) // C5
}, 5));
}, CHOPSTICKS_SPEED));
}
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(8), // D4
PhonosUtil.pitchFromNote(17) // B5
}, 5));
}, CHOPSTICKS_SPEED));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(10), // E4
PhonosUtil.pitchFromNote(15) // A4
}, 5));
}, CHOPSTICKS_SPEED));

chopsticksCommonSection(stages);

stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), // C4
PhonosUtil.pitchFromNote(18) // C5
}, 5));
}, CHOPSTICKS_SPEED));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(13), // G4
}, 5));
}, CHOPSTICKS_SPEED));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(10), // E4
}, 5));
}, CHOPSTICKS_SPEED));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), // C4
}, 5));
}, CHOPSTICKS_SPEED));

CHOPSTICKS = new PianoRoll(stages);
int halfSpeed = CHOPSTICKS_SPEED / 2;
if (Calendar.getInstance().get(Calendar.MONTH) == 3 && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == 1) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(1),
}, halfSpeed));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(3),
}, halfSpeed));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6),
}, halfSpeed));
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(3),
}, halfSpeed));
for (int i = 0; i < 3; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), PhonosUtil.pitchFromNote(10)
}, CHOPSTICKS_SPEED));
}
for (int i = 0; i < 3; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(5), PhonosUtil.pitchFromNote(13)
}, CHOPSTICKS_SPEED));
}
for (int i = 0; i < 3; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(8), PhonosUtil.pitchFromNote(13)
}, CHOPSTICKS_SPEED));
}
for (int i = 0; i < 3; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), PhonosUtil.pitchFromNote(13)
}, CHOPSTICKS_SPEED));
}
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(6), PhonosUtil.pitchFromNote(10), PhonosUtil.pitchFromNote(15)
}, CHOPSTICKS_SPEED));
}

return new PianoRoll(stages);
}

private static void chopsticksCommonSection(List<PianoRoll.Stage> stages) {
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(11), // F4
PhonosUtil.pitchFromNote(13) // G4
}, CHOPSTICKS_SPEED));
}
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(10), // E4
PhonosUtil.pitchFromNote(13) // G4
}, CHOPSTICKS_SPEED));
}
for (int i = 0; i < 6; i++) {
stages.add(new PianoRoll.Stage(new float[] {
PhonosUtil.pitchFromNote(8), // D4
PhonosUtil.pitchFromNote(17) // B5
}, CHOPSTICKS_SPEED));
}
}
}

0 comments on commit d303c38

Please sign in to comment.