| 1 | package com.github.dakusui.symfonion.song; | |
| 2 | ||
| 3 | import com.github.dakusui.json.JsonException; | |
| 4 | import com.github.dakusui.json.JsonUtils; | |
| 5 | import com.github.dakusui.symfonion.exceptions.SymfonionException; | |
| 6 | import com.github.dakusui.symfonion.utils.Fraction; | |
| 7 | import com.github.dakusui.symfonion.utils.Utils; | |
| 8 | import com.google.gson.JsonArray; | |
| 9 | import com.google.gson.JsonElement; | |
| 10 | import com.google.gson.JsonObject; | |
| 11 | ||
| 12 | import java.util.Collections; | |
| 13 | import java.util.LinkedList; | |
| 14 | import java.util.List; | |
| 15 | import java.util.Map; | |
| 16 | ||
| 17 | import static com.github.dakusui.json.JsonUtils.asJsonElement; | |
| 18 | import static com.github.dakusui.symfonion.exceptions.ExceptionThrower.illegalFormatException; | |
| 19 | import static com.github.dakusui.symfonion.exceptions.ExceptionThrower.noteMapNotFoundException; | |
| 20 | import static com.github.dakusui.symfonion.exceptions.SymfonionIllegalFormatException.NOTE_LENGTH_EXAMPLE; | |
| 21 | ||
| 22 | ||
| 23 | public class Pattern { | |
| 24 | public static class Parameters { | |
| 25 | static final Fraction QUARTER = new Fraction(1, 4); | |
| 26 | double gate = 0.8; | |
| 27 | Fraction length = QUARTER; | |
| 28 | int transpose = 0; | |
| 29 | int velocityBase = 64; | |
| 30 | int velocityDelta = 10; | |
| 31 | int arpeggio; | |
| 32 | | |
| 33 | public Parameters(JsonObject json) throws SymfonionException, JsonException { | |
| 34 |
1
1. <init> : removed call to com/github/dakusui/symfonion/song/Pattern$Parameters::init → KILLED |
init(json); |
| 35 | } | |
| 36 | | |
| 37 | public double gate() { | |
| 38 |
1
1. gate : replaced double return with 0.0d for com/github/dakusui/symfonion/song/Pattern$Parameters::gate → KILLED |
return this.gate; |
| 39 | } | |
| 40 | | |
| 41 | private void init(JsonObject json) throws SymfonionException, JsonException { | |
| 42 |
1
1. init : negated conditional → KILLED |
if (json == null) { |
| 43 | json = JsonUtils.toJson("{}").getAsJsonObject(); | |
| 44 | } | |
| 45 | this.velocityBase = JsonUtils.asIntWithDefault(json, 64, Keyword.$velocitybase); | |
| 46 | this.velocityDelta = JsonUtils.asIntWithDefault(json, 5, Keyword.$velocitydelta); | |
| 47 | this.gate = JsonUtils.asDoubleWithDefault(json, 0.8, Keyword.$gate); | |
| 48 | this.length = Utils.parseNoteLength(JsonUtils.asStringWithDefault(json, "4", Keyword.$length)); | |
| 49 |
1
1. init : negated conditional → KILLED |
if (this.length == null) { |
| 50 | throw illegalFormatException( | |
| 51 | asJsonElement(json, Keyword.$length), | |
| 52 | NOTE_LENGTH_EXAMPLE | |
| 53 | ); | |
| 54 | } | |
| 55 | this.transpose = JsonUtils.asIntWithDefault(json, 0, Keyword.$transpose); | |
| 56 | this.arpeggio = JsonUtils.asIntWithDefault(json, 0, Keyword.$arpeggio); | |
| 57 | } | |
| 58 | | |
| 59 | public Fraction length() { | |
| 60 |
1
1. length : replaced return value with null for com/github/dakusui/symfonion/song/Pattern$Parameters::length → KILLED |
return this.length; |
| 61 | } | |
| 62 | | |
| 63 | public int transpose() { | |
| 64 |
1
1. transpose : replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::transpose → SURVIVED |
return this.transpose; |
| 65 | } | |
| 66 | | |
| 67 | public int velocitybase() { | |
| 68 |
1
1. velocitybase : replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::velocitybase → SURVIVED |
return this.velocityBase; |
| 69 | } | |
| 70 | | |
| 71 | public int velocitydelta() { | |
| 72 |
1
1. velocitydelta : replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::velocitydelta → SURVIVED |
return this.velocityDelta; |
| 73 | } | |
| 74 | | |
| 75 | public int arpegio() { | |
| 76 |
1
1. arpegio : replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::arpegio → SURVIVED |
return this.arpeggio; |
| 77 | } | |
| 78 | } | |
| 79 | | |
| 80 | public static Pattern createPattern(JsonObject json, Map<String, NoteMap> noteMaps) throws SymfonionException, JsonException { | |
| 81 | NoteMap noteMap = NoteMap.defaultNoteMap; | |
| 82 |
1
1. createPattern : negated conditional → KILLED |
if (JsonUtils.hasPath(json, Keyword.$notemap)) { |
| 83 | String noteMapName = JsonUtils.asString(json, Keyword.$notemap); | |
| 84 | noteMap = noteMaps.get(noteMapName); | |
| 85 |
1
1. createPattern : negated conditional → KILLED |
if (noteMap == null) { |
| 86 | throw noteMapNotFoundException(asJsonElement(json, Keyword.$notemap), noteMapName); | |
| 87 | } | |
| 88 | } | |
| 89 | Pattern ret = new Pattern(noteMap); | |
| 90 |
1
1. createPattern : removed call to com/github/dakusui/symfonion/song/Pattern::init → KILLED |
ret.init(json); |
| 91 |
1
1. createPattern : replaced return value with null for com/github/dakusui/symfonion/song/Pattern::createPattern → KILLED |
return ret; |
| 92 | } | |
| 93 | | |
| 94 | List<Stroke> body = null; | |
| 95 | NoteMap noteMap; | |
| 96 | Parameters params = null; | |
| 97 | | |
| 98 | Pattern(NoteMap noteMap) { | |
| 99 | this.noteMap = noteMap; | |
| 100 | } | |
| 101 | | |
| 102 | protected void init(JsonObject json) throws SymfonionException, JsonException { | |
| 103 | // Initialize 'body'. | |
| 104 | this.body = new LinkedList<>(); | |
| 105 | this.params = new Parameters(json); | |
| 106 | JsonArray bodyJSON; | |
| 107 |
1
1. init : negated conditional → KILLED |
if (asJsonElement(json, Keyword.$body).isJsonPrimitive()) { |
| 108 | bodyJSON = new JsonArray(); | |
| 109 |
1
1. init : removed call to com/google/gson/JsonArray::add → KILLED |
bodyJSON.add(asJsonElement(json, Keyword.$body)); |
| 110 | } else { | |
| 111 | bodyJSON = JsonUtils.asJsonArray(json, Keyword.$body); | |
| 112 | } | |
| 113 | int len = bodyJSON.size(); | |
| 114 |
2
1. init : negated conditional → KILLED 2. init : changed conditional boundary → KILLED |
for (int i = 0; i < len; i++) { |
| 115 | JsonElement cur = bodyJSON.get(i); | |
| 116 | Stroke stroke = new Stroke(cur, params, this.noteMap); | |
| 117 | body.add(stroke); | |
| 118 | } | |
| 119 | } | |
| 120 | | |
| 121 | public List<Stroke> strokes() { | |
| 122 |
1
1. strokes : replaced return value with Collections.emptyList for com/github/dakusui/symfonion/song/Pattern::strokes → KILLED |
return Collections.unmodifiableList(this.body); |
| 123 | } | |
| 124 | | |
| 125 | public Parameters parameters() { | |
| 126 |
1
1. parameters : replaced return value with null for com/github/dakusui/symfonion/song/Pattern::parameters → KILLED |
return this.params; |
| 127 | } | |
| 128 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 38 |
1.1 |
|
| 42 |
1.1 |
|
| 49 |
1.1 |
|
| 60 |
1.1 |
|
| 64 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |
|
| 76 |
1.1 |
|
| 82 |
1.1 |
|
| 85 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 |
|
| 107 |
1.1 |
|
| 109 |
1.1 |
|
| 114 |
1.1 2.2 |
|
| 122 |
1.1 |
|
| 126 |
1.1 |