MidiDeviceManager.java

1
package com.github.dakusui.symfonion.utils.midi;
2
3
import com.github.dakusui.symfonion.compat.exceptions.CompatExceptionThrower;
4
import com.github.dakusui.symfonion.compat.exceptions.ExceptionContext;
5
import com.github.valid8j.pcond.forms.Printables;
6
7
import javax.sound.midi.MidiDevice;
8
import javax.sound.midi.MidiSystem;
9
import javax.sound.midi.MidiUnavailableException;
10
import java.util.*;
11
import java.util.function.Predicate;
12
import java.util.regex.Pattern;
13
import java.util.stream.Stream;
14
15
import static com.github.dakusui.symfonion.compat.exceptions.CompatExceptionThrower.*;
16
import static com.github.dakusui.symfonion.compat.exceptions.CompatExceptionThrower.ContextKey.MIDI_DEVICE_INFO;
17
import static com.github.dakusui.symfonion.compat.exceptions.CompatExceptionThrower.ContextKey.MIDI_DEVICE_INFO_IO;
18
import static com.github.dakusui.symfonion.compat.exceptions.ExceptionContext.entry;
19
import static com.github.dakusui.symfonion.utils.Utils.onlyElement;
20
21
public class MidiDeviceManager {
22
23
24
  final List<MidiDeviceRecord> records;
25
  final MidiDeviceReportFormatter reportFormatter;
26
27
28
  public MidiDeviceManager(MidiDeviceReportFormatter formatter) {
29
    this.reportFormatter = formatter;
30
    this.records = new LinkedList<>();
31
  }
32
33
  public MidiDeviceRecord lookUp(Predicate<MidiDeviceRecord> whereClause) {
34 1 1. lookUp : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUp → KILLED
    return this.find(whereClause)
35 1 1. lambda$lookUp$0 : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$lookUp$0 → NO_COVERAGE
        .collect(onlyElement((e1, e2) -> multipleMidiDevices(e1, e2, whereClause)))
36 1 1. lambda$lookUp$1 : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$lookUp$1 → NO_COVERAGE
        .orElseThrow(() -> noSuchMidiDeviceWasFound(whereClause));
37
  }
38
39
40
  public static MidiDeviceManager from(MidiDeviceReportFormatter reportFormatter) {
41 1 1. from : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED
    return from(reportFormatter, MidiUtils.streamMidiDeviceInfo());
42
  }
43
44
  public static MidiDeviceManager from(MidiDeviceReportFormatter reportFormatter, Stream<MidiDevice.Info> midiDeviceInfoStream) {
45
    MidiDeviceManager reportComposer = new MidiDeviceManager(reportFormatter);
46 1 1. from : removed call to java/util/stream/Stream::forEach → KILLED
    midiDeviceInfoStream.forEach(reportComposer::add);
47 1 1. from : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED
    return reportComposer;
48
  }
49
50
  public static Predicate<MidiDeviceRecord> matchesPortNameInDefinitions(String inPortName, Map<String, Pattern> midiInDefinitions) {
51 1 1. matchesPortNameInDefinitions : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::matchesPortNameInDefinitions → KILLED
    return midiDeviceInfoMatches(midiInDefinitions.get(inPortName));
52
  }
53
54
  private static Predicate<MidiDeviceRecord> midiDeviceInfoMatches(Pattern regexForDeviceName) {
55 3 1. midiDeviceInfoMatches : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::midiDeviceInfoMatches → KILLED
2. lambda$midiDeviceInfoMatches$2 : replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$midiDeviceInfoMatches$2 → KILLED
3. lambda$midiDeviceInfoMatches$2 : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$midiDeviceInfoMatches$2 → KILLED
    return printablePredicate(".info.name.matches[" + regexForDeviceName + "]", r -> regexForDeviceName.matcher(r.info().getName()).matches());
56
  }
57
58
  public static Predicate<MidiDeviceRecord> isMidiDeviceForInput() {
59 3 1. lambda$isMidiDeviceForInput$3 : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForInput$3 → SURVIVED
2. isMidiDeviceForInput : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::isMidiDeviceForInput → KILLED
3. lambda$isMidiDeviceForInput$3 : replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForInput$3 → KILLED
    return printablePredicate("isMidiDeviceForInput", r -> MidiUtils.isMidiDeviceForInput(r.info()));
60
  }
61
62
  public static Predicate<MidiDeviceRecord> isMidiDeviceForOutput() {
63 3 1. lambda$isMidiDeviceForOutput$4 : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForOutput$4 → SURVIVED
2. isMidiDeviceForOutput : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::isMidiDeviceForOutput → KILLED
3. lambda$isMidiDeviceForOutput$4 : replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForOutput$4 → KILLED
    return printablePredicate("isMidiDeviceForOutput", r -> MidiUtils.isMidiDeviceForOutput(r.info()));
64
  }
65
66
  private static <T> Predicate<T> printablePredicate(String name, Predicate<T> p) {
67 1 1. printablePredicate : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::printablePredicate → KILLED
    return Printables.predicate(name, p);
68
  }
69
70
  public static MidiDeviceRecord lookUpMidiDevice(Predicate<MidiDeviceRecord> whereClause, MidiDeviceManager midiDeviceManager) {
71 1 1. lookUpMidiDevice : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUpMidiDevice → KILLED
    return midiDeviceManager.lookUp(whereClause);
72
  }
73
74
  public MidiDeviceManager add(MidiDevice.Info info) {
75 1 1. add : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::add → SURVIVED
    return this.add(MidiDeviceRecord.fromMidiDeviceInfo(info));
76
  }
77
78
  public MidiDeviceManager add(MidiDeviceRecord record) {
79
    this.records.add(record);
80 1 1. add : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::add → SURVIVED
    return this;
81
  }
82
83
84
  public Stream<MidiDeviceRecord> find(Predicate<MidiDeviceRecord> cond) {
85 1 1. find : replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::find → KILLED
    return streamRecords().filter(cond);
86
  }
87
88
  private Stream<MidiDeviceRecord> streamRecords() {
89 1 1. streamRecords : replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::streamRecords → KILLED
    return this.records.stream();
90
  }
91
92
  public MidiDevice openMidiDevice(MidiDeviceRecord deviceRecord) {
93
    Object value = deviceRecord.io();
94
    try (ExceptionContext ignored = exceptionContext(entry(MIDI_DEVICE_INFO, deviceRecord.info()), entry(MIDI_DEVICE_INFO_IO, value))) {
95 1 1. openMidiDevice : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::openMidiDevice → KILLED
      return openMidiDevice(deviceRecord.info());
96
    }
97
  }
98
99
  public MidiDevice openMidiDevice(MidiDevice.Info info) {
100
    try {
101
      MidiDevice ret = MidiSystem.getMidiDevice(info);
102 1 1. openMidiDevice : removed call to javax/sound/midi/MidiDevice::open → SURVIVED
      ret.open();
103 1 1. openMidiDevice : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::openMidiDevice → KILLED
      return ret;
104
    } catch (MidiUnavailableException e) {
105
      throw CompatExceptionThrower.failedToOpenMidiDevice(e);
106
    }
107
  }
108
109
  public List<String> composeReport(Predicate<MidiDeviceRecord> cond, final MidiDeviceReportFormatter reportFormatter, final String title) {
110
    MidiDevice.Info dummyInfoForHeader = new MidiDevice.Info("name", "vendor", "description", "version") {
111
    };
112 1 1. composeReport : replaced return value with Collections.emptyList for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::composeReport → SURVIVED
    return new ArrayList<>() {
113
      {
114
        this.addAll(reportFormatter.header(dummyInfoForHeader, title)
115
            .stream()
116 1 1. lambda$new$0 : replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$0 → SURVIVED
            .map(s -> reportFormatter.formatResult(false, s))
117
            .toList());
118
        this.addAll(MidiDeviceManager.this.records
119
            .stream()
120 1 1. lambda$new$1 : replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$1 → SURVIVED
            .map(r -> reportFormatter.formatResult(cond.test(r), reportFormatter.formatRecord(r)))
121
            .toList());
122 1 1. lambda$new$2 : replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$2 → NO_COVERAGE
        this.addAll(reportFormatter.footer().stream().map(s -> reportFormatter.formatResult(false, s)).toList());
123
      }
124
    };
125
  }
126
}

Mutations

34

1.1
Location : lookUp
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUp → KILLED

35

1.1
Location : lambda$lookUp$0
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$lookUp$0 → NO_COVERAGE

36

1.1
Location : lambda$lookUp$1
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$lookUp$1 → NO_COVERAGE

41

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest]/[method:whenListDevices_thenLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED

46

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
removed call to java/util/stream/Stream::forEach → KILLED

47

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest]/[method:whenListDevices_thenLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED

51

1.1
Location : matchesPortNameInDefinitions
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::matchesPortNameInDefinitions → KILLED

55

1.1
Location : midiDeviceInfoMatches
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::midiDeviceInfoMatches → KILLED

2.2
Location : lambda$midiDeviceInfoMatches$2
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$midiDeviceInfoMatches$2 → KILLED

3.3
Location : lambda$midiDeviceInfoMatches$2
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$midiDeviceInfoMatches$2 → KILLED

59

1.1
Location : isMidiDeviceForInput
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::isMidiDeviceForInput → KILLED

2.2
Location : lambda$isMidiDeviceForInput$3
Killed by : none
replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForInput$3 → SURVIVED
Covering tests

3.3
Location : lambda$isMidiDeviceForInput$3
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForInput$3 → KILLED

63

1.1
Location : lambda$isMidiDeviceForOutput$4
Killed by : none
replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForOutput$4 → SURVIVED
Covering tests

2.2
Location : isMidiDeviceForOutput
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::isMidiDeviceForOutput → KILLED

3.3
Location : lambda$isMidiDeviceForOutput$4
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForOutput$4 → KILLED

67

1.1
Location : printablePredicate
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::printablePredicate → KILLED

71

1.1
Location : lookUpMidiDevice
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUpMidiDevice → KILLED

75

1.1
Location : add
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::add → SURVIVED
Covering tests

80

1.1
Location : add
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::add → SURVIVED
Covering tests

85

1.1
Location : find
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::find → KILLED

89

1.1
Location : streamRecords
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::streamRecords → KILLED

95

1.1
Location : openMidiDevice
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::openMidiDevice → KILLED

102

1.1
Location : openMidiDevice
Killed by : none
removed call to javax/sound/midi/MidiDevice::open → SURVIVED
Covering tests

103

1.1
Location : openMidiDevice
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.[engine:junit-jupiter]/[class:com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest]/[method:whenPatchBay_thenOutputLooksOk()]
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::openMidiDevice → KILLED

112

1.1
Location : composeReport
Killed by : none
replaced return value with Collections.emptyList for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::composeReport → SURVIVED
Covering tests

116

1.1
Location : lambda$new$0
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$0 → SURVIVED
Covering tests

120

1.1
Location : lambda$new$1
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$1 → SURVIVED
Covering tests

122

1.1
Location : lambda$new$2
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager$2::lambda$new$2 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1