| 1 | package com.github.dakusui.symfonion.utils.midi; | |
| 2 | ||
| 3 | import com.github.dakusui.symfonion.exceptions.CliException; | |
| 4 | ||
| 5 | import javax.sound.midi.MidiDevice; | |
| 6 | import javax.sound.midi.MidiSystem; | |
| 7 | import java.io.PrintStream; | |
| 8 | import java.util.Arrays; | |
| 9 | import java.util.regex.Pattern; | |
| 10 | import java.util.stream.Stream; | |
| 11 | ||
| 12 | import static java.lang.String.format; | |
| 13 | ||
| 14 | public enum MidiUtils { | |
| 15 | ; | |
| 16 | ||
| 17 | public static Stream<MidiDevice.Info> streamMidiDeviceInfo() { | |
| 18 |
1
1. streamMidiDeviceInfo : replaced return value with Stream.empty for com/github/dakusui/symfonion/utils/midi/MidiUtils::streamMidiDeviceInfo → KILLED |
return Arrays.stream(MidiSystem.getMidiDeviceInfo()); |
| 19 | } | |
| 20 | ||
| 21 | public static String formatMidiDeviceInfo(MidiDevice.Info info) { | |
| 22 |
1
1. formatMidiDeviceInfo : replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiUtils::formatMidiDeviceInfo → SURVIVED |
return String.format("%-25s %-15s %-35s", info.getName(), info.getVersion(), info.getVendor()); |
| 23 | } | |
| 24 | ||
| 25 | public static boolean isMidiDeviceForInput(MidiDevice.Info device) { | |
| 26 | Object tmp = null; | |
| 27 | try { | |
| 28 | MidiDevice dev = MidiSystem.getMidiDevice(device); | |
| 29 | try (dev) { | |
| 30 |
1
1. isMidiDeviceForInput : removed call to javax/sound/midi/MidiDevice::open → SURVIVED |
dev.open(); |
| 31 | tmp = dev.getTransmitter(); | |
| 32 | } | |
| 33 | } catch (Exception ignored) { | |
| 34 | } | |
| 35 |
2
1. isMidiDeviceForInput : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiUtils::isMidiDeviceForInput → SURVIVED 2. isMidiDeviceForInput : negated conditional → KILLED |
return tmp != null; |
| 36 | } | |
| 37 | ||
| 38 | public static boolean isMidiDeviceForOutput(MidiDevice.Info info) { | |
| 39 | Object tmp = null; | |
| 40 | try { | |
| 41 | MidiDevice dev = MidiSystem.getMidiDevice(info); | |
| 42 | try (dev) { | |
| 43 |
1
1. isMidiDeviceForOutput : removed call to javax/sound/midi/MidiDevice::open → SURVIVED |
dev.open(); |
| 44 | tmp = dev.getReceiver(); | |
| 45 | } | |
| 46 | } catch (Exception ignored) { | |
| 47 | } | |
| 48 |
2
1. isMidiDeviceForOutput : negated conditional → SURVIVED 2. isMidiDeviceForOutput : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiUtils::isMidiDeviceForOutput → SURVIVED |
return tmp != null; |
| 49 | } | |
| 50 | ||
| 51 | public static MidiDeviceScanner chooseOutputDevices( | |
| 52 | PrintStream ps, Pattern regex) { | |
| 53 |
1
1. chooseOutputDevices : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiUtils::chooseOutputDevices → NO_COVERAGE |
return new MidiDeviceScanner.RegexMidiDeviceScanner(ps, regex) { |
| 54 | @Override | |
| 55 | protected String getTitle() { | |
| 56 |
1
1. getTitle : replaced return value with "" for com/github/dakusui/symfonion/utils/midi/MidiUtils$1::getTitle → NO_COVERAGE |
return "MIDI-out devices"; |
| 57 | } | |
| 58 | ||
| 59 | @Override | |
| 60 | protected boolean matches(MidiDevice.Info device) { | |
| 61 |
3
1. matches : replaced boolean return with true for com/github/dakusui/symfonion/utils/midi/MidiUtils$1::matches → NO_COVERAGE 2. matches : negated conditional → NO_COVERAGE 3. matches : negated conditional → NO_COVERAGE |
return super.matches(device) && isMidiDeviceForOutput(device); |
| 62 | } | |
| 63 | }; | |
| 64 | } | |
| 65 | ||
| 66 | public static MidiDevice.Info[] getInfos(String portName, MidiDeviceScanner scanner, Pattern regex) throws CliException { | |
| 67 | MidiDevice.Info[] matchedInfos = scanner.getMatchedDevices(); | |
| 68 |
2
1. getInfos : negated conditional → NO_COVERAGE 2. getInfos : changed conditional boundary → NO_COVERAGE |
if (matchedInfos.length > 1) { |
| 69 | String msg = format("Device for port '%s' (regex:%s) wasn't unique (%d)", portName, regex, matchedInfos.length); | |
| 70 | throw new CliException(msg); | |
| 71 |
1
1. getInfos : negated conditional → NO_COVERAGE |
} else if (matchedInfos.length == 0) { |
| 72 | String msg = format("No matching device was found for port '%s' (regex:%s)", portName, regex); | |
| 73 | throw new CliException(msg); | |
| 74 | } | |
| 75 |
1
1. getInfos : replaced return value with null for com/github/dakusui/symfonion/utils/midi/MidiUtils::getInfos → NO_COVERAGE |
return matchedInfos; |
| 76 | } | |
| 77 | } | |
Mutations | ||
| 18 |
1.1 |
|
| 22 |
1.1 |
|
| 30 |
1.1 |
|
| 35 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 48 |
1.1 2.2 |
|
| 53 |
1.1 |
|
| 56 |
1.1 |
|
| 61 |
1.1 2.2 3.3 |
|
| 68 |
1.1 2.2 |
|
| 71 |
1.1 |
|
| 75 |
1.1 |