MidiDeviceManager.java

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

Mutations

33

1.1
Location : lookUp
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUp → KILLED

34

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

35

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

40

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest.whenListDevices_thenLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED

45

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
removed call to java/util/stream/Stream::forEach → KILLED

46

1.1
Location : from
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest.whenListDevices_thenLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.ListDevicesTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::from → KILLED

50

1.1
Location : matchesPortNameInDefinitions
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::matchesPortNameInDefinitions → KILLED

54

1.1
Location : midiDeviceInfoMatches
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
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.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
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.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$midiDeviceInfoMatches$2 → KILLED

58

1.1
Location : isMidiDeviceForInput
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
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

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

62

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

2.2
Location : isMidiDeviceForOutput
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
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.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced boolean return with false for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lambda$isMidiDeviceForOutput$4 → KILLED

66

1.1
Location : printablePredicate
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::printablePredicate → KILLED

70

1.1
Location : lookUpMidiDevice
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::lookUpMidiDevice → KILLED

74

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

79

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

84

1.1
Location : find
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::find → KILLED

88

1.1
Location : streamRecords
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::streamRecords → KILLED

100

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

101

1.1
Location : openMidiDevice
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest.whenPatchBay_thenOutputLooksOk(com.github.dakusui.symfonion.tests.cli.subcommands.PatchBayTest)
replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiDeviceManager::openMidiDevice → KILLED

110

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

114

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

118

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

120

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.15.3