/
Belyash5
/
Flu
Обзор
Документация
Войти
/
Belyash5
/
Flu
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/hbm/util/NoteBuilder.java
74 строки
1 KB
Bob
return of the radio
13 дек 2022, 00:39
13 дек 2022, 00:39
2ff7052
Код
Авторство
О чём код?
package com.hbm.util; import com.hbm.util.Tuple.Triplet; public class NoteBuilder { private String beat = ""; public static NoteBuilder start() { return new NoteBuilder(); } public NoteBuilder add(Instrument instrument, Note note, Octave octave) { if(!beat.isEmpty()) beat += "-"; String result = instrument.ordinal() + ":" + note.ordinal() + ":" + octave.ordinal(); beat += result; return this; } public String end() { return beat; } public static Triplet<Instrument, Note, Octave>[] translate(String beat) { String[] hits = beat.split("-"); Triplet<Instrument, Note, Octave>[] notes = new Triplet[hits.length]; try { for(int i = 0; i < hits.length; i++) { String[] components = hits[i].split(":"); Instrument instrument = Instrument.values()[Integer.parseInt(components[0])]; Note note = Note.values()[Integer.parseInt(components[1])]; Octave octave = Octave.values()[Integer.parseInt(components[2])]; notes[i] = new Triplet(instrument, note, octave); } return notes; } catch(Exception ex) { return new Triplet[0]; } } public static enum Instrument { PIANO, BASSDRUM, SNARE, CLICKS, BASSGUITAR; } public static enum Note { F_SHARP, G, G_SHARP, A, A_SHARP, B, C, C_SHARP, D, D_SHARP, E, F; } public static enum Octave { LOW, MID, HIGH; } }