| 1 | package com.github.dakusui.symfonion.song; | |
| 2 | ||
| 3 | import com.github.dakusui.symfonion.compat.exceptions.SymfonionException; | |
| 4 | import com.github.dakusui.symfonion.compat.json.CompatJsonUtils; | |
| 5 | import com.google.gson.JsonObject; | |
| 6 | ||
| 7 | import java.util.HashMap; | |
| 8 | import java.util.Iterator; | |
| 9 | import java.util.Map; | |
| 10 | ||
| 11 | import static com.github.dakusui.symfonion.compat.exceptions.CompatExceptionThrower.noteNotDefinedException; | |
| 12 | ||
| 13 | ||
| 14 | /** | |
| 15 | * An object which stores mappings from characters to MIDI note numbers defined in the `SyMFONION` language. | |
| 16 | */ | |
| 17 | public class NoteMap { | |
| 18 | public static final NoteMap defaultNoteMap = new NoteMap(Keyword.normal.name()); | |
| 19 | public static final NoteMap defaultPercussionMap = new NoteMap(Keyword.percussion.name()); | |
| 20 | protected Map<String, Integer> map = new HashMap<>(); | |
| 21 | private String name; | |
| 22 | ||
| 23 | static { | |
| 24 | defaultNoteMap.map.put("C", 60); | |
| 25 | defaultNoteMap.map.put("D", 62); | |
| 26 | defaultNoteMap.map.put("E", 64); | |
| 27 | defaultNoteMap.map.put("F", 65); | |
| 28 | defaultNoteMap.map.put("G", 67); | |
| 29 | defaultNoteMap.map.put("A", 69); | |
| 30 | defaultNoteMap.map.put("B", 71); | |
| 31 | defaultPercussionMap.map.put("B", 36); | |
| 32 | defaultPercussionMap.map.put("S", 38); | |
| 33 | defaultPercussionMap.map.put("C", 49); | |
| 34 | defaultPercussionMap.map.put("O", 46); | |
| 35 | defaultPercussionMap.map.put("H", 42); | |
| 36 | defaultPercussionMap.map.put("T", 47); | |
| 37 | } | |
| 38 | ||
| 39 | public NoteMap(String name) { | |
| 40 | this.name = name; | |
| 41 | } | |
| 42 | ||
| 43 | public NoteMap(final JsonObject json) { | |
| 44 | Iterator<String> i = CompatJsonUtils.keyIterator(json); | |
| 45 |
1
1. <init> : negated conditional → NO_COVERAGE |
while (i.hasNext()) { |
| 46 | String cur = i.next(); | |
| 47 | int v = json.get(cur).getAsInt(); | |
| 48 | this.map.put(cur, v); | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | public int noteFor(String noteName) throws SymfonionException { | |
| 53 |
1
1. noteFor : negated conditional → KILLED |
if ("r".equals(noteName)) { |
| 54 |
1
1. noteFor : replaced int return with 0 for com/github/dakusui/symfonion/song/NoteMap::noteFor → SURVIVED |
return -1; |
| 55 | } | |
| 56 |
1
1. noteFor : negated conditional → KILLED |
if (!this.map.containsKey(noteName)) { |
| 57 | throw noteNotDefinedException(noteName, this.name); | |
| 58 | } | |
| 59 |
1
1. noteFor : replaced int return with 0 for com/github/dakusui/symfonion/song/NoteMap::noteFor → KILLED |
return this.map.get(noteName); |
| 60 | } | |
| 61 | ||
| 62 | public String name() { | |
| 63 |
1
1. name : replaced return value with "" for com/github/dakusui/symfonion/song/NoteMap::name → NO_COVERAGE |
return this.name; |
| 64 | } | |
| 65 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 56 |
1.1 |
|
| 59 |
1.1 |
|
| 63 |
1.1 |