Pattern.java

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
Location : <init>
Killed by : com.github.dakusui.symfonion.tests.InvalidDataErrorTest.illegalNoteLength_02(com.github.dakusui.symfonion.tests.InvalidDataErrorTest)
removed call to com/github/dakusui/symfonion/song/Pattern$Parameters::init → KILLED

38

1.1
Location : gate
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.exercise[6: POSITIVE: given: 'sixteen notes are given in two string elements' when: 'compile' then: 'number of events and tick length seem ok'](com.github.dakusui.symfonion.tests.MidiCompilerTest)
replaced double return with 0.0d for com/github/dakusui/symfonion/song/Pattern$Parameters::gate → KILLED

42

1.1
Location : init
Killed by : com.github.dakusui.symfonion.tests.InvalidDataErrorTest.illegalNoteLength_02(com.github.dakusui.symfonion.tests.InvalidDataErrorTest)
negated conditional → KILLED

49

1.1
Location : init
Killed by : com.github.dakusui.symfonion.tests.InvalidDataErrorTest.illegalNoteLength_02(com.github.dakusui.symfonion.tests.InvalidDataErrorTest)
negated conditional → KILLED

60

1.1
Location : length
Killed by : com.github.dakusui.symfonion.tests.ReferenceErrorTest.missingNote(com.github.dakusui.symfonion.tests.ReferenceErrorTest)
replaced return value with null for com/github/dakusui/symfonion/song/Pattern$Parameters::length → KILLED

64

1.1
Location : transpose
Killed by : none
replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::transpose → SURVIVED

68

1.1
Location : velocitybase
Killed by : none
replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::velocitybase → SURVIVED

72

1.1
Location : velocitydelta
Killed by : none
replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::velocitydelta → SURVIVED

76

1.1
Location : arpegio
Killed by : none
replaced int return with 0 for com/github/dakusui/symfonion/song/Pattern$Parameters::arpegio → SURVIVED

82

1.1
Location : createPattern
Killed by : com.github.dakusui.symfonion.tests.ReferenceErrorTest.missingNoteMap(com.github.dakusui.symfonion.tests.ReferenceErrorTest)
negated conditional → KILLED

85

1.1
Location : createPattern
Killed by : com.github.dakusui.symfonion.tests.ReferenceErrorTest.missingNoteMap(com.github.dakusui.symfonion.tests.ReferenceErrorTest)
negated conditional → KILLED

90

1.1
Location : createPattern
Killed by : com.github.dakusui.symfonion.tests.InvalidDataErrorTest.illegalNoteLength_02(com.github.dakusui.symfonion.tests.InvalidDataErrorTest)
removed call to com/github/dakusui/symfonion/song/Pattern::init → KILLED

91

1.1
Location : createPattern
Killed by : com.github.dakusui.symfonion.tests.InvalidJsonErrorTest.missingSection_parts(com.github.dakusui.symfonion.tests.InvalidJsonErrorTest)
replaced return value with null for com/github/dakusui/symfonion/song/Pattern::createPattern → KILLED

107

1.1
Location : init
Killed by : com.github.dakusui.symfonion.tests.ReferenceErrorTest.missingNote(com.github.dakusui.symfonion.tests.ReferenceErrorTest)
negated conditional → KILLED

109

1.1
Location : init
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.exercise[5: POSITIVE: given: 'sixteen notes are given in a single string element' when: 'compile' then: 'number of events and tick length seem ok'](com.github.dakusui.symfonion.tests.MidiCompilerTest)
removed call to com/google/gson/JsonArray::add → KILLED

114

1.1
Location : init
Killed by : com.github.dakusui.symfonion.tests.ReferenceErrorTest.missingNote(com.github.dakusui.symfonion.tests.ReferenceErrorTest)
negated conditional → KILLED

2.2
Location : init
Killed by : com.github.dakusui.symfonion.tests.InvalidJsonErrorTest.missingSection_sequence(com.github.dakusui.symfonion.tests.InvalidJsonErrorTest)
changed conditional boundary → KILLED

122

1.1
Location : strokes
Killed by : com.github.dakusui.symfonion.tests.MidiCompilerTest.exercise[7: POSITIVE: given: 'sixteenth note with short gate (0.25)' when: 'compile' then: 'number of events and tick length seem ok'](com.github.dakusui.symfonion.tests.MidiCompilerTest)
replaced return value with Collections.emptyList for com/github/dakusui/symfonion/song/Pattern::strokes → KILLED

126

1.1
Location : parameters
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.CompileTest.test(com.github.dakusui.symfonion.tests.cli.subcommands.CompileTest)
replaced return value with null for com/github/dakusui/symfonion/song/Pattern::parameters → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.3