From 69a1ec499ec950c194a3992d761e7af12ab27747 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 30 Apr 2024 20:57:43 +0900 Subject: [PATCH 1/8] make tests more effective --- src/test/java/vavi/sound/mfi/MfiSystemTest.java | 7 ++++++- .../java/vavi/sound/mfi/vavi/VaviMidiConverterTest.java | 5 +++++ .../java/vavi/sound/midi/mfi/MfiMidiFileReaderTest.java | 5 +++++ src/test/java/vavi/sound/smaf/SmafSystemTest.java | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/java/vavi/sound/mfi/MfiSystemTest.java b/src/test/java/vavi/sound/mfi/MfiSystemTest.java index 3df491f..2e7aaab 100644 --- a/src/test/java/vavi/sound/mfi/MfiSystemTest.java +++ b/src/test/java/vavi/sound/mfi/MfiSystemTest.java @@ -15,7 +15,6 @@ import java.util.logging.Level; import org.junit.jupiter.api.Test; - import vavi.util.Debug; @@ -27,12 +26,18 @@ */ public class MfiSystemTest { + static { + System.setProperty("vavi.sound.mobile.AudioEngine.volume", System.getProperty("vavi.test.volume", "0.02")); +Debug.println("adpcm volume: " + System.getProperty("vavi.sound.mobile.AudioEngine.volume")); + } + @Test public void test() throws Exception { CountDownLatch cdl = new CountDownLatch(1); Path inPath = Paths.get(MfiSystemTest.class.getResource("/test.mld").toURI()); Sequencer sequencer = MfiSystem.getSequencer(); sequencer.open(); +// volume(((Synthesizer) sequencer).getReceiver(), 0.2f); // TODO interlock mid adpcm volume Sequence sequence = MfiSystem.getSequence(new BufferedInputStream(Files.newInputStream(inPath))); sequencer.setSequence(sequence); sequencer.addMetaEventListener(meta -> { diff --git a/src/test/java/vavi/sound/mfi/vavi/VaviMidiConverterTest.java b/src/test/java/vavi/sound/mfi/vavi/VaviMidiConverterTest.java index 669c087..6ed278b 100644 --- a/src/test/java/vavi/sound/mfi/vavi/VaviMidiConverterTest.java +++ b/src/test/java/vavi/sound/mfi/vavi/VaviMidiConverterTest.java @@ -32,6 +32,11 @@ */ public class VaviMidiConverterTest { + static { + System.setProperty("vavi.sound.mobile.AudioEngine.volume", System.getProperty("vavi.test.volume", "0.02")); +Debug.println("adpcm volume: " + System.getProperty("vavi.sound.mobile.AudioEngine.volume")); + } + @Test public void test() throws Exception { CountDownLatch cdl = new CountDownLatch(1); diff --git a/src/test/java/vavi/sound/midi/mfi/MfiMidiFileReaderTest.java b/src/test/java/vavi/sound/midi/mfi/MfiMidiFileReaderTest.java index caf59ce..d23bd64 100644 --- a/src/test/java/vavi/sound/midi/mfi/MfiMidiFileReaderTest.java +++ b/src/test/java/vavi/sound/midi/mfi/MfiMidiFileReaderTest.java @@ -25,6 +25,11 @@ */ public class MfiMidiFileReaderTest { + static { + System.setProperty("vavi.sound.mobile.AudioEngine.volume", System.getProperty("vavi.test.volume", "0.02")); +Debug.println("adpcm volume: " + System.getProperty("vavi.sound.mobile.AudioEngine.volume")); + } + @Test public void test() throws Exception { InputStream is = MfiVaviSequenceTest.class.getResourceAsStream("/test.mld"); diff --git a/src/test/java/vavi/sound/smaf/SmafSystemTest.java b/src/test/java/vavi/sound/smaf/SmafSystemTest.java index fc010fb..49acb8e 100644 --- a/src/test/java/vavi/sound/smaf/SmafSystemTest.java +++ b/src/test/java/vavi/sound/smaf/SmafSystemTest.java @@ -27,6 +27,11 @@ */ public class SmafSystemTest { + static { + System.setProperty("vavi.sound.mobile.AudioEngine.volume", System.getProperty("vavi.test.volume", "0.02")); +Debug.println("adpcm volume: " + System.getProperty("vavi.sound.mobile.AudioEngine.volume")); + } + @Test public void test() throws Exception { CountDownLatch cdl = new CountDownLatch(1); From 2a386808638a3df64d8592c6d71d92c6dd6e58e1 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 30 Apr 2024 20:58:34 +0900 Subject: [PATCH 2/8] make it interlock with maven project version --- .../sound/mfi/vavi/VaviMfiDeviceProvider.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java b/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java index d301087..ef5cf2d 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java @@ -6,6 +6,7 @@ package vavi.sound.mfi.vavi; +import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -27,11 +28,27 @@ */ public class VaviMfiDeviceProvider extends MfiDeviceProvider { + static { + try { + try (InputStream is = VaviMfiDeviceProvider.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound/pom.properties")) { + if (is != null) { + Properties props = new Properties(); + props.load(is); + version = props.getProperty("version", "undefined in pom.properties"); + } else { + version = System.getProperty("vavi.test.version", "undefined"); + } + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + /** */ - public static final String version = "1.0.10"; + public static final String version; /** */ - private MfiDevice.Info[] mfiDeviceInfos; + private final MfiDevice.Info[] mfiDeviceInfos; /** */ public VaviMfiDeviceProvider() { From 41d680724f855388fda2c7c170975b98106c7365 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 30 Apr 2024 20:59:03 +0900 Subject: [PATCH 3/8] follow ide advices --- .../vavi/sound/mfi/vavi/VaviSequencer.java | 27 +++++++++---------- .../java/vavi/sound/mobile/AudioEngine.java | 5 ++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java b/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java index 6f7b9b9..2a8cd85 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java @@ -202,26 +202,23 @@ protected void fireMeta(MetaMessage meta) { } /** meta 0x2f listener */ - private javax.sound.midi.MetaEventListener mel = new javax.sound.midi.MetaEventListener() { - @Override - public void meta(javax.sound.midi.MetaMessage message) { + private javax.sound.midi.MetaEventListener mel = message -> { Debug.println("★0 meta: type: " + message.getType()); - switch (message.getType()) { - case 0x2f: // java midi sequencer adds automatically - try { - MetaMessage metaMessage = new MetaMessage(); - metaMessage.setMessage(0x2f, new byte[0], 0); - fireMeta(metaMessage); - off(); - } catch (InvalidMfiDataException e) { + switch (message.getType()) { + case 0x2f: // java midi sequencer adds automatically + try { + MetaMessage metaMessage = new MetaMessage(); + metaMessage.setMessage(0x2f, new byte[0], 0); + fireMeta(metaMessage); + off(); + } catch (InvalidMfiDataException e) { Debug.println(Level.SEVERE, e); - } + } catch (RuntimeException | Error e) { Debug.printStackTrace(e); - throw e; +throw e; } - break; - } + break; } }; diff --git a/src/main/java/vavi/sound/mobile/AudioEngine.java b/src/main/java/vavi/sound/mobile/AudioEngine.java index 1424e80..f3faa78 100644 --- a/src/main/java/vavi/sound/mobile/AudioEngine.java +++ b/src/main/java/vavi/sound/mobile/AudioEngine.java @@ -19,11 +19,16 @@ * (means having a contractor without argument) * {@link #encode(int, int, byte[])} related should be stateless. *

+ * system property + *
    + *
  • vavi.sound.mobile.AudioEngine.volume ... adpcm volume
  • + *
* @author Naohide Sano (nsano) * @version 0.00 051116 nsano initial version
*/ public interface AudioEngine { + // TODO interlock midi volume double volume = Double.parseDouble(System.getProperty("vavi.sound.mobile.AudioEngine.volume", "0.2")); /** From dd95ba0a1362ff8db5bf0acb1f35ccbfad5ee08e Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Fri, 17 May 2024 01:21:50 +0900 Subject: [PATCH 4/8] anti i18n --- src/main/java/readme.md | 20 +- src/main/java/vavi/sound/mfi/readme.md | 33 +- .../vavi/sound/mfi/vavi/mitsubishi/readme.md | 2 +- .../java/vavi/sound/mfi/vavi/nec/readme.md | 2 +- src/main/java/vavi/sound/mfi/vavi/readme.md | 24 +- .../java/vavi/sound/mfi/vavi/sharp/readme.md | 2 +- .../java/vavi/sound/mfi/vavi/track/readme.md | 22 +- src/main/java/vavi/sound/midi/mfi/readme.md | 10 +- src/main/java/vavi/sound/midi/readme.md | 7 +- src/main/java/vavi/sound/midi/smaf/readme.md | 6 +- src/main/java/vavi/sound/mobile/readme.md | 4 +- src/main/java/vavi/sound/smaf/chunk/readme.md | 4 +- src/main/java/vavi/sound/smaf/readme.md | 14 +- src/main/java/vavi/util/readme.md | 6 +- .../vavi/sound/mfi/MfiSystem.properties | 6 +- .../mfi/vavi/mitsubishi/mitsubishi.properties | 16 +- .../vavi/sound/mfi/vavi/nec/nec.properties | 26 +- .../sound/mfi/vavi/sharp/sharp.properties | 4 +- .../vavi/sound/mfi/vavi/vavi.properties | 365 +++++++++--------- .../vavi/sound/sampled/FilterChain.properties | 2 +- .../sampled/mfi/MfiWithVoiceMaker.properties | 6 +- .../smaf/SmafWithVoiceMaker.properties | 2 +- .../vavi/sound/smaf/chunk/language.properties | 20 +- .../resources/vavi/sound/smaf/smaf.properties | 10 +- 24 files changed, 304 insertions(+), 309 deletions(-) diff --git a/src/main/java/readme.md b/src/main/java/readme.md index db34d74..4ec4fef 100644 --- a/src/main/java/readme.md +++ b/src/main/java/readme.md @@ -25,9 +25,9 @@ packages * `vavi.sound.adpcm.ma` * `vavi.sound.adpcm.vox` -着声に使用される ADPCM コーデックを取り扱うパッケージ群です。 -Java の標準 IO ({@link java.io.InputStream}/{@link java.io.OutputStream}) として実装されているため -取り扱いが容易でストリーミングも楽に行えます。 +A group of packages that handle the ADPCM codec used for voice ringtone. +Because it is implemented as Java standard IO ({@link java.io.InputStream}/{@link java.io.OutputStream}) +Easy to handle and stream easily. ### 2. MFi library @@ -37,10 +37,10 @@ packages * `vavi.sound.mfi.vavi` * : -着メロライブラリの核となる部分です。MFi のファイル構造を取り扱い、MIDI 構造に変換する事が出来ます。 -また MIDI から MFi への変換も可能です。基本的に {@link javax.sound.midi} パッケージと同じ構造をとっています。 -機種依存データを扱うパッケージとして {@link vavi.sound.mfi.vavi.mitsubishi D社} と -{@link vavi.sound.mfi.vavi.nec N社} がサンプル実装されています。 +This is the core part of the ringtone library. It can handle MFi file structures and convert them to MIDI structures. +It is also possible to convert from MIDI to MFi. It basically has the same structure as the {@link javax.sound.midi} package. +{@link vavi.sound.mfi.vavi.mitsubishi Company D} as a package that handles model-dependent data +{@link vavi.sound.mfi.vavi.nec Company N} has been implemented as a sample. ### 3. `javax.sound.midi.spi` implementation @@ -49,10 +49,10 @@ packages * `vavi.sound.midi` * `vavi.sound.midi.mfi` -`javax.sound.midi.spi` の一実装として機能させるためのパッケージです。 +This is a package to function as an implementation of `javax.sound.midi.spi`. [SPI](http://java.sun.com/j2se/1.5.0/ja/docs/ja/guide/sound/programmer_guide/chapter1.html#111901) -仕様に従い登録すれば midi の一ファイル形式として MFi ファイルを -再生する事が可能になります。 +If you register according to the specifications, you can use MFi files as a midi file format. +It will be possible to play it. ## How to diff --git a/src/main/java/vavi/sound/mfi/readme.md b/src/main/java/vavi/sound/mfi/readme.md index 9428f96..dd1ea1d 100644 --- a/src/main/java/vavi/sound/mfi/readme.md +++ b/src/main/java/vavi/sound/mfi/readme.md @@ -1,30 +1,31 @@ # vavi.sound.mfi -MFi サウンド関連のクラスを提供します. +Provides MFi sound related classes. ## Abstract -{@link javax.sound.midi} パッケージとほぼ同じ構造をしています。 -使用法は {@link javax.sound.midi} を参考にしてください。 +It has almost the same structure as the {@link javax.sound.midi} package. +Please refer to {@link javax.sound.midi} for usage. -{@link vavi.sound.mfi.MfiSystem.getSequencer()} で再生する場合は -システムプロパティ javax.sound.midi.Sequencer に "#Real Time Sequencer" -を明示するようにしてください。{@link vavi.sound.midi.VaviSequencer} が -デフォルトシーケンサになった場合 {@link vavi.sound.mfi.MfiSystem#getMetaEventListener()} -が重複して登録されてしまいます。 +When playing with {@link vavi.sound.mfi.MfiSystem.getSequencer()} +"#Real Time Sequencer" in system property javax.sound.midi.Sequencer +Please make it clear. {@link vavi.sound.midi.VaviSequencer} +If it becomes the default sequencer {@link vavi.sound.mfi.MfiSystem#getMetaEventListener()} +will be registered twice. ## TODO - * 特殊命令の実装 - * ~~"030825" MfiFileFormat のヘッダ情報の扱いが未実装、メッセージにするか?ファイルフォーマットにするか?~~ → - * ~~"030825" 出てない音階がある~~ - * MfiSystem converter の取得法が他と違う - * ~~"090110">MfiSystem#main で鳴らない...~~ + * Implementing special instructions + * ~~030825 Handling of MfiFileFormat header information is not implemented, should it be made into a message? Should it be a file format?~~ → + * ~~030825 There are scales that don't appear~~ + * The method of obtaining MfiSystem converter is different from others + * ~~090110 MfiSystem#main does not sound...~~ ## License -オリジナルのソースは見あたらないため -一次ライセンスを気にする必要は無いと思われますが、 -念のために記しておきます。 + +Because the original source is not found +Although it seems that there is no need to worry about the primary license, +I'll note this down just in case. * [open i-Melody Project](http://www.xucker.jpn.org/ood/java/imelody/") * [Academic Free License (AFL)](http://opensource.org/licenses/academic.php") diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/readme.md b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/readme.md index 4770d65..7c13dfc 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/readme.md +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/readme.md @@ -1,5 +1,5 @@ # vavi.sound.mfi.vavi.mitsubishi -三菱電機製固有のメッセージ処理クラスを提供します. +Provides message processing classes specific to Mitsubishi Electric. ## TODO diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/readme.md b/src/main/java/vavi/sound/mfi/vavi/nec/readme.md index c8e8b5b..99fa013 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/readme.md +++ b/src/main/java/vavi/sound/mfi/vavi/nec/readme.md @@ -1,5 +1,5 @@ # vavi.sound.mfi.vavi.nec -NEC 固有のメッセージ処理クラスを提供します. +Provides NEC-specific message processing classes. ## TODO diff --git a/src/main/java/vavi/sound/mfi/vavi/readme.md b/src/main/java/vavi/sound/mfi/vavi/readme.md index 1a7b5b7..eb6ab05 100644 --- a/src/main/java/vavi/sound/mfi/vavi/readme.md +++ b/src/main/java/vavi/sound/mfi/vavi/readme.md @@ -1,17 +1,19 @@ -MFi のサービスプロバイダ実装例のクラスを提供します. +# vavi.sound.mfi.vavi - * 特別な仕様として拡張情報の空番 0xfd を MetaMessage として使用します。 +Provides a class for MFi service provider implementation example. + + * As a special specification, the empty number 0xfd in the extension information is used as MetaMessage. ## TODO * ~~020630 VaviSequencer: stop()~~ * ~~020706 VaviSequence: Midi Converter~~ - * ~~030826 MidiFileReader を作る~~ - * ~~030917 InfoMessage のいくつかは MetaMessage (1,2,3...) に変換可能~~ - * ~~041223 TempoMessage もデルタタイム対応させなければいけない~~ - * ~~041231 SMF type 1 対応 → 4ch を一つの ArrayList に入れてから処理とか~~ - * MFiConvertible は違うところで実装すべき? - * ADPCM も Δ タイムにのっとって演奏する -> Thread 化? - * SMF -> MFi がまだおかしい M$ 系のやつとか - * ~~070117 { Normal, Class A, B, C, Note }, { Extension A, B, Info } の統合~~ - * Track, AudioData, Info* の統合 + * ~~030826 Create a MidiFileReader~~ + * ~~030917 Some InfoMessages can be converted to MetaMessage (1,2,3...)~~ + * ~~041223 TempoMessage must also support delta time~~ + * ~~041231 SMF type 1 compatible → Put 4ch into one ArrayList and then process it?~~ + * Should MFiConvertible be implemented somewhere else? + * ADPCM also plays according to Δ time -> Thread? + * SMF -> M$ type where MFi is still strange + * ~~070117 Integration of { Normal, Class A, B, C, Note }, { Extension A, B, Info }~~ + * Track, AudioData, Info* integration diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/readme.md b/src/main/java/vavi/sound/mfi/vavi/sharp/readme.md index a2b91bc..c4fca83 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/readme.md +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/readme.md @@ -1,5 +1,5 @@ # vavi.sound.mfi.vavi.sharp -Sharp 製固有のメッセージ処理クラスを提供します. +Provides Sharp-specific message processing classes. ## TODO diff --git a/src/main/java/vavi/sound/mfi/vavi/track/readme.md b/src/main/java/vavi/sound/mfi/vavi/track/readme.md index 70564e9..c52e031 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/readme.md +++ b/src/main/java/vavi/sound/mfi/vavi/track/readme.md @@ -1,28 +1,28 @@ # vavi.sound.mfi.vavi.system -SysexMessage の派生クラスを提供します. +Provides a derived class of SysexMessage. -### Δタイム +### Δtime - * テンポ ... 1 分間の 4 分音符の数 - * タイムベース ... 4 分音符の分解能 = PPQ (Parts ...), TpQN (Tick par Quarter Note) + * Tempo ... number of quarter notes in 1 minute + * Timebase ... Quarter note resolution = PPQ (Parts ...), TpQN (Tick par Quarter Note) ``` - 1Δ = 60[s] / テンポ / タイムベース; + 1Δ = 60[s] / Tempo / Timebase; ``` ## TODO - * Δ > 255 の Note の取り扱い + * Handling notes with Δ > 255 - たとえば音調 380 (voice = 1) +For example, tone 380 (voice = 1) -|delta|voice|gateTime|説明| +|delta|voice|gateTime|explanation| |:-:|:-:|:-:|:-:| |-|1|2 + 10 + 1 = 13|| |2|2|-|| |10|3|-|| -|0|1|max(380 - 13, 255) = 255|voice が 1 ラウンドしたあとに?| +|0|1|max(380 - 13, 255) = 255|After one round of voice?| - PsmPlayer は飛ばした分を最初のΔから引いている +PsmPlayer subtracts the skipped amount from the initial Δ - * MFi 5.0 拡張用情報 + * Information for MFi 5.0 extension diff --git a/src/main/java/vavi/sound/midi/mfi/readme.md b/src/main/java/vavi/sound/midi/mfi/readme.md index cd980ae..2a0129c 100644 --- a/src/main/java/vavi/sound/midi/mfi/readme.md +++ b/src/main/java/vavi/sound/midi/mfi/readme.md @@ -1,11 +1,11 @@ # vavi.sound.midi.mfi -MIDI のサービスプロバイダ実装例 (MFi) のクラスを提供します。 +Provides a MIDI Service Provider Implementation Example (MFi) class. -fileType は 0x88 +fileType is 0x88 # TODO - * ~~midi spi のとき MetaEvent 06 がリッスンされていない → MetaListener の提供~~ - * MetaEventApapter を Sequencer にあらかじめ付けておく~~ - * ~~spi に追加した場合 SMF もストリームから読めなくなる~~ + * ~~MetaEvent 06 is not being listened to when using midi spi → Providing MetaListener~~ + * Attach MetaEventAdapter to Sequencer in advance~~ + * ~~If added to spi, SMF will also become unreadable from the stream.~~ diff --git a/src/main/java/vavi/sound/midi/readme.md b/src/main/java/vavi/sound/midi/readme.md index 5ed9ae3..fbbe110 100644 --- a/src/main/java/vavi/sound/midi/readme.md +++ b/src/main/java/vavi/sound/midi/readme.md @@ -2,9 +2,10 @@ Provides base classes for the MIDI service provider. -## 注意 -MFi, SMAF をこのパッケージで再生する場合、システムプロパティ `javax.sound.midi.Sequencer` に -`"#Java MIDI(MFi/SMAF) ADPCM Sequencer"` と設定してください。ADPCM のハンドリングができなくなります。 +## Note + +~~When playing MFi, SMAF with this package, set the system property `javax.sound.midi.Sequencer` to +Please set `"#Java MIDI(MFi/SMAF) ADPCM Sequencer"`. ADPCM handling will no longer be possible.~~ ## MIDI file type for MFi/SMAF (⚠ this is not MIDI specs, proprietary) diff --git a/src/main/java/vavi/sound/midi/smaf/readme.md b/src/main/java/vavi/sound/midi/smaf/readme.md index 47b9e7e..ebb2c38 100644 --- a/src/main/java/vavi/sound/midi/smaf/readme.md +++ b/src/main/java/vavi/sound/midi/smaf/readme.md @@ -1,9 +1,9 @@ # vavi.sound.midi.smaf -MIDI のサービスプロバイダ実装例 (SMAF) のクラスを提供します。 +Provides a MIDI Service Provider Implementation Example (SMAF) class. -fileType は 0x84 (MobileStandard) +fileType is 0x84 (MobileStandard) ## TODO - * Handyphone とか Compress とか + * Handyphone, Compress etc. diff --git a/src/main/java/vavi/sound/mobile/readme.md b/src/main/java/vavi/sound/mobile/readme.md index 985dd71..9b7581b 100644 --- a/src/main/java/vavi/sound/mobile/readme.md +++ b/src/main/java/vavi/sound/mobile/readme.md @@ -1,7 +1,7 @@ # vavi.sound.mobile -mobile 用の wave シーケンサのクラスを提供します。 +Provides a wave sequencer class for mobile. ## TODO - * continued がおかしい + * something is wrong with `continued` diff --git a/src/main/java/vavi/sound/smaf/chunk/readme.md b/src/main/java/vavi/sound/smaf/chunk/readme.md index a053586..48a575f 100644 --- a/src/main/java/vavi/sound/smaf/chunk/readme.md +++ b/src/main/java/vavi/sound/smaf/chunk/readme.md @@ -1,10 +1,10 @@ # vavi.sound.smaf.chunk -SMAF サウンド関連のファイル構造を表すクラスを提供します. +Provides a class that represents the file structure related to SMAF sound. ## Abstract -SMAF ファイルの読み込み時に使用されます。 +Used when reading SMAF files. ## Structure diff --git a/src/main/java/vavi/sound/smaf/readme.md b/src/main/java/vavi/sound/smaf/readme.md index 98498c7..37346c4 100644 --- a/src/main/java/vavi/sound/smaf/readme.md +++ b/src/main/java/vavi/sound/smaf/readme.md @@ -1,18 +1,18 @@ # vavi.sound.smaf -SMAF サウンド関連のクラスを提供します. +Provides classes related to SMAF sound. ## Abstract -{@link javax.sound.midi} パッケージとほぼ同じ構造をしています。 -使用法は {@link javax.sound.midi} を参考にしてください。 +It has almost the same structure as the {@link javax.sound.midi} package. +Please refer to {@link javax.sound.midi} for usage. ## TODO - * ~~ datetime="080512" smaf -> midi がおかしい~~ - * ma# emu を使用したシーケンサーとか [mmftool](https://murachue.sytes.net/web/softlist.cgi?mode=desc&title=mmftool) - * HV と VSQ の相互変換? - * GraphicsTrackChunk でモバラジ + * ~~ 080512 Something is wrong with smaf -> midi~~ + * sequencer using ma# emu? [mmftool](https://murachue.sytes.net/web/softlist.cgi?mode=desc&title=mmftool) + * Conversion between HV and VSQ? + * MobaRad with GraphicsTrackChunk * gervill ## Reference diff --git a/src/main/java/vavi/util/readme.md b/src/main/java/vavi/util/readme.md index a7acaa9..71cc4a2 100644 --- a/src/main/java/vavi/util/readme.md +++ b/src/main/java/vavi/util/readme.md @@ -1,11 +1,11 @@ # vavi.util -FFT, Bessel 関連のクラスを提供します. +Provides classes related to FFT and Bessel. ## TODO - * ~~FFT がおかしい~~ - * FFT がバージョンアップしてる + * ~~FFT is wrong~~ + * FFT has been updated ## License diff --git a/src/main/resources/vavi/sound/mfi/MfiSystem.properties b/src/main/resources/vavi/sound/mfi/MfiSystem.properties index e075858..95cd03c 100644 --- a/src/main/resources/vavi/sound/mfi/MfiSystem.properties +++ b/src/main/resources/vavi/sound/mfi/MfiSystem.properties @@ -10,10 +10,10 @@ # ## -# MfiSystem がデフォルトで使用する MfiDeviceProvider +# MfiDeviceProvider used by MfiSystem by default # -# @name "default.provider" キー -# @value MfiDeviceProvider クラス名 +# @name "default.provider" key +# @value MfiDeviceProvider class name # @see vavi.sound.mfi.MfiSystem # #default.provider=vavi.sound.mfi.ittake.IttakeMfiDeviceProvider diff --git a/src/main/resources/vavi/sound/mfi/vavi/mitsubishi/mitsubishi.properties b/src/main/resources/vavi/sound/mfi/vavi/mitsubishi/mitsubishi.properties index 35d715f..3c9e47d 100644 --- a/src/main/resources/vavi/sound/mfi/vavi/mitsubishi/mitsubishi.properties +++ b/src/main/resources/vavi/sound/mfi/vavi/mitsubishi/mitsubishi.properties @@ -11,21 +11,21 @@ # # MitsubishiSequencer # -# 0x01 Pitch Bend 設定 +# 0x01 Pitch Bend setting function.1=vavi.sound.mfi.vavi.mitsubishi.Function1 -# 0x02 Pitch Bend Range 設定 +# 0x02 Pitch Bend Range setting function.2=vavi.sound.mfi.vavi.mitsubishi.Function2 -# 0x03 Modulation 設定 +# 0x03 Modulation setting function.3=vavi.sound.mfi.vavi.mitsubishi.Function3 -# 0x10 UCS Wave 設定 +# 0x10 UCS Wave setting #function.16=vavi.sound.mfi.vavi.mitsubishi.Function16 -# 0x11 UCS Parameter 設定 +# 0x11 UCS Parameter setting #function.17=vavi.sound.mfi.vavi.mitsubishi.Function17 -# 0x12 UCS 管理ステータス設定 +# 0x12 UCS Admin status setting #function.18=vavi.sound.mfi.vavi.mitsubishi.Function18 -# 0x81 WAVE Channel Volume 設定 +# 0x81 WAVE Channel Volume setting function.129=vavi.sound.mfi.vavi.mitsubishi.Function129 -# 0x82 WAVE Channel Panpot 設定 +# 0x82 WAVE Channel Panpot setting function.130=vavi.sound.mfi.vavi.mitsubishi.Function130 # 0x83 WAVE Packet Data function.131=vavi.sound.mfi.vavi.mitsubishi.Function131 diff --git a/src/main/resources/vavi/sound/mfi/vavi/nec/nec.properties b/src/main/resources/vavi/sound/mfi/vavi/nec/nec.properties index 9b58a9f..4e5199a 100644 --- a/src/main/resources/vavi/sound/mfi/vavi/nec/nec.properties +++ b/src/main/resources/vavi/sound/mfi/vavi/nec/nec.properties @@ -28,13 +28,13 @@ function.242.4=vavi.sound.mfi.vavi.nec.Function242_4 # f2._5 LED function.242.5=vavi.sound.mfi.vavi.nec.Function242_5 -# 01.f0._3 拡張 FM 基本波形 -# 01.f0._4 拡張 FM 音色指定 -# 01.f0._5 拡張 WT 音色指定 -# 01.f0._6 拡張 WT 波形指定 -# 01.f0._7 拡張ストリーム波形制御情報 +# 01.f0._3 Extended FM basic waveform +# 01.f0._4 Extended FM tone specification +# 01.f0._5 Extended WT tone specification +# 01.f0._6 Extended WT waveform specification +# 01.f0._7 Extended stream waveform control information function.1.240.7=vavi.sound.mfi.vavi.nec.Function1_240_7 -# 01.f0._8 拡張 AL 音色指定 +# 01.f0._8 Extended AL tone specification # 01.f1.x3 StreamOn function.1.241.3=vavi.sound.mfi.vavi.nec.Function1_241_3 @@ -47,18 +47,18 @@ function.1.241.6=vavi.sound.mfi.vavi.nec.Function1_241_6 # 01.f1.x7 Hold1 # 01.f1.x8 MonoOn # 01.f1.x9 PlayOn -# 01.f1.xa フィルタレゾナンス -# 01.f1.xb フィルタブライトネス +# 01.f1.xa filter resonance +# 01.f1.xb filter brightness -# 01.f2._7 Channel Status 制御情報 +# 01.f2._7 Channel Status control information -# 01.f3._1 FM モード設定 +# 01.f3._1 FM mode setting # # 01.f3._2 UserEvent -# 01.f3._3 MaxGain 設定 +# 01.f3._3 MaxGain setting function.1.243.3=vavi.sound.mfi.vavi.nec.Function1_243_3 -# 01.f3._4 ストリーム数指定 +# 01.f3._4 Specify number of streams function.1.243.4=vavi.sound.mfi.vavi.nec.Function1_243_4 -# 01.f3._5 AL チャンネル指定 +# 01.f3._5 AL channel specification ## diff --git a/src/main/resources/vavi/sound/mfi/vavi/sharp/sharp.properties b/src/main/resources/vavi/sound/mfi/vavi/sharp/sharp.properties index a44cd0f..7059c55 100644 --- a/src/main/resources/vavi/sound/mfi/vavi/sharp/sharp.properties +++ b/src/main/resources/vavi/sound/mfi/vavi/sharp/sharp.properties @@ -11,9 +11,9 @@ # # SharpSequencer # -# 0x81 Wave Channel Volume 設定 +# 0x81 Wave Channel Volume setting function.129=vavi.sound.mfi.vavi.sharp.Function129 -# 0x82 Wave Channel Panpot 設定 +# 0x82 Wave Channel Panpot setting function.130=vavi.sound.mfi.vavi.sharp.Function130 # 0x83 Wave Packet Data function.131=vavi.sound.mfi.vavi.sharp.Function131 diff --git a/src/main/resources/vavi/sound/mfi/vavi/vavi.properties b/src/main/resources/vavi/sound/mfi/vavi/vavi.properties index 3c6d07c..c16631f 100644 --- a/src/main/resources/vavi/sound/mfi/vavi/vavi.properties +++ b/src/main/resources/vavi/sound/mfi/vavi/vavi.properties @@ -13,7 +13,7 @@ #------------------------------------------------------------------------------ ## -# フォーマットのデフォルトの値 +# Default value for format # format.type.major=1 format.type.minor=1 @@ -24,9 +24,9 @@ format.header.vers=0400 #------------------------------------------------------------------------------ ## -# ベンダー番号に対応するシーケンサー +# Sequencer corresponding to vendor number # -# @name "sequencer.vendor" + ベンダー番号 + キャリア番号 +# @name "sequencer.vendor" + Vendor number + Carrier number # @see vavi.sound.mfi.vavi.MetaEventAdapter # # nec 16 | docomo 1 @@ -49,9 +49,9 @@ sequencer.vendor.113=vavi.sound.mfi.vavi.sharp.SharpSequencer #------------------------------------------------------------------------------ ## -# フォーマットタイプに対応する AudioEngine +# AudioEngine corresponding to the format type # -# @name "audioEngine.format" + フォーマットタイプ +# @name "audioEngine.format" + format type # @see vavi.sound.mobile.AudioDataMessage # # ADPCM Type1 0x80 ??? @@ -69,10 +69,9 @@ audioEngine.format.129=vavi.sound.mobile.FuetrekAudioEngine # ## -# 未定義メッセージを処理するクラス +# Class to handle undefined messages # -# @value vavi.sound.mfi.MfiMessage を継承し -# (int,int,int,[B), (int,int,int,int) コンストラクタを持つもの +# @value Those that inherit vavi.sound.mfi.MfiMessage and have (int,int,int,[B), (int,int,int,int) constructors # mfi.track.unknown=vavi.sound.mfi.vavi.track.UndefinedMessage @@ -81,51 +80,48 @@ mfi.track.unknown=vavi.sound.mfi.vavi.track.UndefinedMessage # ## -# ノートメッセージを処理するクラス +# Class that handles note messages # -# @value vavi.sound.mfi.NoteMessage を継承し -# (int,int,int), (int,int,int,int) コンストラクタを持つもの +# @value Inherits from vavi.sound.mfi.NoteMessage (int,int,int) and has (int,int,int,int) constructor # mfi.track.note=vavi.sound.mfi.vavi.VaviNoteMessage # -# -------- Normal (拡張ステータス情報) -------- +# -------- Normal (Extended status information) -------- # -# ---- 拡張ステータス A ---- +# ---- Extended status A ---- # -# vavi.sound.mfi.LongMessage を継承し -# (int,int,int,[B) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.LongMessage and has a (int,int,int,[B) constructor # -# すべて予約 +# All reserved -# ---- 拡張ステータス B ---- +# ---- Extended status B ---- # -# vavi.sound.mfi.ShortMessage を継承し -# (int,int,int,int) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.ShortMessage and has a (int,int,int,int) constructor # # -# 0xb# チャンネルナンバに依存しない音源制御情報 +# 0xb# Sound source control information independent of channel numbers # -# + 0xb0 マスタボリューム +# + 0xb0 Master volume mfi.track.255.b.176=vavi.sound.mfi.vavi.track.MasterVolumeMessage -# + 0xb1 マスタバランス +# + 0xb1 Master balance #mfi.track.255.b.177=vavi.sound.mfi.vavi.track.MasterValanceMessage -# + 0xbc テンポの相対変化 +# + 0xbc Relative change in tempo #mfi.track.255.b.188=vavi.sound.mfi.vavi.track.RelativeTempoMessage -# + 0xbd マスタボリュームの相対変化 +# + 0xbd Relative change in master volume #mfi.track.255.b.189=vavi.sound.mfi.vavi.track.RelativeMasterVolumeMessage -# + 0xbe ストップ・アンド・ミュート +# + 0xbe Stop and mute #mfi.track.255.b.190=vavi.sound.mfi.vavi.track.StopAndMuteMessage -# + 0xbf 音源リセット +# + 0xbf Sound source reset #mfi.track.255.b.191=vavi.sound.mfi.vavi.track.ResetMessage -# + 0xba チャンネルコンフィグレーション +# + 0xba Channel configuration mfi.track.255.b.186=vavi.sound.mfi.vavi.track.ChannelConfigurationMessage # -# 0xc# テンポメッセージ +# 0xc# tempo message # # + 0xc0 6 mfi.track.255.b.192=vavi.sound.mfi.vavi.track.TempoMessage @@ -141,7 +137,7 @@ mfi.track.255.b.196=vavi.sound.mfi.vavi.track.TempoMessage mfi.track.255.b.197=vavi.sound.mfi.vavi.track.TempoMessage # + 0xc6 384 mfi.track.255.b.198=vavi.sound.mfi.vavi.track.TempoMessage -# + 0xc7 予約 +# + 0xc7 \u4E88\u7D04 mfi.track.255.b.199=vavi.sound.mfi.vavi.track.TempoMessage # + 0xc8 15 mfi.track.255.b.200=vavi.sound.mfi.vavi.track.TempoMessage @@ -157,17 +153,17 @@ mfi.track.255.b.204=vavi.sound.mfi.vavi.track.TempoMessage mfi.track.255.b.205=vavi.sound.mfi.vavi.track.TempoMessage # + 0xce 960 mfi.track.255.b.206=vavi.sound.mfi.vavi.track.TempoMessage -# + 0xcf 予約 +# + 0xcf \u4E88\u7D04 mfi.track.255.b.207=vavi.sound.mfi.vavi.track.TempoMessage # -# 0xd# 演奏管理情報 +# 0xd# Performance management information # -# + 0xd0 演奏位置情報 (キューポイント) +# + 0xd0 Performance position information (cue point) mfi.track.255.b.208=vavi.sound.mfi.vavi.track.CuePointMessage # + 0xdc NOP2 (No OPeration2) mfi.track.255.b.220=vavi.sound.mfi.vavi.track.Nop2Message -# + 0xdd ループポイント +# + 0xdd Loop point mfi.track.255.b.221=vavi.sound.mfi.vavi.track.LoopPointMessage # + 0xde NOP (No OPeration) mfi.track.255.b.222=vavi.sound.mfi.vavi.track.NopMessage @@ -175,39 +171,39 @@ mfi.track.255.b.222=vavi.sound.mfi.vavi.track.NopMessage mfi.track.255.b.223=vavi.sound.mfi.vavi.track.EndOfTrackMessage # -# 0xe# 音源制御情報 +# 0xe# Sound source control information # -# + 0xe0 音色番号変更 +# + 0xe0 Tone number change mfi.track.255.b.224=vavi.sound.mfi.vavi.track.ChangeVoiceMessage -# + 0xe1 音色バンク変更 +# + 0xe1 Change tone bank mfi.track.255.b.225=vavi.sound.mfi.vavi.track.ChangeBankMessage -# + 0xe2 ボリューム変更 +# + 0xe2 Volume change mfi.track.255.b.226=vavi.sound.mfi.vavi.track.VolumeMessage -# + 0xe3 パンポット +# + 0xe3 Pan pot mfi.track.255.b.227=vavi.sound.mfi.vavi.track.PanpotMessage -# + 0xe4 ピッチベンド設定 +# + 0xe4 Pitch bend settings mfi.track.255.b.228=vavi.sound.mfi.vavi.track.PitchBendMessage -# + 0xe5 チャンネル割り当て +# + 0xe5 Channel assignment mfi.track.255.b.229=vavi.sound.mfi.vavi.track.ChannelChangeMessage -# + 0xe6 ボリュームの相対変化 +# + 0xe6 Relative change in volume mfi.track.255.b.230=vavi.sound.mfi.vavi.track.ExpressionMessage -# + 0xe7 ピッチベンドレンジ設定 +# + 0xe7 Pitch bend range setting mfi.track.255.b.231=vavi.sound.mfi.vavi.track.PitchBendRangeMessage -# + 0xe8 ファインピッチベンド A 設定 +# + 0xe8 Fine pitch bend A setting #mfi.track.255.b.232=vavi.sound.mfi.vavi.track.FinePitchBendAMessage -# + 0xe9 ファインピッチベンド B 設定 +# + 0xe9 Fine pitch bend B setting #mfi.track.255.b.233=vavi.sound.mfi.vavi.track.FinePitchBendBMessage -# + 0xea モジュレーションデプス設定 +# + 0xea Modulation depth setting mfi.track.255.b.234=vavi.sound.mfi.vavi.track.ModulationDepthMessage -# ---- 拡張情報 ---- +# ---- Extended information ---- # -# vavi.sound.mfi.SysexMessage を継承し -# static SysexMessage readFrom(int,int,int,InputStream) メソッドシグネチャを持つもの +# Those that inherit vavi.sound.mfi.SysexMessage and have the +# static SysexMessage readFrom(int,int,int,InputStream) method signature # # -# 0xf# 拡張情報 +# 0xf# Extended information # # + 0xf0 mfi.track.255.e.240=vavi.sound.mfi.vavi.track.VoiceEditMessage @@ -217,11 +213,11 @@ mfi.track.255.e.241=vavi.sound.mfi.vavi.track.ExtendedEditMessage #mfi.track.255.e.242=vavi.sound.mfi.vavi.track.CaraokeTextMessage # + 0xf3 #mfi.track.255.e.243=vavi.sound.mfi.vavi.track.CaraokeImageMessage -# + 0xfe ノン・レジスタード・メッセージ指定 +# + 0xfe Non-registered message specification # length = dis.readShort() # id = dis.read(); # data ... -# 0: 拡張用情報識別 ID +# 0: Extension information ID # 7654 3210 # ~~~~ ~~~~ # | +- 0001: DoCoMo @@ -229,138 +225,133 @@ mfi.track.255.e.241=vavi.sound.mfi.vavi.track.ExtendedEditMessage # +- 0000: reserved # : # 1110: reserved -# 1111: 海外向け拡張データ -# 0xff なら次(1:)に拡張用情報識別 ID2 を指定できる -# 1: data or 拡張用情報識別 ID2 +# 1111: Expanded data for overseas +# If it is 0xff, you can specify the extension information identification ID2 next (1:). +# 1: data or Extension information ID2 # 2: : #mfi.track.255.e.254=NonRegisteredMessage -# + 0xff 拡張用情報 +# + 0xff Expansion information mfi.track.255.e.255=vavi.sound.mfi.vavi.track.MachineDependentMessage # -# -------- Class A (ノン・レジスタード・メッセージ) (0x3f) -------- +# -------- Class A (Non-registered message) (0x3f) -------- # -# ---- 拡張ステータス A ---- +# ---- Extended status A ---- # -# vavi.sound.mfi.LongMessage を継承し -# (int,int,int,[B) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.LongMessage +# with (int,int,int,[B) constructor # -# すべて予約 +# All reserved -# ---- 拡張ステータス B ---- +# ---- Extended status B ---- # -# vavi.sound.mfi.ShortMessage を継承し -# (int,int,int,int) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.ShortMessage and has an (int,int,int,int) constructor # -# すべて予約 +# All reserved -# ---- 拡張情報 ---- +# ---- Extended information ---- # -# vavi.sound.mfi.SysexMessage を継承し -# static SysexMessage readFrom(int,int,int,InputStream) メソッドシグネチャを持つもの +# Those that inherit vavi.sound.mfi.SysexMessage and have the +# static SysexMessage readFrom(int,int,int,InputStream) method signature # -# すべて予約 +# All reserved # # -------- Class B (0x7f) -------- # -# ---- 拡張ステータス A ---- +# ---- Extended status A ---- -# + 0x00 オーディオプレイ +# + 0x00 Audio play mfi.track.127.a.0=vavi.sound.mfi.vavi.track.AudioPlayMessage -# + 0x01 オーディオストップ +# + 0x01 Audio Stop mfi.track.127.a.1=vavi.sound.mfi.vavi.track.AudioStopMessage -# ---- 拡張ステータス B ---- +# ---- Extended status B ---- -# + 0x80 オーディオチャネルボリューム +# + 0x80 Audio channel volume mfi.track.127.b.128=vavi.sound.mfi.vavi.track.AudioChannelVolumeMessage -# + 0x81 オーディオチャネルパンポット +# + 0x81 Audio channel pan pot mfi.track.127.b.129=vavi.sound.mfi.vavi.track.AudioChannelPanpotMessage # # 0x9# -# + 0x90 3D 定位機能利用情報 +# + 0x90 3D localization function usage information #mfi.track.127.b.144= -# ---- 拡張情報 ---- +# ---- Extended information ---- -# + 0xf0 3D 定位情報 +# + 0xf0 3D localization information #mfi.track.127.e.240= # # -------- Class C (0xbf) -------- # -# ---- 拡張ステータス A ---- +# ---- Extended status A ---- # -# vavi.sound.mfi.LongMessage を継承し -# (int,int,int,[B) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.LongMessage and has a (int,int,int,[B) constructor # -# すべて予約 +# All reserved -# ---- 拡張ステータス B ---- +# ---- Extended status B ---- # -# vavi.sound.mfi.ShortMessage を継承し -# (int,int,int,int) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.ShortMessage and has a (int,int,int,int) constructor # -# すべて予約 +# All reserved -# ---- 拡張情報 ---- +# ---- Extended information ---- # -# vavi.sound.mfi.SysexMessage を継承し -# static SysexMessage readFrom(int,int,int,InputStream) メソッドシグネチャを持つもの +# Those that inherit vavi.sound.mfi.SysexMessage and have the +# static SysexMessage readFrom(int,int,int,InputStream) method signature # -# すべて予約 +# All reserved #------------------------------------------------------------------------------ # # AudioDataChunk SubChunk # -# vavi.sound.mfi.vavi.SubMessage を継承し -# (String,[B) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.vavi.SubMessage and has a (String,[B) constructor # -# + ADPCM 情報 +# + ADPCM information mfi.audio.adpm=vavi.sound.mfi.vavi.audio.AdpmMessage # # HeaderChunk SubChunk # -# vavi.sound.mfi.vavi.SubMessage を継承し -# (String,[B) コンストラクタを持つもの +# Inherits from vavi.sound.mfi.vavi.SubMessage and has a (String,[B) constructor # -# + 再配布不可識別子 +# + Non-redistributable identifier mfi.header.sorc=vavi.sound.mfi.vavi.header.SorcMessage -# + タイトル情報 +# + Title information mfi.header.titl=vavi.sound.mfi.vavi.header.TitlMessage -# + バージョン情報 +# + Version information mfi.header.vers=vavi.sound.mfi.vavi.header.VersMessage -# + 日付情報 +# + Date information mfi.header.date=vavi.sound.mfi.vavi.header.DateMessage -# + Copyright 情報 +# + Copyright information mfi.header.copy=vavi.sound.mfi.vavi.header.CopyMessage -# + データ管理及び保護情報 +# + Data management and protection information mfi.header.prot=vavi.sound.mfi.vavi.header.ProtMessage -# + ノートメッセージ長情報 +# + Note message length information mfi.header.note=vavi.sound.mfi.vavi.header.NoteMessage -# + 拡張ステータス A メッセージ長情報 +# + Extended status A Message length information mfi.header.exst=vavi.sound.mfi.vavi.header.ExstMessage -# + 著作権管理情報 +# + Copyright management information mfi.header.auth=vavi.sound.mfi.vavi.header.AuthMessage -# + サポート情報 +# + Support information mfi.header.supt=vavi.sound.mfi.vavi.header.SuptMessage -# + オーディオチャンク情報 +# + Audio chunk information mfi.header.ainf=vavi.sound.mfi.vavi.header.AinfMessage -# + 3D 定位機能利用情報 +# + 3D localization function usage information #mfi.header.thrd=vavi.sound.mfi.vavi.header.ThrdMessage # @@ -376,96 +367,96 @@ encoding.read=JISAutoDetect # # -# メタイベント +# Meta event # -# + 0x01 テキスト +# + 0x01 Text midi.meta.1=vavi.sound.mfi.vavi.header.ProtMessage -# + 0x02 著作権表示 +# + 0x02 Copyright notice midi.meta.2=vavi.sound.mfi.vavi.header.CopyMessage -# + 0x03 シーケンス名/トラック名 +# + 0x03 Sequence name/track name midi.meta.3=vavi.sound.mfi.vavi.header.TitlMessage # + 0x2f midi.meta.47=vavi.sound.mfi.vavi.track.EndOfTrackMessage -# + 0x51 セットテンポ +# + 0x51 Set tempo midi.meta.81=vavi.sound.mfi.vavi.track.TempoMessage -# + 0x58 拍子 +# + 0x58 Beat #midi.meta.88= -# + 0x59 調号 +# + 0x59 Key signature #midi.meta.89= -# + 0x7f シーケンサ固有 +# + 0x7f Sequencer specific #midi.meta.127= # -# チャンネルメッセージ +# Channel message # -# + 0x8_ ノートオフ +# + 0x8_ Note off midi.short.128=vavi.sound.mfi.vavi.VaviNoteMessage -# + 0x9_ ノートオン +# + 0x9_ Note on midi.short.144=vavi.sound.mfi.vavi.VaviNoteMessage -# + 0xa_ ポリフォニックキープレッシャー +# + 0xa_ Polyphonic key pressure -# + 0xb_ コントロールチェンジ +# + 0xb_ Control change # -# + 0xb_ 0x00 バンクセレクト MSB +# + 0xb_ 0x00 Bank select MSB midi.short.176.0=vavi.sound.mfi.vavi.track.MfiConvertibleMessage -# + 0xb_ 0x01 モジュレーションデプス MSB +# + 0xb_ 0x01 Modulation depth MSB midi.short.176.1=vavi.sound.mfi.vavi.track.ModulationDepthMessage -# + 0xb_ 0x02 ブレスコントローラー MSB -# + 0xb_ 0x04 フットコントローラー MSB -# + 0xb_ 0x05 ポルタメントタイム MSB +# + 0xb_ 0x02 Breath controller MSB +# + 0xb_ 0x04 Foot controller MSB +# + 0xb_ 0x05 Portamento time MSB #midi.short.176.5= -# + 0xb_ 0x06 データエントリー MSB +# + 0xb_ 0x06 Data entry MSB midi.short.176.6=vavi.sound.mfi.vavi.track.MfiConvertibleMessage -# + 0xb_ 0x07 メインボリューム MSB +# + 0xb_ 0x07 Main volume MSB midi.short.176.7=vavi.sound.mfi.vavi.track.VolumeMessage -# + 0xb_ 0x08 バランスコントロール MSB -# + 0xb_ 0x0a パンポット MSB +# + 0xb_ 0x08 Balance control MSB +# + 0xb_ 0x0a Pan pot MSB midi.short.176.10=vavi.sound.mfi.vavi.track.PanpotMessage -# + 0xb_ 0x0b エクスプレッション MSB +# + 0xb_ 0x0b Expression MSB midi.short.176.11=vavi.sound.mfi.vavi.track.ExpressionMessage -# + 0xb_ 0x20 バンクセレクト LSB +# + 0xb_ 0x20 Bank select LSB midi.short.176.32=vavi.sound.mfi.vavi.track.MfiConvertibleMessage -# + 0xb_ 0x30 汎用汎用操作子-1 -# + 0xb_ 0x31 汎用汎用操作子-2 -# + 0xb_ 0x32 汎用汎用操作子-3 -# + 0xb_ 0x33 汎用汎用操作子-4 -# + 0xb_ 0x40 ホールド1 (ダンパー) -# + 0xb_ 0x41 ポルタメント +# + 0xb_ 0x30 General-purpose controller-1 +# + 0xb_ 0x31 General-purpose controller-2 +# + 0xb_ 0x32 General-purpose controller-3 +# + 0xb_ 0x33 General-purpose controller-4 +# + 0xb_ 0x40 Hold 1 (damper) +# + 0xb_ 0x41 Portamento #midi.short.176.65= -# + 0xb_ 0x42 ソステヌート -# + 0xb_ 0x43 ソフトペダル -# + 0xb_ 0x44 レガートフットスイッチ -# + 0xb_ 0x45 ホールド2 (フリーズ) -# + 0xb_ 0x46 サウンドコントローラー1 (サウンドバリエーション) -# + 0xb_ 0x47 レゾナンス -# + 0xb_ 0x48 リリースタイム -# + 0xb_ 0x49 アタックタイム -# + 0xb_ 0x4a カットオフ -# + 0xb_ 0x4b ディケイタイム -# + 0xb_ 0x4c ビブラートレイト -# + 0xb_ 0x4d ビブラートデプス -# + 0xb_ 0x4e ビブラートディレイ -# + 0xb_ 0x50 汎用汎用操作子-5 -# + 0xb_ 0x51 汎用汎用操作子-6 -# + 0xb_ 0x52 汎用汎用操作子-7 -# + 0xb_ 0x53 汎用汎用操作子-8 -# + 0xb_ 0x54 ポルタメントタイム LSB -# + 0xb_ 0x5b 汎用エフェクト1(リバーブ) +# + 0xb_ 0x42 Sostenuto +# + 0xb_ 0x43 Soft pedal +# + 0xb_ 0x44 Legato foot switch +# + 0xb_ 0x45 Hold 2 (freeze) +# + 0xb_ 0x46 Sound controller 1 (sound variation) +# + 0xb_ 0x47 Resonance +# + 0xb_ 0x48 Release time +# + 0xb_ 0x49 Attack time +# + 0xb_ 0x4a Cut off +# + 0xb_ 0x4b Decay time +# + 0xb_ 0x4c Vibrato trait +# + 0xb_ 0x4d Vibrato depth +# + 0xb_ 0x4e Vibrato delay +# + 0xb_ 0x50 General-purpose controller-5 +# + 0xb_ 0x51 General-purpose controller-6 +# + 0xb_ 0x52 General-purpose controller-7 +# + 0xb_ 0x53 General-purpose controller-8 +# + 0xb_ 0x54 Portamento time LSB +# + 0xb_ 0x5b General-purpose effect 1 (reverb) #midi.short.176.91= -# + 0xb_ 0x5c 汎用エフェクト2(トレモロ) +# + 0xb_ 0x5c General-purpose effect 2 (tremolo) #midi.short.176.92= -# + 0xb_ 0x5d 汎用エフェクト3(コーラス) +# + 0xb_ 0x5d General-purpose effect 3 (chorus) #midi.short.176.93= -# + 0xb_ 0x5e 汎用エフェクト4(セレステ) +# + 0xb_ 0x5e General-purpose effect 4 (celeste) #midi.short.176.94= -# + 0xb_ 0x5f 汎用エフェクト5(フェイザ) +# + 0xb_ 0x5f General-purpose effect 5 (phaser) #midi.short.176.95= -# + 0xb_ 0x60 データインクリメント -# + 0xb_ 0x61 データデクリメント +# + 0xb_ 0x60 Data increment +# + 0xb_ 0x61 Data decrement # + 0xb_ 0x62 NRPN LSB midi.short.176.98=vavi.sound.mfi.vavi.track.MfiConvertibleMessage # + 0xb_ 0x63 NRPN MSB @@ -475,46 +466,46 @@ midi.short.176.100=vavi.sound.mfi.vavi.track.MfiConvertibleMessage # + 0xb_ 0x65 RPN MSB midi.short.176.101=vavi.sound.mfi.vavi.track.MfiConvertibleMessage -# + 0xb_ チャンネルモードメッセージ +# + 0xb_ Channel mode message # -# + 0xb_ 0x78 (120) オールサウンドオフ -# + 0xb_ 0x79 (121) リセットオールコントローラー +# + 0xb_ 0x78 (120) All sound off +# + 0xb_ 0x79 (121) Rest all controller #midi.short.176.121= -# + 0xb_ 0x7a (122) ローカルコントロール -# + 0xb_ 0x7b (123) オールノートオフ -# + 0xb_ 0x7c (124) オムニオフ -# + 0xb_ 0x7d (125) オムニオン -# + 0xb_ 0x7e (126) モノオン +# + 0xb_ 0x7a (122) Local control +# + 0xb_ 0x7b (123) All note off +# + 0xb_ 0x7c (124) Omni off +# + 0xb_ 0x7d (125) Omni on +# + 0xb_ 0x7e (126) Mono on #midi.short.176.126= -# + 0xb_ 0x7f (127) ポリオン +# + 0xb_ 0x7f (127) Poly on #midi.short.176.127= -# + 0xc_ プログラムチェンジ +# + 0xc_ Program change midi.short.192=vavi.sound.mfi.vavi.track.ChangeVoiceMessage -# + 0xd_ チャンネルプレッシャー +# + 0xd_ Channel pressure -# + 0xe_ ピッチベンドチェンジ +# + 0xe_ Pitch bend change midi.short.224=vavi.sound.mfi.vavi.track.PitchBendMessage -# + 0xf0 システムエクスクルーシブメッセージ +# + 0xf0 System exclusive message -# + 0xf_ システムコモンメッセージ +# + 0xf_ System common message # -# + 0xf1 MTC クォーターフレーム -# + 0xf2 ソングポジションポインタ -# + 0xf3 ソングセレクト -# + 0xf6 チューンリクエスト -# + 0xf7 エンドオブエクスクルーシブ (EOX) +# + 0xf1 MTC Quarter frame +# + 0xf2 Song position pointer +# + 0xf3 Song selection +# + 0xf6 Tune request +# + 0xf7 End of exclusive (EOX) -# + 0xf_ システムリアルタイムメッセージ +# + 0xf_ System real-time messages # -# + 0xf8 タイミングクロック -# + 0xfa スタート -# + 0xfb コンティニュー -# + 0xfc ストップ -# + 0xfe アクティブセンシング -# + 0xff システムリセット +# + 0xf8 Timing clock +# + 0xfa Start +# + 0xfb Continue +# + 0xfc Stop +# + 0xfe Active sensing +# + 0xff System reset #------------------------------------------------------------------------------ diff --git a/src/main/resources/vavi/sound/sampled/FilterChain.properties b/src/main/resources/vavi/sound/sampled/FilterChain.properties index 1a01829..6ca31d0 100644 --- a/src/main/resources/vavi/sound/sampled/FilterChain.properties +++ b/src/main/resources/vavi/sound/sampled/FilterChain.properties @@ -10,7 +10,7 @@ # ## -# 機種依存部作成クラス +# Model dependent part creation class # #inputFilter.0=vavi.sound.sampled.SimpleResamplingInputFilter #inputFilter.1=vavi.sound.sampled.MonauralInputFilter diff --git a/src/main/resources/vavi/sound/sampled/mfi/MfiWithVoiceMaker.properties b/src/main/resources/vavi/sound/sampled/mfi/MfiWithVoiceMaker.properties index 84d7a01..6de7c76 100644 --- a/src/main/resources/vavi/sound/sampled/mfi/MfiWithVoiceMaker.properties +++ b/src/main/resources/vavi/sound/sampled/mfi/MfiWithVoiceMaker.properties @@ -10,7 +10,7 @@ # ## -# 機種依存部作成クラス +# Model dependent part creation class # #class.d505=vavi.sound.sampled.mfi.type.d505 #class.n505=vavi.sound.sampled.mfi.type.n505 @@ -20,7 +20,7 @@ class.sh252=vavi.sound.sampled.mfi.type.sh252 class.sh900=vavi.sound.sampled.mfi.type.sh900 ## -# 作成者情報 +# Author information # prot=vavi @@ -37,6 +37,6 @@ vers=0300 ## # # -defaultModle=sh900 +defaultModel=sh900 ## diff --git a/src/main/resources/vavi/sound/sampled/smaf/SmafWithVoiceMaker.properties b/src/main/resources/vavi/sound/sampled/smaf/SmafWithVoiceMaker.properties index 059f077..b7fd542 100644 --- a/src/main/resources/vavi/sound/sampled/smaf/SmafWithVoiceMaker.properties +++ b/src/main/resources/vavi/sound/sampled/smaf/SmafWithVoiceMaker.properties @@ -10,7 +10,7 @@ # ## -# コンテンツの情報 (',', '\' は '\' でエスケープすること) +# Content information (',', '\' must be escaped with '\') # contentsInfo.subDatum.vn=vavi contentsInfo.subDatum.cr=(c) 2008 Vavisoft Inc. diff --git a/src/main/resources/vavi/sound/smaf/chunk/language.properties b/src/main/resources/vavi/sound/smaf/chunk/language.properties index 04644de..2c8f2ce 100644 --- a/src/main/resources/vavi/sound/smaf/chunk/language.properties +++ b/src/main/resources/vavi/sound/smaf/chunk/language.properties @@ -6,22 +6,22 @@ # 0.00 050506 nsano initial version # -# 日本語 +# Japanese 0x00=Shift-JIS -# 英語、フランス語、ドイツ イタリア語、スペイン語、ポルトガル語 +# English, French, German Italian, Spanish, Portuguese 0x01=ISO 8859-1(Latin-1) -# 韓国語 +# Korean 0x02=EUC-KR(KS) -# 中国語(簡体字) +# Simplified Chinese 0x03=HZ-GB-2312 -# 中国語(繁体字) +# Traditional Chinese 0x04=Big5 -# ロシア語など +# Russian etc. 0x05=KOI8-R -# ベトナム語 +# Vietnamese 0x06=TCVN-5773:1993 # Reserved -# 0x07〜0x1F Reserved +# 0x07\u301C0x1F Reserved 0x20=UCS-2 Unicode 0x21=UCS-4 Unicode 0x22=UTF-7 Unicode @@ -29,6 +29,6 @@ 0x24=UTF-16 Unicode 0x25=UTF-32 Unicode # Reserved -# 0x26〜0xFE Reserved -# Binary 値 +# 0x26\u301C0xFE Reserved +# Binary value 0xFF=Octet Stream \ No newline at end of file diff --git a/src/main/resources/vavi/sound/smaf/smaf.properties b/src/main/resources/vavi/sound/smaf/smaf.properties index 582a8f3..a3b6858 100644 --- a/src/main/resources/vavi/sound/smaf/smaf.properties +++ b/src/main/resources/vavi/sound/smaf/smaf.properties @@ -12,10 +12,10 @@ #------------------------------------------------------------------------------ ## -# Chunk の ID に対応するクラスです。 +# This class corresponds to the Chunk ID. # -# @name "chunk." + ChunkID、'*' はワイルドカードになります -# @value クラス名、Chunk を継承しシグネチャが (byte[],int) のコンストラクタを持つもの +# @name "chunk." + ChunkID\u3001'*' is a wildcard +# @value class name, Classes that inherits from Chunk and has a constructor with the signature (byte[],int) # @see vavi.sound.smaf.Chunk # chunk.MMMD=vavi.sound.smaf.chunk.FileChunk @@ -60,9 +60,9 @@ maker.43=vavi.sound.smaf.message.yamaha.YamahaMessage #------------------------------------------------------------------------------ ## -# フォーマットタイプに対応する AudioEngine +# AudioEngine corresponding to the format type # -# @name "audioEngine.format" + フォーマットタイプ +# @name "audioEngine.format" + format type # @see vavi.sound.smaf.chunk.WaveType # # WAVE Format 0 PCM Signed From 9d2c6979ebd0e4886e33efcf407376118e228494 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sat, 22 Jun 2024 05:39:48 +0900 Subject: [PATCH 5/8] follow ide advice use jpl instead of jul clean up --- .../vavi/sound/adpcm/AdpcmInputStream.java | 28 +- .../vavi/sound/adpcm/AdpcmOutputStream.java | 10 +- .../java/vavi/sound/adpcm/ccitt/G711.java | 16 +- .../java/vavi/sound/adpcm/ccitt/G721.java | 22 +- .../java/vavi/sound/adpcm/ccitt/G723_16.java | 2 +- .../sound/adpcm/ccitt/G723_16InputStream.java | 4 +- .../java/vavi/sound/adpcm/ccitt/G723_24.java | 8 +- .../java/vavi/sound/adpcm/ccitt/State.java | 34 +-- src/main/java/vavi/sound/adpcm/dvi/Dvi.java | 4 +- src/main/java/vavi/sound/adpcm/ima/Ima.java | 49 +-- .../vavi/sound/adpcm/ima/ImaInputEngine.java | 19 +- .../vavi/sound/adpcm/ima/ImaInputStream.java | 9 +- .../vavi/sound/adpcm/ima/ImaOutputEngine.java | 12 +- src/main/java/vavi/sound/adpcm/ms/Ms.java | 79 ++--- .../vavi/sound/adpcm/ms/MsInputEngine.java | 31 +- .../vavi/sound/adpcm/ms/MsInputStream.java | 14 +- .../vavi/sound/adpcm/ms/MsOutputEngine.java | 16 +- .../vavi/sound/adpcm/oki/OkiInputStream.java | 10 +- src/main/java/vavi/sound/adpcm/vox/Vox.java | 6 +- .../vavi/sound/adpcm/vox/VoxInputStream.java | 8 +- .../vavi/sound/adpcm/vox/VoxOutputStream.java | 2 +- .../java/vavi/sound/adpcm/yamaha/Yamaha.java | 6 +- .../java/vavi/sound/adpcm/ym2608/Ym2608.java | 16 +- src/main/java/vavi/sound/mfi/MfiDevice.java | 8 +- src/main/java/vavi/sound/mfi/MfiEvent.java | 2 +- .../java/vavi/sound/mfi/MfiFileFormat.java | 2 +- src/main/java/vavi/sound/mfi/MfiSystem.java | 37 +-- src/main/java/vavi/sound/mfi/NoteMessage.java | 23 +- src/main/java/vavi/sound/mfi/Sequence.java | 2 +- src/main/java/vavi/sound/mfi/Track.java | 2 +- .../vavi/sound/mfi/vavi/AudioDataMessage.java | 29 +- .../java/vavi/sound/mfi/vavi/HeaderChunk.java | 45 +-- .../vavi/sound/mfi/vavi/MetaEventAdapter.java | 42 +-- .../java/vavi/sound/mfi/vavi/MetaSupport.java | 2 +- .../java/vavi/sound/mfi/vavi/MfiContext.java | 41 +-- .../java/vavi/sound/mfi/vavi/MidiContext.java | 44 +-- .../java/vavi/sound/mfi/vavi/SubMessage.java | 26 +- .../vavi/sound/mfi/vavi/TrackMessage.java | 76 ++--- .../sound/mfi/vavi/VaviMfiDeviceProvider.java | 15 +- .../sound/mfi/vavi/VaviMfiFileFormat.java | 26 +- .../sound/mfi/vavi/VaviMfiFileWriter.java | 26 +- .../sound/mfi/vavi/VaviMidiConverter.java | 81 ++--- .../vavi/sound/mfi/vavi/VaviNoteMessage.java | 35 ++- .../vavi/sound/mfi/vavi/VaviSequencer.java | 41 +-- .../mfi/vavi/audio/CommonAudioMessage.java | 28 +- .../mfi/vavi/audio/FuetrekAudioMessage.java | 16 +- .../mfi/vavi/audio/RohmAudioMessage.java | 10 +- .../mfi/vavi/audio/YamahaAudioMessage.java | 10 +- .../sound/mfi/vavi/header/AinfMessage.java | 8 +- .../sound/mfi/vavi/header/NoteMessage.java | 2 +- .../sound/mfi/vavi/mitsubishi/Function1.java | 10 +- .../mfi/vavi/mitsubishi/Function129.java | 10 +- .../mfi/vavi/mitsubishi/Function130.java | 10 +- .../mfi/vavi/mitsubishi/Function131.java | 54 ++-- .../mfi/vavi/mitsubishi/Function132.java | 14 +- .../mfi/vavi/mitsubishi/Function143.java | 16 +- .../sound/mfi/vavi/mitsubishi/Function16.java | 5 +- .../sound/mfi/vavi/mitsubishi/Function17.java | 5 +- .../sound/mfi/vavi/mitsubishi/Function2.java | 5 +- .../sound/mfi/vavi/mitsubishi/Function3.java | 5 +- .../vavi/mitsubishi/MitsubishiMessage.java | 20 +- .../vavi/mitsubishi/MitsubishiSequencer.java | 16 +- .../sound/mfi/vavi/nec/Function1_240_7.java | 7 +- .../sound/mfi/vavi/nec/Function1_241_3.java | 5 +- .../sound/mfi/vavi/nec/Function1_241_4.java | 5 +- .../sound/mfi/vavi/nec/Function1_241_5.java | 5 +- .../sound/mfi/vavi/nec/Function1_241_6.java | 5 +- .../sound/mfi/vavi/nec/Function1_243_3.java | 5 +- .../sound/mfi/vavi/nec/Function1_243_4.java | 5 +- .../sound/mfi/vavi/nec/Function240_1.java | 7 +- .../sound/mfi/vavi/nec/Function240_2.java | 9 +- .../sound/mfi/vavi/nec/Function241_0.java | 5 +- .../sound/mfi/vavi/nec/Function241_1.java | 7 +- .../sound/mfi/vavi/nec/Function241_2.java | 7 +- .../sound/mfi/vavi/nec/Function242_1.java | 5 +- .../sound/mfi/vavi/nec/Function242_4.java | 7 +- .../sound/mfi/vavi/nec/Function242_5.java | 7 +- .../vavi/sound/mfi/vavi/nec/NecMessage.java | 44 +-- .../vavi/sound/mfi/vavi/nec/NecSequencer.java | 18 +- .../vavi/sequencer/AudioDataSequencer.java | 4 +- .../sequencer/MachineDependentFunction.java | 12 +- .../mfi/vavi/sequencer/MfiMessageStore.java | 2 +- .../mfi/vavi/sequencer/UndefinedFunction.java | 12 +- .../sound/mfi/vavi/sharp/Function129.java | 5 +- .../sound/mfi/vavi/sharp/Function130.java | 5 +- .../sound/mfi/vavi/sharp/Function131.java | 49 ++- .../sound/mfi/vavi/sharp/Function132.java | 9 +- .../sound/mfi/vavi/sharp/Function143.java | 11 +- .../sound/mfi/vavi/sharp/SharpMessage.java | 18 +- .../sound/mfi/vavi/sharp/SharpSequencer.java | 16 +- .../mfi/vavi/track/AudioPlayMessage.java | 2 +- .../mfi/vavi/track/AudioStopMessage.java | 2 +- .../mfi/vavi/track/ChangeBankMessage.java | 4 +- .../mfi/vavi/track/ChangeVoiceMessage.java | 4 +- .../mfi/vavi/track/ChannelChangeMessage.java | 13 +- .../track/ChannelConfigurationMessage.java | 15 +- .../sound/mfi/vavi/track/CuePointMessage.java | 4 +- .../mfi/vavi/track/EndOfTrackMessage.java | 2 +- .../mfi/vavi/track/ExpressionMessage.java | 2 +- .../mfi/vavi/track/ExtendedEditMessage.java | 12 +- .../mfi/vavi/track/LoopPointMessage.java | 15 +- .../vavi/track/MachineDependentMessage.java | 17 +- .../mfi/vavi/track/MfiConvertibleMessage.java | 18 +- .../sound/mfi/vavi/track/Nop2Message.java | 14 +- .../vavi/sound/mfi/vavi/track/NopMessage.java | 6 +- .../mfi/vavi/track/PitchBendMessage.java | 2 +- .../mfi/vavi/track/PitchBendRangeMessage.java | 4 +- .../sound/mfi/vavi/track/TempoMessage.java | 33 +- .../mfi/vavi/track/UndefinedMessage.java | 9 +- .../sound/mfi/vavi/track/VolumeMessage.java | 4 +- .../vavi/sound/midi/BasicMidiFileReader.java | 14 +- .../java/vavi/sound/midi/MidiConstants.java | 15 +- src/main/java/vavi/sound/midi/MidiUtil.java | 57 ++-- .../sound/midi/VaviMidiDeviceProvider.java | 12 +- .../java/vavi/sound/midi/VaviSequencer.java | 24 +- .../sound/midi/mfi/MfiMidiFileReader.java | 18 +- .../sound/midi/mfi/MfiMidiFileWriter.java | 27 +- .../sound/midi/smaf/SmafMidiFileReader.java | 19 +- .../sound/midi/smaf/SmafMidiFileWriter.java | 17 +- .../vavi/sound/mobile/BasicAudioEngine.java | 40 +-- .../vavi/sound/mobile/FuetrekAudioEngine.java | 10 +- .../vavi/sound/mobile/PcmAudioEngine.java | 22 +- .../vavi/sound/mobile/YamahaAudioEngine.java | 11 +- .../vavi/sound/pcm/resampling/ssrc/SSRC.java | 287 ++++++++---------- .../pcm/resampling/ssrc/SSRCInputStream.java | 10 +- .../sound/sampled/MonauralInputFilter.java | 12 +- .../sampled/Pcm16BitMonauralWaveDivider.java | 25 +- .../sampled/SimpleResamplingInputFilter.java | 16 +- .../sampled/TemporaryFiledInputFilter.java | 10 +- .../java/vavi/sound/sampled/WaveDivider.java | 22 +- .../adpcm/AdpcmWaveAudioFileReader.java | 31 +- .../sampled/mfi/DividedMfiWithVoiceMaker.java | 22 +- src/main/java/vavi/sound/sampled/mfi/MFi.java | 2 +- .../sound/sampled/mfi/MfiAudioFileWriter.java | 12 +- .../sound/sampled/mfi/MfiWithVoiceMaker.java | 18 +- .../smaf/DividedSmafWithVoiceMaker.java | 24 +- .../java/vavi/sound/sampled/smaf/SMAF.java | 2 +- .../sampled/smaf/SmafWithVoiceMaker.java | 54 ++-- .../vavi/sound/smaf/MetaEventAdapter.java | 39 +-- .../java/vavi/sound/smaf/MetaSupport.java | 2 +- src/main/java/vavi/sound/smaf/Sequence.java | 2 +- src/main/java/vavi/sound/smaf/SmafDevice.java | 8 +- .../vavi/sound/smaf/SmafDeviceProvider.java | 16 +- src/main/java/vavi/sound/smaf/SmafEvent.java | 4 +- .../java/vavi/sound/smaf/SmafFileWriter.java | 13 +- .../vavi/sound/smaf/SmafMidiConverter.java | 33 +- .../java/vavi/sound/smaf/SmafSequence.java | 14 +- .../java/vavi/sound/smaf/SmafSequencer.java | 51 ++-- src/main/java/vavi/sound/smaf/SmafSystem.java | 21 +- .../java/vavi/sound/smaf/SysexMessage.java | 23 +- src/main/java/vavi/sound/smaf/Track.java | 2 +- .../smaf/chunk/AudioSequenceDataChunk.java | 14 +- .../vavi/sound/smaf/chunk/BitmapChunk.java | 12 +- .../vavi/sound/smaf/chunk/ChannelStatus.java | 6 +- .../java/vavi/sound/smaf/chunk/Chunk.java | 47 +-- .../chunk/ColorPaletteDefinitionChunk.java | 2 +- .../sound/smaf/chunk/ContentsInfoChunk.java | 28 +- .../java/vavi/sound/smaf/chunk/DataChunk.java | 22 +- .../DisplayParameterDefinitionChunk.java | 18 +- .../java/vavi/sound/smaf/chunk/FileChunk.java | 26 +- .../smaf/chunk/GraphicsSetupDataChunk.java | 12 +- .../sound/smaf/chunk/GraphicsTrackChunk.java | 14 +- .../chunk/GraphicsTrackSequenceDataChunk.java | 20 +- .../chunk/HuffmanDecodingInputStream.java | 25 +- .../vavi/sound/smaf/chunk/ImageChunk.java | 13 +- .../vavi/sound/smaf/chunk/ImageDataChunk.java | 18 +- .../java/vavi/sound/smaf/chunk/LinkChunk.java | 12 +- .../sound/smaf/chunk/MasterTrackChunk.java | 18 +- .../chunk/MasterTrackSequenceDataChunk.java | 10 +- .../sound/smaf/chunk/OptionalDataChunk.java | 12 +- .../sound/smaf/chunk/PcmAudioTrackChunk.java | 24 +- .../sound/smaf/chunk/ScoreTrackChunk.java | 34 ++- .../smaf/chunk/SeekAndPhraseInfoChunk.java | 20 +- .../sound/smaf/chunk/SequenceDataChunk.java | 57 ++-- .../vavi/sound/smaf/chunk/SetupDataChunk.java | 20 +- .../sound/smaf/chunk/StreamPcmDataChunk.java | 14 +- .../sound/smaf/chunk/StreamWaveDataChunk.java | 10 +- .../java/vavi/sound/smaf/chunk/SubData.java | 4 +- .../vavi/sound/smaf/chunk/TrackChunk.java | 2 +- .../vavi/sound/smaf/chunk/UndefinedChunk.java | 14 +- .../vavi/sound/smaf/chunk/WaveDataChunk.java | 10 +- .../java/vavi/sound/smaf/chunk/WaveType.java | 49 ++- .../sound/smaf/message/BankSelectMessage.java | 14 +- .../smaf/message/EndOfSequenceMessage.java | 11 +- .../sound/smaf/message/ExpressionMessage.java | 2 +- .../vavi/sound/smaf/message/MidiContext.java | 104 +++---- .../smaf/message/MidiConvertibleMessage.java | 8 +- .../vavi/sound/smaf/message/NoteMessage.java | 50 +-- .../smaf/message/OctaveShiftMessage.java | 2 +- .../sound/smaf/message/PitchBendMessage.java | 2 +- .../smaf/message/ProgramChangeMessage.java | 2 +- .../vavi/sound/smaf/message/STMessage.java | 10 +- .../vavi/sound/smaf/message/SmafContext.java | 43 +-- .../vavi/sound/smaf/message/TrackMessage.java | 14 +- .../sound/smaf/message/UndefinedMessage.java | 2 +- .../vavi/sound/smaf/message/VNMessage.java | 10 +- .../sound/smaf/message/VolumeMessage.java | 13 +- .../sound/smaf/message/WaveDataMessage.java | 27 +- .../vavi/sound/smaf/message/WaveMessage.java | 17 +- .../BackDropColorDefinitionMessage.java | 2 +- .../smaf/message/graphics/UserMessage.java | 2 +- .../smaf/message/yamaha/YamahaMessage.java | 16 +- .../smaf/sequencer/SmafMessageStore.java | 2 +- .../sound/smaf/sequencer/WaveSequencer.java | 4 +- src/test/java/PlayMFi.java | 3 - src/test/java/SoundFontTest.java | 1 - .../sound/adpcm/ms/MsInputStreamTest.java | 1 - .../sound/mfi/vavi/VaviMfiFileWriterTest.java | 8 +- .../MachineDependentSequencerTest.java | 13 +- .../sound/mobile/BasicAudioEngineTest.java | 4 +- .../sound/pcm/resampling/ssrc/SSRCTest.java | 3 +- .../sound/pcm/resampling/ssrc/fftsgTest.java | 2 +- .../adpcm/ima/ImaWaveAudioFileReaderTest.java | 1 - 213 files changed, 2033 insertions(+), 1740 deletions(-) diff --git a/src/main/java/vavi/sound/adpcm/AdpcmInputStream.java b/src/main/java/vavi/sound/adpcm/AdpcmInputStream.java index d1920b4..ff6254d 100644 --- a/src/main/java/vavi/sound/adpcm/AdpcmInputStream.java +++ b/src/main/java/vavi/sound/adpcm/AdpcmInputStream.java @@ -9,13 +9,15 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; - import javax.sound.sampled.AudioFormat; import vavi.io.BitInputStream; import vavi.io.BitOutputStream; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,14 +32,16 @@ */ public abstract class AdpcmInputStream extends FilterInputStream { + private static final Logger logger = getLogger(AdpcmInputStream.class.getName()); + /** PCM format that #read() returns */ - protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; + protected final AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; /** PCM byte order that #read() returns */ - protected ByteOrder byteOrder; + protected final ByteOrder byteOrder; /** decoder */ - protected Codec decoder; + protected final Codec decoder; /** */ protected abstract Codec getCodec(); @@ -52,13 +56,13 @@ public AdpcmInputStream(InputStream in, ByteOrder byteOrder, int bits, ByteOrder super(new BitInputStream(in, bits, bitOrder)); this.byteOrder = byteOrder; this.decoder = getCodec(); -//Debug.println(this.in); +//logger.log(Level.DEBUG, this.in); } /** ADPCM (4bit) length */ @Override public int available() throws IOException { -//Debug.println("0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); +//logger.log(Level.DEBUG, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); // TODO "* 2" calc should be in bits? return (in.available() * 2) + (rest ? 1 : 0); } @@ -73,10 +77,10 @@ public int available() throws IOException { */ @Override public int read() throws IOException { -//Debug.println(in); +//logger.log(Level.DEBUG, in); if (!rest) { int adpcm = in.read(); -//System.err.println("0: " + StringUtil.toHex2(adpcm)); +//logger.log(Level.DEBUG, "0: " + StringUtil.toHex2(adpcm)); if (adpcm == -1) { return -1; } @@ -84,7 +88,7 @@ public int read() throws IOException { current = decoder.decode(adpcm); rest = true; -//System.err.println("1: " + StringUtil.toHex2(current & 0xff)); +//logger.log(Level.DEBUG, "1: " + StringUtil.toHex2(current & 0xff)); if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) { return (current & 0xff00) >> 8; } else { @@ -92,7 +96,7 @@ public int read() throws IOException { } } else { rest = false; -//System.err.println("2: " + StringUtil.toHex2((current & 0xff00) >> 8)); +//logger.log(Level.DEBUG, "2: " + StringUtil.toHex2((current & 0xff00) >> 8)); if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) { return current & 0xff; } else { @@ -130,7 +134,7 @@ public int read(byte[] b, int off, int len) throws IOException { } } } catch (IOException e) { - Debug.printStackTrace(e); + logger.log(Level.ERROR, e.getMessage(), e); } return i; } diff --git a/src/main/java/vavi/sound/adpcm/AdpcmOutputStream.java b/src/main/java/vavi/sound/adpcm/AdpcmOutputStream.java index 08c7425..45e39bd 100644 --- a/src/main/java/vavi/sound/adpcm/AdpcmOutputStream.java +++ b/src/main/java/vavi/sound/adpcm/AdpcmOutputStream.java @@ -26,13 +26,13 @@ public abstract class AdpcmOutputStream extends FilterOutputStream { /** PCM format for #write(int) */ - protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; + protected final AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; /** PCM byte order for #write(int) */ - protected ByteOrder byteOrder; + protected final ByteOrder byteOrder; /** encoder */ - protected Codec encoder; + protected final Codec encoder; /** */ protected abstract Codec getCodec(); @@ -48,7 +48,7 @@ public AdpcmOutputStream(OutputStream out, ByteOrder byteOrder, int bits, ByteOr super(new BitOutputStream(out, bits, bitOrder)); this.byteOrder = byteOrder; this.encoder = getCodec(); -//Debug.println(this.out); +//logger.log(Level.DEBUG, this.out); } /** remaining or not (having PCM L or H at least one side) */ @@ -74,7 +74,7 @@ public void write(int b) throws IOException { current -= 0x10000; } } -//System.err.println("current: " + StringUtil.toHex4(current)); +//logger.log(Level.DEBUG, "current: " + StringUtil.toHex4(current)); out.write(encoder.encode(current)); // BitOutputStream write 4bit flushed = true; diff --git a/src/main/java/vavi/sound/adpcm/ccitt/G711.java b/src/main/java/vavi/sound/adpcm/ccitt/G711.java index 6a18727..08e4300 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/G711.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/G711.java @@ -47,7 +47,7 @@ abstract class G711 implements Codec { /** */ - protected State state = new State(); + protected final State state = new State(); /** */ protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; @@ -346,7 +346,7 @@ protected int reconstruct(boolean sign, int dqln, int y) { int dql = dqln + (y >> 2); // ADDA if (dql < 0) { -// System.err.println("1: " + (sign ? -0x8000 : 0)); +// logger.log(Level.DEBUG, "1: " + (sign ? -0x8000 : 0)); return sign ? -0x8000 : 0; } else { // ANTILOG // Integer part of log @@ -354,8 +354,8 @@ protected int reconstruct(boolean sign, int dqln, int y) { int dqt = 128 + (dql & 127); // Reconstructed difference signal sample int dq = (dqt << 7) >> (14 - dex); -// System.err.println("2: " + sign + ", " + dqln + ", " + y); -// System.err.println("-: " + (sign ? dq - 0x8000 : dq) + ", " + (dq - 0x8000) + ", " + dq); +// logger.log(Level.DEBUG, "2: " + sign + ", " + dqln + ", " + y); +// logger.log(Level.DEBUG, "-: " + (sign ? dq - 0x8000 : dq) + ", " + (dq - 0x8000) + ", " + dq); return sign ? dq - 0x8000 : dq; } } @@ -380,11 +380,11 @@ protected int quantize(int d, int y, int[] table, int size) { // // Magnitude of 'd' int dqm = Math.abs(d); -// System.err.println("d:\t" + d); -// System.err.println("dqm:\t" + dqm); +// logger.log(Level.DEBUG, "d:\t" + d); +// logger.log(Level.DEBUG, "dqm:\t" + dqm); // Integer part of base 2 log of 'd' int exp = State.quan(dqm >> 1); -// System.err.println("exp:\t" + exp); +// logger.log(Level.DEBUG, "exp:\t" + exp); // Fractional part of base 2 log int mant = ((dqm << 7) >> exp) & 0x7f; // Fractional portion. // Log of magnitude of 'd' @@ -509,7 +509,7 @@ protected int adjustUlawTandem(int sr, int se, int y, int i, int sign, int[] qta } } - //------------------------------------------------------------------------- + // ---- /** */ public abstract int getEncodingBits(); diff --git a/src/main/java/vavi/sound/adpcm/ccitt/G721.java b/src/main/java/vavi/sound/adpcm/ccitt/G721.java index 6aefb06..b07e16a 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/G721.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/G721.java @@ -95,11 +95,11 @@ public int encode(int sl) { } else if (AudioFormat.Encoding.ULAW.equals(encoding)) { sl = ulaw2linear(sl) >> 2; } else if (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) { -//System.err.println("---- " + ccc + " ----"); +//logger.log(Level.DEBUG, "---- " + ccc + " ----"); //ccc++; -//System.err.println("sl:B:\t" + sl); +//logger.log(Level.DEBUG, "sl:B:\t" + sl); sl >>= 2; // 14-bit dynamic range -//System.err.println("sl:A:\t" + sl); +//logger.log(Level.DEBUG, "sl:A:\t" + sl); } else { throw new IllegalArgumentException(encoding.toString()); } @@ -109,8 +109,8 @@ public int encode(int sl) { int sez = sezi >> 1; int se = (sezi + state.getPolePredictor()) >> 1; // estimated signal -//System.err.println("sl:\t" + sl); -//System.err.println("se:\t" + se); +//logger.log(Level.DEBUG, "sl:\t" + sl); +//logger.log(Level.DEBUG, "se:\t" + se); // SUBTA int d = sl - se; // estimation difference @@ -153,12 +153,12 @@ public int decode(int i) { int sei = sezi + state.getPolePredictor(); int se = sei >> 1; // se = estimated signal -//System.err.println("---- (" + (ccc++) + ")"); -//System.err.println("i:\t" + StringUtil.toHex2(i)); -//System.err.println("sezi:\t" + sezi); -//System.err.println("sez:\t" + sez); -//System.err.println("sei:\t" + sei); -//System.err.println("se:\t" + se); +//logger.log(Level.DEBUG, "---- (" + (ccc++) + ")"); +//logger.log(Level.DEBUG, "i:\t" + StringUtil.toHex2(i)); +//logger.log(Level.DEBUG, "sezi:\t" + sezi); +//logger.log(Level.DEBUG, "sez:\t" + sez); +//logger.log(Level.DEBUG, "sei:\t" + sei); +//logger.log(Level.DEBUG, "se:\t" + se); // MIX int y = state.getStepSize(); // dynamic quantizer step size diff --git a/src/main/java/vavi/sound/adpcm/ccitt/G723_16.java b/src/main/java/vavi/sound/adpcm/ccitt/G723_16.java index a33fa80..ccd3749 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/G723_16.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/G723_16.java @@ -72,7 +72,7 @@ class G723_16 extends G711 { /** * Comes from quantizer decision level tables (Table 7/G.726) */ - private static int[] qtab_723_16 = { 261 }; + private static final int[] qtab_723_16 = { 261 }; /** * Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit diff --git a/src/main/java/vavi/sound/adpcm/ccitt/G723_16InputStream.java b/src/main/java/vavi/sound/adpcm/ccitt/G723_16InputStream.java index 20ec08c..d3be8c2 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/G723_16InputStream.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/G723_16InputStream.java @@ -35,13 +35,13 @@ protected Codec getCodec() { public G723_16InputStream(InputStream in, ByteOrder byteOrder) { super(in, byteOrder, 2, ByteOrder.LITTLE_ENDIAN); ((G723_16) decoder).setEncoding(encoding); -//Debug.println(this.in); +//logger.log(Level.DEBUG, this.in); } /** ADPCM (4bit) length */ @Override public int available() throws IOException { -//Debug.println("0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); +//logger.log(Level.DEBUG, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); return (in.available() * 4) + (rest ? 1 : 0); // TODO check * 4 ??? } } diff --git a/src/main/java/vavi/sound/adpcm/ccitt/G723_24.java b/src/main/java/vavi/sound/adpcm/ccitt/G723_24.java index 148d684..9c5b61c 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/G723_24.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/G723_24.java @@ -45,12 +45,12 @@ class G723_24 extends G711 { * Maps G.723_24 code word to reconstructed scale factor normalized log * magnitude values. */ - private static int[] _dqlntab = { + private static final int[] _dqlntab = { -2048, 135, 273, 373, 373, 273, 135, -2048 }; /** Maps G.723_24 code word to log of scale factor multiplier. */ - private static int[] _witab = { + private static final int[] _witab = { -128, 960, 4384, 18624, 18624, 4384, 960, -128 }; @@ -59,12 +59,12 @@ class G723_24 extends G711 { * term averages are computed and then compared to give an indication * how stationary (steady state) the signal is. */ - private static int[] _fitab = { + private static final int[] _fitab = { 0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0 }; /** */ - private static int[] qtab_723_24 = { 8, 218, 331 }; + private static final int[] qtab_723_24 = { 8, 218, 331 }; /** * Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit diff --git a/src/main/java/vavi/sound/adpcm/ccitt/State.java b/src/main/java/vavi/sound/adpcm/ccitt/State.java index c0928c4..c35450f 100644 --- a/src/main/java/vavi/sound/adpcm/ccitt/State.java +++ b/src/main/java/vavi/sound/adpcm/ccitt/State.java @@ -81,26 +81,26 @@ class State { private int ap; /** Coefficients of pole portion of prediction filter. */ - private int[] a = new int[2]; + private final int[] a = new int[2]; /** Coefficients of zero portion of prediction filter. */ - private int[] b = new int[6]; + private final int[] b = new int[6]; /** * Signs of previous two samples of a partially * reconstructed signal. */ - private int[] pk = new int[2]; + private final int[] pk = new int[2]; /** * Previous 6 samples of the quantized difference * signal represented in an internal floating point * format. */ - private int[] dq = new int[6]; + private final int[] dq = new int[6]; /** * Previous 2 samples of the quantized difference * signal represented in an internal floating point * format. */ - private int[] sr = new int[2]; + private final int[] sr = new int[2]; /** delayed tone detect, new in 1988 version */ private int td; @@ -147,7 +147,7 @@ private static int fmult(int an, int srn) { int retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7fff) : (wanmant >> -wanexp); -// System.err.println(an + ", " + srn + ": " + ((an ^ srn) < 0 ? -retval : retval)); +//logger.log(Level.DEBUG, an + ", " + srn + ": " + ((an ^ srn) < 0 ? -retval : retval)); return (an ^ srn) < 0 ? -retval : retval; } @@ -208,10 +208,10 @@ public int getStepSize() { */ public void update(int code_size, int y, int wi, int fi, int _dq, int _sr, int dqsez) { -//System.err.println("y:\t" + y); -//System.err.println("dq:\t" + _dq); -//System.err.println("sr:\t" + _sr); -//System.err.println("dqsez:\t" + dqsez); +//logger.log(Level.DEBUG, "y:\t" + y); +//logger.log(Level.DEBUG, "dq:\t" + _dq); +//logger.log(Level.DEBUG, "sr:\t" + _sr); +//logger.log(Level.DEBUG, "dqsez:\t" + dqsez); // needed in updating predictor poles int pk0 = (dqsez < 0) ? 1 : 0; @@ -346,33 +346,33 @@ public void update(int code_size, int y, int wi, int fi, int _dq, int _sr, int d // FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. if (mag == 0) { dq[0] = (_dq >= 0) ? 0x20 : -992; -//System.err.println("dq[0]:1: " + dq[0]); +//logger.log(Level.DEBUG, "dq[0]:1: " + dq[0]); } else { exp = quan(mag); dq[0] = (_dq >= 0) ? (exp << 6) + ((mag << 6) >> exp) : (exp << 6) + ((mag << 6) >> exp) - 0x400; -//System.err.println("dq[0]:2: " + dq[0] + ", " + _dq + ", " + exp + ", " + mag); -//System.err.println("dq[0]:-: " + (exp << 6) + ", " + ((mag << 6) >> exp)); +//logger.log(Level.DEBUG, "dq[0]:2: " + dq[0] + ", " + _dq + ", " + exp + ", " + mag); +//logger.log(Level.DEBUG, "dq[0]:-: " + (exp << 6) + ", " + ((mag << 6) >> exp)); } sr[1] = sr[0]; // FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. if (_sr == 0) { sr[0] = 0x20; -//System.err.println("sr[0]:1: " + sr[0]); +//logger.log(Level.DEBUG, "sr[0]:1: " + sr[0]); } else if (_sr > 0) { exp = quan(_sr); sr[0] = (exp << 6) + ((_sr << 6) >> exp); -//System.err.println("sr[0]:2: " + sr[0]); +//logger.log(Level.DEBUG, "sr[0]:2: " + sr[0]); } else if (_sr > -32768) { mag = -_sr; exp = quan(mag); sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; -//System.err.println("sr[0]:3: " + sr[0]); +//logger.log(Level.DEBUG, "sr[0]:3: " + sr[0]); } else { sr[0] = -992; -//System.err.println("sr[0]:4: " + sr[0]); +//logger.log(Level.DEBUG, "sr[0]:4: " + sr[0]); } // DELAY A diff --git a/src/main/java/vavi/sound/adpcm/dvi/Dvi.java b/src/main/java/vavi/sound/adpcm/dvi/Dvi.java index f57cdda..bbd9be2 100644 --- a/src/main/java/vavi/sound/adpcm/dvi/Dvi.java +++ b/src/main/java/vavi/sound/adpcm/dvi/Dvi.java @@ -81,7 +81,7 @@ private static class State { } /** */ - private State state = new State(); + private final State state = new State(); /** */ public State getState() { @@ -180,7 +180,7 @@ public int decode(int input) { // int valPrev = state.valPrev; -//System.err.printf("%d\n", valPrev); +//logger.log(Level.DEBUG, "{}", valPrev); // Current step change index int index = state.index; diff --git a/src/main/java/vavi/sound/adpcm/ima/Ima.java b/src/main/java/vavi/sound/adpcm/ima/Ima.java index a14bb72..b0caee0 100644 --- a/src/main/java/vavi/sound/adpcm/ima/Ima.java +++ b/src/main/java/vavi/sound/adpcm/ima/Ima.java @@ -18,9 +18,10 @@ package vavi.sound.adpcm.ima; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -32,6 +33,8 @@ */ class Ima { + private static final Logger logger = getLogger(Ima.class.getName()); + /** */ public static final int ISSTMAX = 88; @@ -60,7 +63,7 @@ private static int adjustState(int c) { } /** */ - private static int[][] stateAdjustTable = new int[ISSTMAX + 1][8]; + private static final int[][] stateAdjustTable = new int[ISSTMAX + 1][8]; /* */ static { @@ -87,13 +90,13 @@ private static int adjustState(int c) { * @param length samples to decode PER channel, REQUIRE n % 8 == 1 * @param outIncrement index difference between successive output samples */ - private void decode(int channel, - int channels, - byte[] inBuffer, - int[] outBuffer, - int op, - int length, - int outIncrement) { + private static void decode(int channel, + int channels, + byte[] inBuffer, + int[] outBuffer, + int op, + int length, + int outIncrement) { // input pointer to 4-byte block state-initializer int ip = 4 * channel; @@ -106,7 +109,7 @@ private void decode(int channel, } int state = inBuffer[ip + 2] & 0xff; if (state > ISSTMAX) { -Debug.println(Level.FINE, "IMA_ADPCM block ch" + channel + " initial-state (" + state + ") out of range"); +logger.log(Level.DEBUG, "IMA_ADPCM block ch" + channel + " initial-state (" + state + ") out of range"); state = 0; } // specs say to ignore ip[3] , but write it as 0 @@ -150,13 +153,13 @@ private void decode(int channel, if (c != cm) { val -= dp; if (val < -0x8000) { -//Debug.println(StringUtil.toHex4(val) + " -> " + (-0x8000)); +//logger.log(Level.DEBUG, String.format("%04x -> %d", val, -0x8000)); val = -0x8000; } } else { val += dp; if (val > 0x7fff) { -//Debug.println(StringUtil.toHex4(val) + " -> " + (0x7fff)); +//logger.log(Level.DEBUG, String.format("%04x -> %d", val, 0x7fff)); val = 0x7fff; } } @@ -173,7 +176,7 @@ private void decode(int channel, * @param outBuffer output samples, n*chans * @param length samples to decode PER channel, REQUIRE n % 8 == 1 */ - public void decodeBlock(int channels, byte[] inBuffer, int[] outBuffer, int length) { + public static void decodeBlock(int channels, byte[] inBuffer, int[] outBuffer, int length) { for (int ch = 0; ch < channels; ch++) { decode(ch, channels, inBuffer, outBuffer, ch, length, channels); } @@ -187,7 +190,7 @@ public void decodeBlock(int channels, byte[] inBuffer, int[] outBuffer, int leng * @param outBuffers chan output sample buffers, each takes n samples * @param length samples to decode PER channel, REQUIRE n % 8 == 1 */ - public void decodeBlocks(int channels, byte[] inBuffer, int[][] outBuffers, int length) { + public static void decodeBlocks(int channels, byte[] inBuffer, int[][] outBuffers, int length) { for (int ch = 0; ch < channels; ch++) { decode(ch, channels, inBuffer, outBuffers[ch], 0, length, 1); } @@ -202,7 +205,7 @@ public void decodeBlocks(int channels, byte[] inBuffer, int[][] outBuffers, int * @param st input/output state, REQUIRE 0 <= *st <= ISSTMAX * @param obuff output buffer[blockAlign], or null for no output */ - private int encode(int ch, int chans, int v0, int[] ibuff, int n, int[] st, int stp, byte[] obuff) { + private static int encode(int ch, int chans, int v0, int[] ibuff, int n, int[] st, int stp, byte[] obuff) { // set 0 only to shut up gcc's 'might be uninitialized' int o_inc = 0; @@ -261,7 +264,7 @@ private int encode(int ch, int chans, int v0, int[] ibuff, int n, int[] st, int op += o_inc; // skip op for next group } } else { -//System.err.println("op: " + op); +//logger.log(Level.DEBUG, "op: " + op); obuff[op] = (byte) cm; } i = (i + 1) & 0x07; @@ -409,10 +412,10 @@ public void encodeBlock(int channels, int[] inBuffer, int length, int[] steps, b */ public static int getSamplesIn(int dataLength, int channels, int blockAlign, int samplesPerBlock) { int m, n; -// Debug.println("dataLength: " + dataLength); -// Debug.println("channels: " + channels); -// Debug.println("blockAlign: " + blockAlign); -// Debug.println("samplesPerBlock: " + samplesPerBlock); +//logger.log(Level.DEBUG, "dataLength: " + dataLength); +//logger.log(Level.DEBUG, "channels: " + channels); +//logger.log(Level.DEBUG, "blockAlign: " + blockAlign); +//logger.log(Level.DEBUG, "samplesPerBlock: " + samplesPerBlock); if (samplesPerBlock != 0) { n = (dataLength / blockAlign) * samplesPerBlock; @@ -421,8 +424,8 @@ public static int getSamplesIn(int dataLength, int channels, int blockAlign, int n = 0; m = blockAlign; } -//Debug.println("n: " + n); -//Debug.println("m: " + m); +//logger.log(Level.DEBUG, "n: " + n); +//logger.log(Level.DEBUG, "m: " + m); if (m >= 4 * channels) { m -= 4 * channels; // number of bytes beyond block-header m /= 4 * channels; // number of 4-byte blocks/channel beyond header diff --git a/src/main/java/vavi/sound/adpcm/ima/ImaInputEngine.java b/src/main/java/vavi/sound/adpcm/ima/ImaInputEngine.java index 2c4b423..b6a9335 100644 --- a/src/main/java/vavi/sound/adpcm/ima/ImaInputEngine.java +++ b/src/main/java/vavi/sound/adpcm/ima/ImaInputEngine.java @@ -10,15 +10,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; import vavi.io.InputEngine; import vavi.io.LittleEndianDataInputStream; -import vavi.util.Debug; - import vavix.io.IOStreamInputEngine; +import static java.lang.System.getLogger; + /** * ImaInputEngine. @@ -28,7 +29,9 @@ */ class ImaInputEngine implements InputEngine { - private OutputStream out; + private static final Logger logger = getLogger(ImaInputEngine.class.getName()); + + private final OutputStream out; private final Ima encoder = new Ima(); @@ -47,7 +50,7 @@ public ImaInputEngine(OutputStream out, this.samplesPerBlock = samplesPerBlock; this.channels = channels; this.byteOrder = byteOrder; -Debug.println(Level.FINE, "byteOrder: " + this.byteOrder); +logger.log(Level.DEBUG, "byteOrder: " + this.byteOrder); } @Override @@ -73,7 +76,7 @@ public void execute() throws IOException { throw new IOException("Not yet initialized"); } else { int bytesPerBlock = Ima.getBytesPerBlock(channels, samplesPerBlock); -//System.err.println("bytesPerBlock: " + bytesPerBlock + ", samplesPerBlock: " + samplesPerBlock); +//logger.log(Level.DEBUG, "bytesPerBlock: " + bytesPerBlock + ", samplesPerBlock: " + samplesPerBlock); byte[] buffer = new byte[samplesPerBlock * 2]; int l = 0; while (l < buffer.length) { @@ -86,7 +89,7 @@ public void execute() throws IOException { if (l > 0) { byte[] adpcm = new byte[bytesPerBlock]; int[] pcm = new int[l / 2]; -//Debug.println("adpcm: " + bytesPerBlock + ", pcm: " + pcm.length + ", " + l); +//logger.log(Level.DEBUG, "adpcm: " + bytesPerBlock + ", pcm: " + pcm.length + ", " + l); LittleEndianDataInputStream ledis = new LittleEndianDataInputStream(new ByteArrayInputStream(buffer)); for (int i = 0; i < pcm.length; i++) { pcm[i] = ledis.readShort(); @@ -94,7 +97,7 @@ public void execute() throws IOException { ledis.close(); encoder.encodeBlock(1, pcm, pcm.length, steps, adpcm, 9); -//Debug.println("adpcm: " + adpcm.length); +//logger.log(Level.DEBUG, "adpcm: " + adpcm.length); out.write(adpcm); } } diff --git a/src/main/java/vavi/sound/adpcm/ima/ImaInputStream.java b/src/main/java/vavi/sound/adpcm/ima/ImaInputStream.java index 7f3e533..69723ed 100644 --- a/src/main/java/vavi/sound/adpcm/ima/ImaInputStream.java +++ b/src/main/java/vavi/sound/adpcm/ima/ImaInputStream.java @@ -9,10 +9,13 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; import vavi.io.OutputEngineInputStream; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -23,6 +26,8 @@ */ public class ImaInputStream extends FilterInputStream { + private static final Logger logger = getLogger(ImaInputStream.class.getName()); + /** * byte order is little endian */ @@ -107,7 +112,7 @@ public int read(byte[] b, int off, int len) throws IOException { } } } catch (IOException e) { - Debug.printStackTrace(e); + logger.log(Level.ERROR, e.getMessage(), e); } return i; } diff --git a/src/main/java/vavi/sound/adpcm/ima/ImaOutputEngine.java b/src/main/java/vavi/sound/adpcm/ima/ImaOutputEngine.java index 8250cfd..41a7b6a 100644 --- a/src/main/java/vavi/sound/adpcm/ima/ImaOutputEngine.java +++ b/src/main/java/vavi/sound/adpcm/ima/ImaOutputEngine.java @@ -24,18 +24,18 @@ class ImaOutputEngine implements OutputEngine { /** */ - private InputStream in; + private final InputStream in; /** */ - private Ima decoder = new Ima(); + private final Ima decoder = new Ima(); /** */ private DataOutputStream out; - private int samplesPerBlock; - private int channels; - private int blockSize; - private ByteOrder byteOrder; + private final int samplesPerBlock; + private final int channels; + private final int blockSize; + private final ByteOrder byteOrder; private byte[] packet; private int[] samples; diff --git a/src/main/java/vavi/sound/adpcm/ms/Ms.java b/src/main/java/vavi/sound/adpcm/ms/Ms.java index 5a9f3c4..170c92c 100644 --- a/src/main/java/vavi/sound/adpcm/ms/Ms.java +++ b/src/main/java/vavi/sound/adpcm/ms/Ms.java @@ -18,9 +18,10 @@ package vavi.sound.adpcm.ms; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -45,11 +46,13 @@ */ class Ms { + private static final Logger logger = getLogger(Ms.class.getName()); + /** */ private static class State { /** step size */ int step; - int[] iCoef = new int[2]; + final int[] iCoef = new int[2]; } /** @@ -82,22 +85,22 @@ private static class State { /** * @param sp state pointer */ - private int decode(int code, - State[] state, - int sp, - int sample1, - int sample2) { + private static int decode(int code, + State[] state, + int sp, + int sample1, + int sample2) { // Compute next step value int step = state[sp].step; int nstep = (stepAdjustTable[code] * step) >> 8; - state[sp].step = (nstep < 16) ? 16 : nstep; + state[sp].step = Math.max(nstep, 16); // make linear prediction for next sample int vlin = ((sample1 * state[sp].iCoef[0]) + (sample2 * state[sp].iCoef[1])) >> 8; -//System.err.println(vlin); +//logger.log(Level.DEBUG, vlin); // then add the code * step adjustment code -= (code & 0x08) << 1; int sample = (code * step) + vlin; @@ -135,7 +138,7 @@ public void decodeBlock(int channels, for (int channel = 0; channel < channels; channel++) { int bpred = inBuffer[ip++] & 0xff; if (bpred >= nCoef) { -Debug.println(Level.FINE, "MSADPCM bpred >= nCoef, arbitrarily using 0"); +logger.log(Level.DEBUG, "MSADPCM bpred >= nCoef, arbitrarily using 0"); bpred = 0; } state[channel] = new State(); @@ -148,7 +151,7 @@ public void decodeBlock(int channels, if ((value & 0x8000) != 0) { value -= 0x10000; } -//System.err.println("1: " + value); +//logger.log(Level.DEBUG, "1: " + value); state[channel].step = value; ip += 2; } @@ -159,7 +162,7 @@ public void decodeBlock(int channels, if ((value & 0x8000) != 0) { value -= 0x10000; } -//System.err.println("2: " + value); +//logger.log(Level.DEBUG, "2: " + value); outBuffer[channels + channel] = value; ip += 2; } @@ -170,7 +173,7 @@ public void decodeBlock(int channels, if ((value & 0x8000) != 0) { value -= 0x10000; } -//System.err.println("3: " + value); +//logger.log(Level.DEBUG, "3: " + value); outBuffer[channel] = value; ip += 2; } @@ -208,15 +211,15 @@ public void decodeBlock(int channels, * @param outBuffer output buffer[blockAlign], or NULL for no output * @return ??? */ - private int encode(int channel, - int channels, - int[] v, - int[] iCoef, - int[] inBuffer, - int length, - int[] steps, - int sp, - byte[] outBuffer) { + private static int encode(int channel, + int channels, + int[] v, + int[] iCoef, + int[] inBuffer, + int length, + int[] steps, + int sp, + byte[] outBuffer) { int ox = 0; // @@ -259,7 +262,7 @@ private int encode(int channel, // difference between linear prediction and current sample d = inBuffer[ip] - vlin; int dp = d + (step << 3) + (step >> 1); -//System.err.println("vlin: " + vlin + ", d: " + d + ", dp: " + dp + ", in: " + inBuffer[ip] + ", coef: " + iCoef[0] + ", " + iCoef[1]); +//logger.log(Level.DEBUG, "vlin: " + vlin + ", d: " + d + ", dp: " + dp + ", in: " + inBuffer[ip] + ", coef: " + iCoef[0] + ", " + iCoef[1]); int c = 0; if (dp > 0) { c = dp / step; @@ -286,7 +289,7 @@ private int encode(int channel, // FIXME does c << 0 work properly ? outBuffer[op + (ox >> 3)] |= (byte) ((ox & 4) != 0 ? c : (c << 4)); ox += 4 * channels; -//System.err.printf("%1x\n", c); +//logger.log(Level.DEBUG, String.format("%1x", c)); } // Update the step for the next sample @@ -296,9 +299,9 @@ private int encode(int channel, } } //if (outBuffer != null) -// System.err.print("\n"); +// logger.log(Level.DEBUG, ""); d2 /= length; // be sure it's non-negative -//System.err.printf("ch%d: st %d->%d, d %.1f\n", channel, steps[sp], step, Math.sqrt(d2)); +//logger.log(Level.DEBUG, String.format("ch%d: st %d->%d, d %.1f", channel, steps[sp], step, Math.sqrt(d2))); steps[sp] = step; return (int) Math.sqrt(d2); @@ -315,13 +318,13 @@ private int encode(int channel, * @param sp steps pointer * @param outBuffer output buffer[blockAlign] */ - private void encodeChannel(int channel, - int channels, - int[] inBuffer, - int length, - int[] steps, - int sp, - byte[] outBuffer) { + private static void encodeChannel(int channel, + int channels, + int[] inBuffer, + int length, + int[] steps, + int sp, + byte[] outBuffer) { int[] v = new int[2]; int[] ss = new int[1]; @@ -351,7 +354,7 @@ private void encodeChannel(int channel, s1[0] = s0; encode(channel, channels, v, _iCoef[k], inBuffer, n0, s1, 0, null); -//System.err.printf(" s32 %d\n", s1[0]); +//logger.log(Level.DEBUG, String.format(" s32 %d", s1[0])); ss[0] = (3 * s0 + s1[0]) / 4; s1[0] = ss[0]; @@ -369,7 +372,7 @@ private void encodeChannel(int channel, } } steps[sp] = smin; -//System.err.printf("kmin %d, smin %5d, \n", kmin, smin); +//logger.log(Level.DEBUG, String.format("kmin %d, smin %5d, ", kmin, smin)); encode(channel, channels, v, _iCoef[kmin], inBuffer, length, steps, sp, outBuffer); outBuffer[channel] = (byte) kmin; } @@ -419,8 +422,8 @@ public static int getSamplesIn(int dataLength, n = 0; m = blockAlign; } -//Debug.println("n: " + n); -//Debug.println("m: " + m); +//logger.log(Level.DEBUG, "n: " + n); +//logger.log(Level.DEBUG, "m: " + m); if (m >= 7 * channels) { m -= 7 * channels; // bytes beyond block-header m = (2 * m) / channels + 2; // nibbles / channels + 2 in header diff --git a/src/main/java/vavi/sound/adpcm/ms/MsInputEngine.java b/src/main/java/vavi/sound/adpcm/ms/MsInputEngine.java index dbfb4b1..b9fc2f0 100644 --- a/src/main/java/vavi/sound/adpcm/ms/MsInputEngine.java +++ b/src/main/java/vavi/sound/adpcm/ms/MsInputEngine.java @@ -10,15 +10,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; import vavi.io.InputEngine; import vavi.io.LittleEndianDataInputStream; -import vavi.util.Debug; - import vavix.io.IOStreamInputEngine; +import static java.lang.System.getLogger; + /** * MsInputEngine. @@ -28,15 +29,17 @@ */ class MsInputEngine implements InputEngine { - private OutputStream out; + private static final Logger logger = getLogger(MsInputEngine.class.getName()); + + private final OutputStream out; - private Ms encoder = new Ms(); + private final Ms encoder = new Ms(); private InputStream in; - private int samplesPerBlock; - private int channels; - private ByteOrder byteOrder; + private final int samplesPerBlock; + private final int channels; + private final ByteOrder byteOrder; /** */ public MsInputEngine(OutputStream out, @@ -47,7 +50,7 @@ public MsInputEngine(OutputStream out, this.samplesPerBlock = samplesPerBlock; this.channels = channels; this.byteOrder = byteOrder; -Debug.println(Level.FINE, "byteOrder: " + this.byteOrder); +logger.log(Level.DEBUG, "byteOrder: " + this.byteOrder); } @Override @@ -60,7 +63,7 @@ public void initialize(InputStream in) throws IOException { } /** */ - private int[] steps = new int[16]; + private final int[] steps = new int[16]; /** * because {@link #in} reads only {@link #samplesPerBlock} * 2 bytes, bufferSize for @@ -73,7 +76,7 @@ public void execute() throws IOException { throw new IOException("Not yet initialized"); } else { int bytesPerBlock = Ms.getBytesPerBlock(channels, samplesPerBlock); -//System.err.println("bytesPerBlock: " + bytesPerBlock + ", samplesPerBlock: " + samplesPerBlock); +//logger.log(Level.DEBUG, "bytesPerBlock: " + bytesPerBlock + ", samplesPerBlock: " + samplesPerBlock); byte[] buffer = new byte[samplesPerBlock * 2]; int l = 0; while (l < buffer.length) { @@ -83,18 +86,18 @@ public void execute() throws IOException { } l += r; } -//System.err.println(StringUtil.getDump(buffer, 128)); +//logger.log(Level.DEBUG, StringUtil.getDump(buffer, 128)); if (l > 0) { byte[] adpcm = new byte[bytesPerBlock]; int[] pcm = new int[l / 2]; -//Debug.println("adpcm: " + bytesPerBlock + ", pcm: " + pcm.length + ", " + l); +//logger.log(Level.DEBUG, "adpcm: " + bytesPerBlock + ", pcm: " + pcm.length + ", " + l); LittleEndianDataInputStream ledis = new LittleEndianDataInputStream(new ByteArrayInputStream(buffer)); for (int i = 0; i < pcm.length; i++) { pcm[i] = ledis.readShort(); } ledis.close(); encoder.encodeBlock(1, pcm, pcm.length, steps, adpcm, bytesPerBlock); -//System.err.println(StringUtil.getDump(adpcm, 128)); +//logger.log(Level.DEBUG, StringUtil.getDump(adpcm, 128)); out.write(adpcm); } diff --git a/src/main/java/vavi/sound/adpcm/ms/MsInputStream.java b/src/main/java/vavi/sound/adpcm/ms/MsInputStream.java index f840581..d9c16ba 100644 --- a/src/main/java/vavi/sound/adpcm/ms/MsInputStream.java +++ b/src/main/java/vavi/sound/adpcm/ms/MsInputStream.java @@ -9,11 +9,13 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; import vavi.io.OutputEngineInputStream; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -24,6 +26,8 @@ */ public class MsInputStream extends FilterInputStream { + private static final Logger logger = getLogger(MsInputStream.class.getName()); + /** * byte order little endian */ @@ -61,9 +65,9 @@ public MsInputStream(InputStream in, channels, blockSize, samplesPerBlock); -Debug.println(Level.FINER, "numSamples: " + numSamples); +logger.log(Level.TRACE, "numSamples: " + numSamples); this.available = numSamples * channels * bytesPerSample; -Debug.println(Level.FINER, "available: " + available); +logger.log(Level.TRACE, "available: " + available); } /** */ @@ -109,7 +113,7 @@ public int read(byte[] b, int off, int len) throws IOException { } } } catch (IOException e) { -e.printStackTrace(System.err); +logger.log(Level.ERROR, e.getMessage(), e); } return i; } diff --git a/src/main/java/vavi/sound/adpcm/ms/MsOutputEngine.java b/src/main/java/vavi/sound/adpcm/ms/MsOutputEngine.java index 63fbf0f..46880e9 100644 --- a/src/main/java/vavi/sound/adpcm/ms/MsOutputEngine.java +++ b/src/main/java/vavi/sound/adpcm/ms/MsOutputEngine.java @@ -24,20 +24,20 @@ class MsOutputEngine implements OutputEngine { /** */ - private InputStream in; + private final InputStream in; /** */ - private Ms decoder = new Ms(); + private final Ms decoder = new Ms(); /** */ private DataOutputStream out; - private int samplesPerBlock; - private int nCoefs; - private int[][] iCoefs; - private int channels; - private int blockSize; - private ByteOrder byteOrder; + private final int samplesPerBlock; + private final int nCoefs; + private final int[][] iCoefs; + private final int channels; + private final int blockSize; + private final ByteOrder byteOrder; private byte[] packet; private int[] samples; diff --git a/src/main/java/vavi/sound/adpcm/oki/OkiInputStream.java b/src/main/java/vavi/sound/adpcm/oki/OkiInputStream.java index 648403e..33d4a4e 100644 --- a/src/main/java/vavi/sound/adpcm/oki/OkiInputStream.java +++ b/src/main/java/vavi/sound/adpcm/oki/OkiInputStream.java @@ -7,12 +7,14 @@ package vavi.sound.adpcm.oki; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; import vavi.sound.adpcm.AdpcmInputStream; import vavi.sound.adpcm.Codec; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -23,6 +25,8 @@ */ public class OkiInputStream extends AdpcmInputStream { + private static final Logger logger = getLogger(OkiInputStream.class.getName()); + @Override protected Codec getCodec() { return new Oki(); @@ -34,6 +38,6 @@ protected Codec getCodec() { */ public OkiInputStream(InputStream in, ByteOrder byteOrder) { super(in, byteOrder, 4, ByteOrder.LITTLE_ENDIAN); // oki adpcm is little endian fixed -Debug.println(Level.FINE, this.in); +logger.log(Level.DEBUG, this.in); } } diff --git a/src/main/java/vavi/sound/adpcm/vox/Vox.java b/src/main/java/vavi/sound/adpcm/vox/Vox.java index 35768e0..d52c12e 100644 --- a/src/main/java/vavi/sound/adpcm/vox/Vox.java +++ b/src/main/java/vavi/sound/adpcm/vox/Vox.java @@ -33,7 +33,7 @@ private static class State { }; /** */ - private State state = new State(); + private final State state = new State(); @Override public int encode(int samp) { @@ -58,7 +58,7 @@ public int encode(int samp) { } state.last = decode(code); -//System.err.printf("%04X -> %02X\n", samp, code); +//logger.log(Level.DEBUG, String.format("%04X -> %02X", samp, code)); return code; } @@ -103,7 +103,7 @@ public int decode(int code) { } /** */ - private int adjust(int code) { + private static int adjust(int code) { int c = code & 0x07; if (c < 4) { return -1; diff --git a/src/main/java/vavi/sound/adpcm/vox/VoxInputStream.java b/src/main/java/vavi/sound/adpcm/vox/VoxInputStream.java index 9330967..f4b6801 100644 --- a/src/main/java/vavi/sound/adpcm/vox/VoxInputStream.java +++ b/src/main/java/vavi/sound/adpcm/vox/VoxInputStream.java @@ -37,7 +37,7 @@ public VoxInputStream(InputStream in, ByteOrder byteOrder) { @Override public int available() throws IOException { -//Debug.println("0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); +//logger.log(Level.DEBUG, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0))); return (in.available() * 2) + (rest ? 1 : 0); } @@ -46,7 +46,7 @@ public int available() throws IOException { */ @Override public int read() throws IOException { -//Debug.println(in); +//logger.log(Level.DEBUG, in); if (!rest) { int adpcm = in.read(); if (adpcm == -1) { @@ -56,7 +56,7 @@ public int read() throws IOException { current = decoder.decode(adpcm) * 16; // TODO check!!! rest = true; -//Debug.println("1: " + StringUtil.toHex2(current & 0xff)); +//logger.log(Level.DEBUG, "1: " + StringUtil.toHex2(current & 0xff)); if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) { return (current & 0xff00) >> 8; } else { @@ -64,7 +64,7 @@ public int read() throws IOException { } } else { rest = false; -//Debug.println("2: " + StringUtil.toHex2((current & 0xff00) >> 8)); +//logger.log(Level.DEBUG, "2: " + StringUtil.toHex2((current & 0xff00) >> 8)); if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) { return current & 0xff; } else { diff --git a/src/main/java/vavi/sound/adpcm/vox/VoxOutputStream.java b/src/main/java/vavi/sound/adpcm/vox/VoxOutputStream.java index 730ea38..192e8a3 100644 --- a/src/main/java/vavi/sound/adpcm/vox/VoxOutputStream.java +++ b/src/main/java/vavi/sound/adpcm/vox/VoxOutputStream.java @@ -55,7 +55,7 @@ public void write(int b) throws IOException { } } -// System.err.println("current: " + StringUtil.toHex4(current)); +//logger.log(Level.DEBUG, "current: " + StringUtil.toHex4(current)); out.write(encoder.encode(current / 16)); // BitOutputStream write 4bit flushed = true; diff --git a/src/main/java/vavi/sound/adpcm/yamaha/Yamaha.java b/src/main/java/vavi/sound/adpcm/yamaha/Yamaha.java index 728bbb5..bec747a 100644 --- a/src/main/java/vavi/sound/adpcm/yamaha/Yamaha.java +++ b/src/main/java/vavi/sound/adpcm/yamaha/Yamaha.java @@ -24,14 +24,14 @@ private static class Status { } /** You need initialize before reuse methods! */ - private Status stat = new Status(); + private final Status stat = new Status(); /** * @param code ADPCM (LSB 4bit available) * @param ss ? * @return adjusted ss */ - private int adjust(int code, int ss) { + private static int adjust(int code, int ss) { switch (code & 0x07) { case 0x00: case 0x01: @@ -123,7 +123,7 @@ public int encode(int samp) { } stat.last = decode(code); -//System.err.printf("%04X -> %02X\n", samp, code); +//logger.log(Level.DEBUG, String.format("%04X -> %02X", samp, code)); return code; } } diff --git a/src/main/java/vavi/sound/adpcm/ym2608/Ym2608.java b/src/main/java/vavi/sound/adpcm/ym2608/Ym2608.java index e5ed2b2..d725a91 100644 --- a/src/main/java/vavi/sound/adpcm/ym2608/Ym2608.java +++ b/src/main/java/vavi/sound/adpcm/ym2608/Ym2608.java @@ -31,7 +31,7 @@ void next() { } /** */ - private State state = new State(); + private final State state = new State(); /** */ private static final int[] stepsizeTable = { @@ -48,12 +48,12 @@ public int encode(int pcm) { // encoding process 2 long dn = pcm - state.xn; -//System.err.printf("%05d: %d, %d, %d\n", ccc, dn, pcm, state.xn); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d, %d, %d", ccc, dn, pcm, state.xn)); // OK // encoding process 3, 4 // calc An from "I = | dn | / Sn" // calc using integer part of production. long i = (int) (((Math.abs(dn)) << 16) / ((state.stepSize) << 14)); -//System.err.printf("%05d: %d\n", ccc, i); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d", ccc, i)); // OK if (i > 7) { i = 7; } @@ -62,7 +62,7 @@ public int encode(int pcm) { // encoding process 5 // L3 + L2 / 2 + L1 / 4 + 1 / 8 * stepSize multiply 8 times and calc as integer i = (adpcm * 2L + 1) * state.stepSize / 8; -//System.err.printf("%05d: %d, %d, %d\n", ccc, i, adpcm, state.stepSize); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d, %d, %d", ccc, i, adpcm, state.stepSize)); // OK // if "1 - 2 * L4 -> L4" is 1 equals multiply -1 if (dn < 0) { @@ -74,12 +74,12 @@ public int encode(int pcm) { } else { state.xn += i; } -//System.err.printf("%05d: %d, %d\n", ccc, state.xn, i); +//logger.log(Level.DEBUG, String.format("%05d: %d, %d", ccc, state.xn, i)); // encode process 6 // update step size state.stepSize = (stepsizeTable[adpcm] * state.stepSize) / 64; -//System.err.printf("%05d: %d, %d, %d\n", ccc, i, adpcm, state.stepSize); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d, %d, %d", ccc, i, adpcm, state.stepSize)); // OK // encode process 7 if (state.stepSize < 127) { @@ -108,7 +108,7 @@ public int decode(int adpcm) { } else { state.xn += i; } -//System.err.printf("%05d: %d, %d, %d\n", state.count, state.xn, state.stepSize, adpcm); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d, %d, %d", state.count, state.xn, state.stepSize, adpcm)); // OK // decode process 4 if (state.xn > 32767) { @@ -125,7 +125,7 @@ public int decode(int adpcm) { } else if (state.stepSize > 24576) { state.stepSize = 24576; } -// System.err.printf("%05d: %d, %d, %d\n", state.count, state.xn, state.stepSize, adpcm); // OK +//logger.log(Level.DEBUG, String.format("%05d: %d, %d, %d", state.count, state.xn, state.stepSize, adpcm)); // OK // store PCM int pcm = (int) state.xn; diff --git a/src/main/java/vavi/sound/mfi/MfiDevice.java b/src/main/java/vavi/sound/mfi/MfiDevice.java index d46f486..dbd3665 100644 --- a/src/main/java/vavi/sound/mfi/MfiDevice.java +++ b/src/main/java/vavi/sound/mfi/MfiDevice.java @@ -19,13 +19,13 @@ public interface MfiDevice { class Info { /** */ - String name; + final String name; /** */ - String vendor; + final String vendor; /** */ - String description; + final String description; /** */ - String version; + final String version; /** */ protected Info(String name, diff --git a/src/main/java/vavi/sound/mfi/MfiEvent.java b/src/main/java/vavi/sound/mfi/MfiEvent.java index 5552a27..3e8b6d6 100644 --- a/src/main/java/vavi/sound/mfi/MfiEvent.java +++ b/src/main/java/vavi/sound/mfi/MfiEvent.java @@ -18,7 +18,7 @@ public class MfiEvent { /** */ - private MfiMessage message; + private final MfiMessage message; /** */ private long tick; diff --git a/src/main/java/vavi/sound/mfi/MfiFileFormat.java b/src/main/java/vavi/sound/mfi/MfiFileFormat.java index 16c955d..da9cfc2 100644 --- a/src/main/java/vavi/sound/mfi/MfiFileFormat.java +++ b/src/main/java/vavi/sound/mfi/MfiFileFormat.java @@ -19,7 +19,7 @@ public class MfiFileFormat { protected int byteLength; /** */ - protected int type; + protected final int type; /** */ public MfiFileFormat(int type, int bytes) { diff --git a/src/main/java/vavi/sound/mfi/MfiSystem.java b/src/main/java/vavi/sound/mfi/MfiSystem.java index 683270d..e8f5342 100644 --- a/src/main/java/vavi/sound/mfi/MfiSystem.java +++ b/src/main/java/vavi/sound/mfi/MfiSystem.java @@ -12,13 +12,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.net.URL; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.ServiceLoader; -import java.util.logging.Level; import java.util.stream.StreamSupport; import javax.sound.midi.InvalidMidiDataException; @@ -26,7 +27,8 @@ import vavi.sound.mfi.spi.MfiDeviceProvider; import vavi.sound.mfi.spi.MfiFileReader; import vavi.sound.mfi.spi.MfiFileWriter; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -41,6 +43,8 @@ */ public final class MfiSystem { + private static final Logger logger = getLogger(MfiSystem.class.getName()); + /** cannot be access */ private MfiSystem() { } @@ -138,7 +142,7 @@ public static javax.sound.midi.Sequence toMidiSequence(Sequence sequence) throws InvalidMfiDataException, MfiUnavailableException { MidiConverter converter = MfiSystem.getMidiConverter(); -//Debug.println(converter); +//logger.log(Level.DEBUG, converter); return converter.toMidiSequence(sequence); } @@ -146,14 +150,14 @@ public static javax.sound.midi.Sequence toMidiSequence(Sequence sequence) public static MfiFileFormat getMfiFileFormat(InputStream stream) throws InvalidMfiDataException, IOException { -//Debug.println("readers: " + readers.length); +//logger.log(Level.DEBUG, "readers: " + readers.length); for (MfiFileReader reader : readers) { try { MfiFileFormat mff = reader.getMfiFileFormat(stream); -//Debug.println(StringUtil.paramString(mff)); +//logger.log(Level.DEBUG, StringUtil.paramString(mff)); return mff; } catch (Exception e) { -Debug.println(Level.WARNING, e); +logger.log(Level.WARNING, e.getMessage(), e); } } @@ -175,15 +179,14 @@ public static MfiFileFormat getMfiFileFormat(URL url) throws InvalidMfiDataExcep /** Gets a MFi sequence. */ public static Sequence getSequence(InputStream stream) throws InvalidMfiDataException, IOException { -//Debug.println("readers: " + readers.length); +//logger.log(Level.DEBUG, "readers: " + readers.length); for (MfiFileReader reader : readers) { try { Sequence sequence = reader.getSequence(stream); -//Debug.println(StringUtil.paramString(sequence)); +//logger.log(Level.DEBUG, StringUtil.paramString(sequence)); return sequence; } catch (InvalidMfiDataException e) { -Debug.println(Level.FINE, e); - continue; +logger.log(Level.DEBUG, e); } } @@ -256,7 +259,7 @@ public static int write(Sequence in, int fileType, OutputStream out) throws IOEx return writer.write(in, fileType, out); } } -Debug.println(Level.WARNING, "no writer found for: " + fileType); +logger.log(Level.WARNING, "no writer found for: " + fileType); return 0; } @@ -269,14 +272,14 @@ public static int write(Sequence in, int fileType, File out) throws IOException //---- /** all providers */ - private static ServiceLoader providers; + private static final ServiceLoader providers; /** all readers */ - private static ServiceLoader readers; + private static final ServiceLoader readers; /** all writers */ - private static ServiceLoader writers; + private static final ServiceLoader writers; /** default provider */ - private static MfiDeviceProvider provider; + private static final MfiDeviceProvider provider; /* * default is specified by MfiSystem.properties. @@ -294,7 +297,7 @@ public static int write(Sequence in, int fileType, File out) throws IOException providers = ServiceLoader.load(vavi.sound.mfi.spi.MfiDeviceProvider.class); providers.forEach(System.err::println); provider = StreamSupport.stream(providers.spliterator(), false).filter(p -> p.getClass().getName().equals(defaultProvider)).findFirst().get(); -Debug.println(Level.FINE, "default provider: " + provider.getClass().getName()); +logger.log(Level.DEBUG, "default provider: " + provider.getClass().getName()); readers = ServiceLoader.load(vavi.sound.mfi.spi.MfiFileReader.class); providers.forEach(System.err::println); @@ -302,7 +305,7 @@ public static int write(Sequence in, int fileType, File out) throws IOException writers = ServiceLoader.load(vavi.sound.mfi.spi.MfiFileWriter.class); providers.forEach(System.err::println); } catch (Exception e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/mfi/NoteMessage.java b/src/main/java/vavi/sound/mfi/NoteMessage.java index 5cb89e2..cfdc4f8 100644 --- a/src/main/java/vavi/sound/mfi/NoteMessage.java +++ b/src/main/java/vavi/sound/mfi/NoteMessage.java @@ -107,18 +107,17 @@ protected NoteMessage() { * @return note */ public int getNote() { - switch (shift) { - case 1: // 01 - return note + 12; - case 0: // 00 - return note; - case 3: // 11 - return note - 12; - case 2: // 10 - return note - 24; - default: - throw new IllegalArgumentException("shift: " + shift); - } + return switch (shift) { + case 1 -> // 01 + note + 12; + case 0 -> // 00 + note; + case 3 -> // 11 + note - 12; + case 2 -> // 10 + note - 24; + default -> throw new IllegalArgumentException("shift: " + shift); + }; } /** diff --git a/src/main/java/vavi/sound/mfi/Sequence.java b/src/main/java/vavi/sound/mfi/Sequence.java index 5f838fd..9cbc39c 100644 --- a/src/main/java/vavi/sound/mfi/Sequence.java +++ b/src/main/java/vavi/sound/mfi/Sequence.java @@ -23,7 +23,7 @@ public class Sequence { /** */ - protected List tracks; + protected final List tracks; /** Creates a sequence. */ public Sequence() { diff --git a/src/main/java/vavi/sound/mfi/Track.java b/src/main/java/vavi/sound/mfi/Track.java index eb724d8..11daec2 100644 --- a/src/main/java/vavi/sound/mfi/Track.java +++ b/src/main/java/vavi/sound/mfi/Track.java @@ -21,7 +21,7 @@ public class Track { /** */ - protected List events; + protected final List events; /** Creates new Track */ Track() { diff --git a/src/main/java/vavi/sound/mfi/vavi/AudioDataMessage.java b/src/main/java/vavi/sound/mfi/vavi/AudioDataMessage.java index 0106f2e..84686b7 100644 --- a/src/main/java/vavi/sound/mfi/vavi/AudioDataMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/AudioDataMessage.java @@ -11,10 +11,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.LinkedHashMap; import java.util.Map; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -26,9 +26,10 @@ import vavi.sound.mfi.vavi.sequencer.MfiMessageStore; import vavi.sound.midi.VaviMidiDeviceProvider; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * AudioDataMessage. @@ -60,6 +61,8 @@ public class AudioDataMessage extends MfiMessage implements MidiConvertible, AudioDataSequencer { + private static final Logger logger = getLogger(AudioDataMessage.class.getName()); + /** {@value} */ public static final String TYPE = "adat"; @@ -89,7 +92,7 @@ public class AudioDataMessage extends MfiMessage private int attribute; /** */ - private Map subChunks = new LinkedHashMap<>(); + private final Map subChunks = new LinkedHashMap<>(); /** * @see #FORMAT_ADPCM_TYPE2 @@ -132,15 +135,15 @@ public void writeTo(OutputStream os) // 1. recalc int dataLength = data.length; -Debug.println(Level.FINE, "dataLength: " + dataLength); +logger.log(Level.DEBUG, "dataLength: " + dataLength); int subChunksLength = 0; for (SubMessage subChunk : subChunks.values()) { subChunksLength += 4 + 2 + subChunk.getDataLength(); // type + length + ... } -Debug.println(Level.FINE, "subChunksLength: " + subChunksLength); +logger.log(Level.DEBUG, "subChunksLength: " + subChunksLength); int headerLength = 1 + 1 + subChunksLength; // format + attribute + ... int audioDataLength = 2 + headerLength + dataLength; // headerLength + ... -Debug.println(Level.FINE, "audioDataLength: " + audioDataLength); +logger.log(Level.DEBUG, "audioDataLength: " + audioDataLength); // 2. write DataOutputStream dos = new DataOutputStream(os); @@ -184,7 +187,7 @@ public void readFrom(InputStream is) int headerLength = dis.readUnsignedShort(); this.format = dis.readUnsignedByte(); this.attribute = dis.readUnsignedByte(); -Debug.printf(Level.FINE, "adat header: %d: f: %02x, a: %02x", headerLength, format, attribute); +logger.log(Level.DEBUG, String.format("adat header: %d: f: %02x, a: %02x", headerLength, format, attribute)); // sub chunks int l = 0; @@ -192,14 +195,14 @@ public void readFrom(InputStream is) SubMessage subChunk = SubMessage.readFrom(is); subChunks.put(subChunk.getSubType(), subChunk); l += subChunk.getDataLength() + 4 + 2; // + type + length -Debug.println(Level.FINE, "audio subchunk length sum: " + l + " / " + (headerLength - 2)); +logger.log(Level.DEBUG, "audio subchunk length sum: " + l + " / " + (headerLength - 2)); } // data int dataLength = audioDataLength - (headerLength + 1 + 1); // + format + attribute data = new byte[dataLength]; // TODO while data should be included dis.readFully(data, 0, dataLength); -Debug.println(Level.FINE, "adat length[" + audioDataNumber + "]: " + dataLength + " bytes\n" + StringUtil.getDump(data, 16)); +logger.log(Level.DEBUG, "adat length[" + audioDataNumber + "]: " + dataLength + " bytes\n" + StringUtil.getDump(data, 16)); // this.length = audioDataLength + 4 + 4; // + type + length @@ -215,15 +218,15 @@ public void setData(byte[] data) { // calc int dataLength = data.length; -Debug.println(Level.FINE, "dataLength: " + dataLength); +logger.log(Level.DEBUG, "dataLength: " + dataLength); int subChunksLength = 0; for (SubMessage subChunk : subChunks.values()) { subChunksLength += 4 + 2 + subChunk.getDataLength(); // type + length + ... } -Debug.println(Level.FINE, "subChunksLength: " + subChunksLength); +logger.log(Level.DEBUG, "subChunksLength: " + subChunksLength); int headerLength = 1 + 1 + subChunksLength; // format + attribute + ... int audioDataLength = 2 + headerLength + dataLength; // headerLength + ... -Debug.println(Level.FINE, "audioDataLength: " + audioDataLength); +logger.log(Level.DEBUG, "audioDataLength: " + audioDataLength); this.length = audioDataLength + 4 + 4; // + type + length } diff --git a/src/main/java/vavi/sound/mfi/vavi/HeaderChunk.java b/src/main/java/vavi/sound/mfi/vavi/HeaderChunk.java index 82c4cca..58f6ce9 100644 --- a/src/main/java/vavi/sound/mfi/vavi/HeaderChunk.java +++ b/src/main/java/vavi/sound/mfi/vavi/HeaderChunk.java @@ -11,16 +11,18 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.LinkedHashMap; import java.util.Map; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.Sequence; import vavi.sound.mfi.vavi.header.SorcMessage; import vavi.sound.mfi.vavi.header.TitlMessage; import vavi.sound.mfi.vavi.header.VersMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,6 +32,9 @@ * @version 0.00 070118 nsano initial version
*/ class HeaderChunk { + + private static final Logger logger = getLogger(HeaderChunk.class.getName()); + /** {@value} */ public static final String TYPE = "melo"; @@ -62,7 +67,7 @@ class HeaderChunk { private int tracksCount; /** header, sub chunks */ - private Map subChunks = new LinkedHashMap<>(); + private final Map subChunks = new LinkedHashMap<>(); /** */ private Support support; @@ -154,7 +159,7 @@ public int getSubChunksLength() { int length = 0; for (SubMessage subChunk : subChunks.values()) { length += 4 + 2 + subChunk.getDataLength(); // type + length + ... -//Debug.println(subChunk + ": " + subChunks.getSubLength()); +//logger.log(Level.DEBUG, subChunk + ": " + subChunks.getSubLength()); } return length; } @@ -181,11 +186,11 @@ public void writeTo(OutputStream os) // 1. check if (!isValid()) { -Debug.println(Level.FINE, "majorType: " + majorType); -Debug.println(Level.FINE, "minorType: " + minorType); -Debug.println(Level.FINE, "[sorc]: " + subChunks.get(SorcMessage.TYPE)); -Debug.println(Level.FINE, "[titl]: " + subChunks.get(TitlMessage.TYPE)); -Debug.println(Level.FINE, "[vers]: " + subChunks.get(VersMessage.TYPE)); +logger.log(Level.DEBUG, "majorType: " + majorType); +logger.log(Level.DEBUG, "minorType: " + minorType); +logger.log(Level.DEBUG, "[sorc]: " + subChunks.get(SorcMessage.TYPE)); +logger.log(Level.DEBUG, "[titl]: " + subChunks.get(TitlMessage.TYPE)); +logger.log(Level.DEBUG, "[vers]: " + subChunks.get(VersMessage.TYPE)); throw new InvalidMfiDataException("fields are not filled"); } @@ -208,11 +213,11 @@ public void writeTo(OutputStream os) dos.writeByte(majorType); dos.writeByte(minorType); dos.writeByte(tracksCount); -Debug.println(Level.FINE, "mfiDataLength: " + mfiDataLength); -Debug.println(Level.FINE, "dataLength: " + dataLength); -Debug.println(Level.FINE, "majorType: " + majorType); -Debug.println(Level.FINE, "minorType: " + minorType); -Debug.println(Level.FINE, "numberTracks: " + tracksCount); +logger.log(Level.DEBUG, "mfiDataLength: " + mfiDataLength); +logger.log(Level.DEBUG, "dataLength: " + dataLength); +logger.log(Level.DEBUG, "majorType: " + majorType); +logger.log(Level.DEBUG, "minorType: " + minorType); +logger.log(Level.DEBUG, "numberTracks: " + tracksCount); for (SubMessage subChunk : subChunks.values()) { subChunk.writeTo(os); @@ -240,21 +245,21 @@ public static HeaderChunk readFrom(InputStream is) // 1.2 length headerChunk.mfiDataLength = dis.readInt(); -Debug.println(Level.FINE, "mfiDataLength: " + headerChunk.mfiDataLength); +logger.log(Level.DEBUG, "mfiDataLength: " + headerChunk.mfiDataLength); // 1.3.1 offset to "trac" or "adat" headerChunk.dataLength = dis.readUnsignedShort(); -Debug.println(Level.FINE, "dataLength: " + headerChunk.dataLength); +logger.log(Level.DEBUG, "dataLength: " + headerChunk.dataLength); // 1.3.2.1 major type headerChunk.majorType = dis.readUnsignedByte(); -Debug.println(Level.FINE, "majorType: " + headerChunk.majorType); +logger.log(Level.DEBUG, "majorType: " + headerChunk.majorType); // 1.3.2.2 minor type headerChunk.setMinorType(dis.readUnsignedByte()); -Debug.println(Level.FINE, "minorType: " + headerChunk.minorType); +logger.log(Level.DEBUG, "minorType: " + headerChunk.minorType); // 1.3.3 number of tracks headerChunk.tracksCount = dis.readUnsignedByte(); -Debug.println(Level.FINE, "numberTracks: " + headerChunk.tracksCount); +logger.log(Level.DEBUG, "numberTracks: " + headerChunk.tracksCount); // 1.4 header sub chunks long l = 0; @@ -262,7 +267,7 @@ public static HeaderChunk readFrom(InputStream is) SubMessage subChunk = SubMessage.readFrom(is); headerChunk.subChunks.put(subChunk.getSubType(), subChunk); l += 4 + 2 + subChunk.getDataLength(); // type + length + -//Debug.println("header subchunk length sum: " + l + " / " + (headerLength - 3)); +//logger.log(Level.DEBUG, "header subchunk length sum: " + l + " / " + (headerLength - 3)); } return headerChunk; diff --git a/src/main/java/vavi/sound/mfi/vavi/MetaEventAdapter.java b/src/main/java/vavi/sound/mfi/vavi/MetaEventAdapter.java index 9dbb647..c230d87 100644 --- a/src/main/java/vavi/sound/mfi/vavi/MetaEventAdapter.java +++ b/src/main/java/vavi/sound/mfi/vavi/MetaEventAdapter.java @@ -6,7 +6,8 @@ package vavi.sound.mfi.vavi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MetaEventListener; @@ -20,7 +21,8 @@ import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.midi.MidiUtil; import vavi.sound.midi.VaviMidiDeviceProvider; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,6 +33,8 @@ */ class MetaEventAdapter implements MetaEventListener, MfiDevice { + private static final Logger logger = getLogger(MetaEventAdapter.class.getName()); + /** the device information */ private static final MfiDevice.Info info = new MfiDevice.Info("Java MFi ADPCM Sequencer", @@ -66,32 +70,32 @@ public void open() { */ @Override public void meta(javax.sound.midi.MetaMessage message) { -//Debug.println("type: " + message.getType()); +//logger.log(Level.DEBUG, "type: " + message.getType()); switch (MetaEvent.valueOf(message.getType())) { case META_MACHINE_DEPEND: // sequencer specific meta event try { processSpecial(message); } catch (InvalidMfiDataException e) { - Debug.printStackTrace(e.getCause()); + logger.log(Level.ERROR, e.getCause().getMessage(), e.getCause()); } catch (RuntimeException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); } catch (Error e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw e; } break; case META_TEXT_EVENT: // text event case META_COPYRIGHT: // copyright case META_NAME: // sequence name or track name -Debug.println(Level.FINE, "meta " + message.getType() + ": " + MidiUtil.getDecodedMessage(message.getData())); +logger.log(Level.DEBUG, "meta " + message.getType() + ": " + MidiUtil.getDecodedMessage(message.getData())); break; case META_END_OF_TRACK: // end of track case META_TEMPO: // tempo was set -Debug.println(Level.FINE, "this handler ignore meta: " + message.getType()); +logger.log(Level.DEBUG, "this handler ignore meta: " + message.getType()); break; default: -Debug.println(Level.FINE, "no meta sub handler: " + message.getType()); +logger.log(Level.DEBUG, "no meta sub handler: " + message.getType()); break; } } @@ -108,13 +112,13 @@ private void processSpecial(javax.sound.midi.MetaMessage message) int manufacturerId = data[0]; switch (manufacturerId) { case 0: // 3 byte manufacturer id -Debug.printf(Level.WARNING, "unhandled manufacturer: %02x %02x %02x\n", data[0], data[1], data[2]); +logger.log(Level.WARNING, String.format("unhandled manufacturer: %02x %02x %02x", data[0], data[1], data[2])); break; case VaviMidiDeviceProvider.MANUFACTURER_ID: processSpecial_Vavi(message); break; default: -Debug.printf(Level.WARNING, "unhandled manufacturer: %02x\n", manufacturerId); +logger.log(Level.WARNING, String.format("unhandled manufacturer: %02x", manufacturerId)); break; } } @@ -124,7 +128,7 @@ private void processSpecial(javax.sound.midi.MetaMessage message) * 0x5f * */ - private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi(javax.sound.midi.MetaMessage message) throws InvalidMfiDataException { byte[] data = message.getData(); @@ -137,7 +141,7 @@ private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) processSpecial_Vavi_Mfi4(message); break; default: -Debug.printf(Level.WARNING, "unhandled function: %02x\n", functionId); +logger.log(Level.WARNING, String.format("unhandled function: %02x", functionId)); break; } } @@ -147,12 +151,12 @@ private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) * 0x5f 0x01 * */ - private void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage message) throws InvalidMfiDataException { byte[] data = message.getData(); int id = (data[2] & 0xff) * 0xff + (data[3] & 0xff); -//Debug.println("message id: " + id); +//logger.log(Level.DEBUG, "message id: " + id); MachineDependentMessage mdm = (MachineDependentMessage) MfiMessageStore.get(id); int vendor = mdm.getVendor() | mdm.getCarrier(); @@ -160,8 +164,8 @@ private void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage m try { sequencer = MachineDependentSequencer.factory.get(vendor); } catch (IllegalArgumentException | Error e) { -Debug.printStackTrace(e); -Debug.printf(Level.SEVERE, "error vendor: 0x%02x\n", vendor); +logger.log(Level.ERROR, e.getMessage(), e); +logger.log(Level.ERROR, String.format("error vendor: 0x%02x", vendor)); sequencer = new UnknownVenderSequencer(); } sequencer.sequence(mdm); @@ -173,12 +177,12 @@ private void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage m * * @since MFi 4.0 */ - private void processSpecial_Vavi_Mfi4(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi_Mfi4(javax.sound.midi.MetaMessage message) throws InvalidMfiDataException { byte[] data = message.getData(); int id = (data[2] & 0xff) * 0xff + (data[3] & 0xff); -//Debug.println("message id: " + id); +//logger.log(Level.DEBUG, "message id: " + id); AudioDataSequencer sequencer = (AudioDataSequencer) MfiMessageStore.get(id); sequencer.sequence(); diff --git a/src/main/java/vavi/sound/mfi/vavi/MetaSupport.java b/src/main/java/vavi/sound/mfi/vavi/MetaSupport.java index 53b965d..13beed9 100644 --- a/src/main/java/vavi/sound/mfi/vavi/MetaSupport.java +++ b/src/main/java/vavi/sound/mfi/vavi/MetaSupport.java @@ -23,7 +23,7 @@ class MetaSupport implements Serializable { /** The metaEvent listeners */ - private List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); /** Adds {@link MetaEventListener}. */ public void addMetaEventListener(MetaEventListener l) { diff --git a/src/main/java/vavi/sound/mfi/vavi/MfiContext.java b/src/main/java/vavi/sound/mfi/vavi/MfiContext.java index 775c86d..87b8801 100644 --- a/src/main/java/vavi/sound/mfi/vavi/MfiContext.java +++ b/src/main/java/vavi/sound/mfi/vavi/MfiContext.java @@ -6,14 +6,14 @@ package vavi.sound.mfi.vavi; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; -import java.util.logging.Level; - import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; import javax.sound.midi.MidiFileFormat; @@ -28,7 +28,8 @@ import vavi.sound.mfi.vavi.track.TempoMessage; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.midi.MidiUtil; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -42,6 +43,8 @@ */ public class MfiContext { + private static final Logger logger = getLogger(MfiContext.class.getName()); + /** max MFi track number */ public static final int MAX_MFI_TRACKS = 4; @@ -57,7 +60,7 @@ public int getType() { /** MIDI format type */ public void setType(int type) { -Debug.println(Level.FINE, "type: " + type); +logger.log(Level.DEBUG, "type: " + type); this.type = type; } @@ -72,7 +75,7 @@ public int getTimeBase() { //---- /** index is MFi Track No., when that's used this returns true */ - private boolean[] trackUsed = new boolean[MAX_MFI_TRACKS]; + private final boolean[] trackUsed = new boolean[MAX_MFI_TRACKS]; /** * @param mfiTrackNumber mfi track number @@ -89,7 +92,7 @@ public boolean isTrackUsed(int mfiTrackNumber) { } /** is EOF set to the track ? */ - private boolean[] eofSet = new boolean[MAX_MFI_TRACKS]; + private final boolean[] eofSet = new boolean[MAX_MFI_TRACKS]; /** * @param mfiTrackNumber @@ -132,7 +135,7 @@ public boolean isScaleChanged() { //---- /** previous tick, index is MFi Track No. */ - private long[] previousTicks = new long[MAX_MFI_TRACKS]; + private final long[] previousTicks = new long[MAX_MFI_TRACKS]; /* initializing */ { Arrays.fill(previousTicks, 0); @@ -173,11 +176,11 @@ private int getAdjustedDelta(int mfiTrackNumber, double doubleDelta) { double rounded = doubleDelta - delta; roundedSum[mfiTrackNumber] += rounded; if (roundedSum[mfiTrackNumber] >= 1d) { -//Debug.println("rounded over 1, plus 1: " + roundedSum[mfiTrackNumber] + "[" + mfiTrackNumber + "]"); +//logger.log(Level.DEBUG, "rounded over 1, plus 1: " + roundedSum[mfiTrackNumber] + "[" + mfiTrackNumber + "]"); delta += 1; roundedSum[mfiTrackNumber] -= 1; } else if (roundedSum[mfiTrackNumber] <= -1d) { -//Debug.println("rounded under -1, minus 1: " + roundedSum[mfiTrackNumber] + "[" + mfiTrackNumber + "]"); +//logger.log(Level.DEBUG, "rounded under -1, minus 1: " + roundedSum[mfiTrackNumber] + "[" + mfiTrackNumber + "]"); delta -= 1; roundedSum[mfiTrackNumber] += 1; } @@ -222,22 +225,22 @@ public MfiEvent[] getIntervalMfiEvents(int mfiTrackNumber) { } else if (midiMessage instanceof MetaMessage && ((MetaMessage) midiMessage).getType() == 81) { // tempo interval = retrieveAdjustedDelta(mfiTrackNumber, midiEvent.getTick()); -Debug.println(Level.FINE, "interval for tempo[" + mfiTrackNumber + "]: " + interval); +logger.log(Level.DEBUG, "interval for tempo[" + mfiTrackNumber + "]: " + interval); } else if (midiMessage instanceof MetaMessage && ((MetaMessage) midiMessage).getType() == 47) { // eot interval = retrieveAdjustedDelta(mfiTrackNumber, midiEvent.getTick()); -//Debug.println("interval for EOT[" + mfiTrackNumber + "]: " + interval); +//logger.log(Level.DEBUG, "interval for EOT[" + mfiTrackNumber + "]: " + interval); } else if (midiMessage instanceof MetaMessage) { return null; } else if (midiMessage instanceof SysexMessage) { return null; } else { -Debug.println(Level.WARNING, "not supported for delta: " + midiEventIndex + ", " + MidiUtil.paramString(midiMessage)); +logger.log(Level.WARNING, "not supported for delta: " + midiEventIndex + ", " + MidiUtil.paramString(midiMessage)); return null; } if (interval < 0) { // it shouldn't be possible - Debug.println(Level.WARNING, "interval: " + interval + ", " + midiEventIndex + ", " + MidiUtil.paramString(midiMessage)); + logger.log(Level.WARNING, "interval: " + interval + ", " + midiEventIndex + ", " + MidiUtil.paramString(midiMessage)); interval = 0; } int nopLength = interval / 255; @@ -252,7 +255,7 @@ public MfiEvent[] getIntervalMfiEvents(int mfiTrackNumber) { incrementPreviousTick(mfiTrackNumber, Math.round(255 * scale)); } -//Debug.println(nopLength + " nops inserted"); +//logger.log(Level.DEBUG, nopLength + " nops inserted"); return mfiEvents; } @@ -272,14 +275,14 @@ public int getDelta(int mfiTrackNumber) { } else if (midiMessage instanceof MetaMessage && ((MetaMessage) midiMessage).getType() == 81) { // tempo delta = retrieveAdjustedDelta(mfiTrackNumber, midiEvent.getTick()); // TODO is 0 ok? -//Debug.println("[" + midiEventIndex + "] delta for tempo, " + mfiTrackNumber + "ch: " + delta); +//logger.log(Level.DEBUG, "[" + midiEventIndex + "] delta for tempo, " + mfiTrackNumber + "ch: " + delta); } else { -Debug.println(Level.WARNING, "no delta defined for: " + MidiUtil.paramString(midiMessage)); +logger.log(Level.WARNING, "no delta defined for: " + MidiUtil.paramString(midiMessage)); } if (delta > 255) { // this is impossible because it should be handled by getIntervalMfiEvents - Debug.println(Level.SEVERE, "Δ: " + delta + ", " + (delta % 256)); + logger.log(Level.ERROR, "Δ: " + delta + ", " + (delta % 256)); } return delta % 256; } @@ -348,7 +351,7 @@ public void setMidiSequence(Sequence midiSequence) { } } this.scale = Math.ceil(this.scale); -Debug.println(Level.FINE, "(SCALE) final scale: " + scale + ", " + scaleChanged); +logger.log(Level.DEBUG, "(SCALE) final scale: " + scale + ", " + scaleChanged); for (Track midiTrack : midiTracks) { for (int i = 0; i < midiTrack.size(); i++) { @@ -437,7 +440,7 @@ public MidiEvent getNoteOffMidiEvent() throws NoSuchElementException { shortMessage.getData1() != data1 && shortMessage.getData2() == 0 && !noteOffEventUsed.get(i)) { -//Debug.println("next: " + shortMessage.getChannel() + "ch, " + shortMessage.getData1()); +//logger.log(Level.DEBUG, "next: " + shortMessage.getChannel() + "ch, " + shortMessage.getData1()); noteOffEventUsed.set(i); return midiEvent; } diff --git a/src/main/java/vavi/sound/mfi/vavi/MidiContext.java b/src/main/java/vavi/sound/mfi/vavi/MidiContext.java index 04fea19..225138d 100644 --- a/src/main/java/vavi/sound/mfi/vavi/MidiContext.java +++ b/src/main/java/vavi/sound/mfi/vavi/MidiContext.java @@ -6,15 +6,17 @@ package vavi.sound.mfi.vavi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; +import java.util.Arrays; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.MfiMessage; import vavi.sound.mfi.Track; import vavi.sound.mfi.vavi.track.TempoMessage; -import vavi.util.Debug; -//import vavi.util.StringUtil; + +import static java.lang.System.getLogger; /** @@ -27,6 +29,8 @@ */ public class MidiContext { + private static final Logger logger = getLogger(MidiContext.class.getName()); + /** */ public static final int MAX_MIDI_CHANNELS = 16; @@ -65,7 +69,7 @@ public void setMfiTrackNumber(int trackNumber) { } /** current Δ time */ - private long[] currents = new long[4]; + private final long[] currents = new long[4]; /** mfiTrackNumber must be set */ public long getCurrent() { @@ -83,12 +87,10 @@ public void addCurrent(long value) { } /** whether channel is a rhythm, index is pseudo MIDI channel */ - private ChannelConfiguration[] drums = new ChannelConfiguration[MAX_MIDI_CHANNELS]; + private final ChannelConfiguration[] drums = new ChannelConfiguration[MAX_MIDI_CHANNELS]; /* initializing */ { - for (int i = 0; i < MAX_MIDI_CHANNELS; i++) { - drums[i] = ChannelConfiguration.UNUSED; - } + Arrays.fill(drums, ChannelConfiguration.UNUSED); } /** */ @@ -102,7 +104,7 @@ public void addCurrent(long value) { */ public void setDrum(int channel, ChannelConfiguration value) { if (drumSwapChannel != CHANNEL_UNUSED && channel == drumSwapChannel) { -Debug.println(Level.FINE, "already swapped: " + channel + ", " + value); +logger.log(Level.DEBUG, "already swapped: " + channel + ", " + value); } else { drums[channel] = value; } @@ -112,18 +114,18 @@ public void setDrum(int channel, ChannelConfiguration value) { for (int k = MAX_MIDI_CHANNELS - 1; k >= 0; k--) { if (k != CHANNEL_DRUM && drums[k] == ChannelConfiguration.UNUSED) { drumSwapChannel = k; // TODO support multiple? -Debug.println(Level.FINE, "channel 9 -> " + k); +logger.log(Level.DEBUG, "channel 9 -> " + k); break; } } if (drumSwapChannel == CHANNEL_UNUSED) { -Debug.println(Level.FINE, "cannot swap: " + channel + ", " + value); +logger.log(Level.DEBUG, "cannot swap: " + channel + ", " + value); } } } /** volumes assigned to channel, index is pseudo MIDI channel */ - private int[] volumes = new int[MAX_MIDI_CHANNELS]; + private final int[] volumes = new int[MAX_MIDI_CHANNELS]; /** * @param channel pseudo MIDI channel (mfiTrackNumber * 4 + voice) @@ -147,7 +149,7 @@ public int getVolume(int channel) { } /** program numbers assigned to channel, index is real MIDI channel */ - private int[] programs = new int[MAX_MIDI_CHANNELS]; + private final int[] programs = new int[MAX_MIDI_CHANNELS]; /** * @param channel pseudo MIDI channel (mfiTrackNumber * 4 + voice) @@ -155,7 +157,7 @@ public int getVolume(int channel) { */ public int setProgram(int channel, int program) { if (channel != drumSwapChannel && drums[channel] == ChannelConfiguration.PERCUSSION) { -Debug.println(Level.FINE, "drum always zero:[" + channel + "]: " + program); +logger.log(Level.DEBUG, "drum always zero:[" + channel + "]: " + program); program = 0; } @@ -172,7 +174,7 @@ public int setProgram(int channel, int program) { */ public int setBank(int channel, int bank) { if (channel != drumSwapChannel && drums[channel] == ChannelConfiguration.PERCUSSION) { -Debug.println(Level.FINE, "drum always zero:[" + channel + "]: " + bank); +logger.log(Level.DEBUG, "drum always zero:[" + channel + "]: " + bank); bank = 0; } @@ -189,7 +191,7 @@ public int setBank(int channel, int bank) { * @param channel real MIDI channel */ public int getProgram(int channel) { -//Debug.println("program[" + channel + "]: " + programs[channel] + " (0x" + StringUtil.toHex2(programs[channel]) + ")"); +//logger.log(Level.DEBUG, "program[" + channel + "]: " + programs[channel] + " (0x" + StringUtil.toHex2(programs[channel]) + ")"); return programs[channel]; } @@ -229,11 +231,11 @@ public int retrievePitch(int channel, int pitch) { //---- /** -32 ~ 31, index is pseudo MIDI channel */ - private int[] pitchBends = new int[MAX_MIDI_CHANNELS]; + private final int[] pitchBends = new int[MAX_MIDI_CHANNELS]; /** -32 ~ 31, index is pseudo MIDI channel */ - private int[] finePitchBends = new int[MAX_MIDI_CHANNELS]; + private final int[] finePitchBends = new int[MAX_MIDI_CHANNELS]; /** 0 ~ 24, index is pseudo MIDI channel */ - private int[] pitchBendRanges = new int[MAX_MIDI_CHANNELS]; + private final int[] pitchBendRanges = new int[MAX_MIDI_CHANNELS]; /* initializing */ { for (int i = 0; i < MAX_MIDI_CHANNELS; i++) { @@ -267,7 +269,7 @@ public int retrieveRealPitch(int channel) { int pitch = // (int) ((pb * rgb * 100f / 32f) + ((fpb * rgb * 100f) / (32f * 32f))); (pb * rg * 100 / 32) + ((fpb * rg * 100) / (32 * 32)) / 20; -Debug.println(Level.FINE, "pitch[" + channel + "]: " + pitch); +logger.log(Level.DEBUG, "pitch[" + channel + "]: " + pitch); return pitch; } @@ -295,7 +297,7 @@ public int getResolution(Track[] mfiTracks) } } -Debug.println(Level.INFO, "no tempo message in track 0"); +logger.log(Level.INFO, "no tempo message in track 0"); return 48; // MFi default time base } } diff --git a/src/main/java/vavi/sound/mfi/vavi/SubMessage.java b/src/main/java/vavi/sound/mfi/vavi/SubMessage.java index abb1cb0..b615022 100644 --- a/src/main/java/vavi/sound/mfi/vavi/SubMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/SubMessage.java @@ -12,17 +12,19 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; import java.util.Properties; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MetaMessage; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * MFi Sub Chunk. @@ -52,6 +54,8 @@ */ public abstract class SubMessage extends MetaMessage { + private static final Logger logger = getLogger(SubMessage.class.getName()); + /** TODO use {@link vavi.sound.mfi.vavi.header.CodeMessage} */ protected static String readingEncoding = "JISAutoDetect"; @@ -174,7 +178,7 @@ public void writeTo(OutputStream os) throws IOException { dos.writeBytes(getSubType()); dos.writeShort(getDataLength()); dos.write(getData(), 0, getDataLength()); -Debug.println(Level.FINE, this); +logger.log(Level.DEBUG, this); } /** @@ -212,11 +216,11 @@ public static SubMessage readFrom(InputStream is) try { subChunk = constructor.newInstance(subType, subData); } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } else { -Debug.println(Level.WARNING, "unknown sub chunk: " + subType); +logger.log(Level.WARNING, "unknown sub chunk: " + subType); subChunk = new SubMessage() { { try { @@ -229,14 +233,14 @@ public static SubMessage readFrom(InputStream is) }; } -Debug.println(Level.FINE, subChunk); +logger.log(Level.DEBUG, subChunk); return subChunk; } //---- /** {@link SubMessage} constructors */ - private static Map> subChunkConstructors = new HashMap<>(); + private static final Map> subChunkConstructors = new HashMap<>(); static { try { @@ -251,7 +255,7 @@ public static SubMessage readFrom(InputStream is) if (key.matches("mfi\\.(header|audio)\\.\\w+")) { @SuppressWarnings("unchecked") Class clazz = (Class) Class.forName(props.getProperty(key)); -//Debug.println("sub class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "sub class: " + StringUtil.getClassName(clazz)); Constructor constructor = clazz.getConstructor(String.class, byte[].class); subChunkConstructors.put(key, constructor); @@ -262,15 +266,15 @@ public static SubMessage readFrom(InputStream is) String value = props.getProperty("encoding.write"); if (value != null) { writingEncoding = value; -Debug.println(Level.FINE, "write encoding: " + writingEncoding); +logger.log(Level.DEBUG, "write encoding: " + writingEncoding); } value = props.getProperty("encoding.read"); if (value != null) { readingEncoding = value; -Debug.println(Level.FINE, "read encoding: " + readingEncoding); +logger.log(Level.DEBUG, "read encoding: " + readingEncoding); } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/TrackMessage.java b/src/main/java/vavi/sound/mfi/vavi/TrackMessage.java index aa837e6..ba107d2 100644 --- a/src/main/java/vavi/sound/mfi/vavi/TrackMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/TrackMessage.java @@ -11,12 +11,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Properties; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.LongMessage; @@ -26,7 +27,8 @@ import vavi.sound.mfi.ShortMessage; import vavi.sound.mfi.SysexMessage; import vavi.sound.mfi.Track; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -41,14 +43,16 @@ */ public class TrackMessage extends MfiMessage { + private static final Logger logger = getLogger(TrackMessage.class.getName()); + /** */ public static final String TYPE = "trac"; /** */ - private Track track; + private final Track track; /** */ - private int trackNumber; + private final int trackNumber; /** for reading */ private int noteLength = -1; @@ -67,13 +71,13 @@ public TrackMessage(int trackNumber, Track track) { /** */ public void setNoteLength(int noteLength) { this.noteLength = noteLength; -Debug.println(Level.FINE, "noteLength: " + noteLength); +logger.log(Level.DEBUG, "noteLength: " + noteLength); } /** */ public void setExst(int exst) { this.exst = exst; -Debug.println(Level.FINE, "exst: " + exst); +logger.log(Level.DEBUG, "exst: " + exst); } /** @@ -86,7 +90,7 @@ public void writeTo(OutputStream os) throws IOException { dos.writeBytes(TYPE); dos.writeInt(getDataLength()); -Debug.println(Level.FINE, "track: " + trackNumber + ": " + getDataLength()); +logger.log(Level.DEBUG, "track: " + trackNumber + ": " + getDataLength()); for (int j = 0; j < track.size(); j++) { MfiEvent event = track.get(j); MfiMessage message = event.getMessage(); @@ -113,8 +117,8 @@ public int getDataLength() { trackLength += message.getLength(); } } catch (RuntimeException e) { - Debug.printStackTrace(Level.SEVERE, e); - Debug.println(Level.SEVERE, "j: " + j + ", track.size: " + track.size() + ", " + track.get(j)); + logger.log(Level.ERROR, e.getMessage(), e); + logger.log(Level.ERROR, "j: " + j + ", track.size: " + track.size() + ", " + track.get(j)); throw e; } } @@ -145,13 +149,13 @@ public void readFrom(InputStream is) dis.readFully(bytes, 0, 4); String string = new String(bytes); if (!TYPE.equals(string)) { -//Debug.println("dump:\n" + StringUtil.getDump(is, 64)); +//logger.log(Level.DEBUG, "dump:\n" + StringUtil.getDump(is, 64)); throw new InvalidMfiDataException("invalid track: " + string); } // length int trackLength = dis.readInt(); -Debug.println(Level.FINE, "trackLength[" + trackNumber + "]: " + trackLength); +logger.log(Level.DEBUG, "trackLength[" + trackNumber + "]: " + trackLength); // events int l = 0; @@ -160,7 +164,7 @@ public void readFrom(InputStream is) track.add(new MfiEvent(message, 0L)); l += message.getLength(); -//Debug.println("track[" + trackNumber + "] event length sum: " + l + " / " + trackLlength); +//logger.log(Level.DEBUG, "track[" + trackNumber + "] event length sum: " + l + " / " + trackLlength); } // @@ -177,15 +181,15 @@ private MfiMessage getMessage(DataInputStream dis) int delta = dis.readUnsignedByte(); int status = dis.readUnsignedByte(); - switch (status) { - case MfiMessage.STATUS_CLASS_A: // Class A (0x3f) - case MfiMessage.STATUS_CLASS_B: // Class B (0x7f) - case MfiMessage.STATUS_CLASS_C: // Class C (0xbf) - case MfiMessage.STATUS_NORMAL: // Normal (0xff) - return getClassOrNormalMessage(delta, status, dis); - default: // note message - return NoteMessageFactory.getMessage(delta, status, dis, noteLength); - } + return switch (status) { // Class A (0x3f) + // Class B (0x7f) + // Class C (0xbf) + case MfiMessage.STATUS_CLASS_A, MfiMessage.STATUS_CLASS_B, MfiMessage.STATUS_CLASS_C, + MfiMessage.STATUS_NORMAL -> // Normal (0xff) + getClassOrNormalMessage(delta, status, dis); + default -> // note message + NoteMessageFactory.getMessage(delta, status, dis, noteLength); + }; } /** @@ -282,12 +286,12 @@ public static MfiMessage getMessage(int delta, if (props.containsKey(key)) { @SuppressWarnings("unchecked") Class clazz = (Class) Class.forName(props.getProperty(key)); -//Debug.println("note class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "note class: " + StringUtil.getClassName(clazz)); noteMessageConstructor1 = clazz.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE); noteMessageConstructor2 = clazz.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -309,7 +313,7 @@ public static MfiMessage getMessage(int delta, int status, int data1, DataInputStream dis) throws IOException { -//Debug.println("delta: " + StringUtil.toHex2(delta)); +//logger.log(Level.DEBUG, "delta: " + StringUtil.toHex2(delta)); String key = String.format("mfi.track.%d.%c.%d", status, 'e', data1); @@ -329,7 +333,7 @@ public static MfiMessage getMessage(int delta, data2[1] = (byte) ((length % 0x100) & 0xff); dis.readFully(data2, 2, length); -Debug.printf(Level.WARNING, "sysex unhandled: delta: %02x, status: %02x, extended status: %02x\n", delta, status, data1); +logger.log(Level.WARNING, String.format("sysex unhandled: delta: %02x, status: %02x, extended status: %02x", delta, status, data1)); return UnknownMessageFactory.getMessage(delta, status, data1, data2); } } @@ -350,14 +354,14 @@ public static MfiMessage getMessage(int delta, String key = (String) o; if (key.matches("mfi\\.track\\.\\d+\\.e\\.\\d+")) { Class clazz = Class.forName(props.getProperty(key)); -//Debug.println("sysex class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "sysex class: " + StringUtil.getClassName(clazz)); Method method = clazz.getMethod("readFrom", Integer.TYPE, Integer.TYPE, Integer.TYPE, InputStream.class); sysexMessageInstantiators.put(key, method); } } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -389,7 +393,7 @@ public static MfiMessage getMessage(int delta, if (shortMessageConstructors.containsKey(key)) { constructor = shortMessageConstructors.get(key); } else { -Debug.printf(Level.WARNING, "short unhandled: delta: %02x, status: %02x, extended status: %02x\n", delta, status, data1); +logger.log(Level.WARNING, String.format("short unhandled: delta: %02x, status: %02x, extended status: %02x", delta, status, data1)); return UnknownMessageFactory.getMessage(delta, status, data1, data2); } @@ -417,7 +421,7 @@ public static MfiMessage getMessage(int delta, if (key.matches("mfi\\.track\\.\\d+\\.b\\.\\d+")) { @SuppressWarnings("unchecked") Class shortMessageClass = (Class) Class.forName(props.getProperty(key)); -//Debug.println("short class: " + StringUtil.getClassName(shortMessageClass)); +//logger.log(Level.DEBUG, "short class: " + StringUtil.getClassName(shortMessageClass)); Constructor constructor = shortMessageClass.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); shortMessageConstructors.put(key, constructor); @@ -425,7 +429,7 @@ public static MfiMessage getMessage(int delta, } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -460,7 +464,7 @@ public static MfiMessage getMessage(int delta, if (longMessageConstructors.containsKey(key)) { constructor = longMessageConstructors.get(key); } else { -Debug.printf(Level.WARNING, "long unhandled: delta: %02x, status: %02x, extended status: %02x\n", delta, status, data1); +logger.log(Level.WARNING, String.format("long unhandled: delta: %02x, status: %02x, extended status: %02x", delta, status, data1)); return UnknownMessageFactory.getMessage(delta, status, data1, data2); } @@ -472,7 +476,7 @@ public static MfiMessage getMessage(int delta, } /** constructors for creating Extended Information {@link LongMessage} object instance */ - private static Map> longMessageConstructors = new HashMap<>(); + private static final Map> longMessageConstructors = new HashMap<>(); static { try { @@ -488,14 +492,14 @@ public static MfiMessage getMessage(int delta, if (key.matches("mfi\\.track\\.\\d+\\.a\\.\\d+")) { @SuppressWarnings("unchecked") Class longMessageClass = (Class) Class.forName(props.getProperty(key)); -//Debug.println("long class: " + StringUtil.getClassName(longMessageClass)); +//logger.log(Level.DEBUG, "long class: " + StringUtil.getClassName(longMessageClass)); Constructor constructor = longMessageClass.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, byte[].class); longMessageConstructors.put(key, constructor); } } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -547,13 +551,13 @@ public static MfiMessage getMessage(int delta, if (props.containsKey(key)) { @SuppressWarnings("unchecked") Class clazz = (Class) Class.forName(props.getProperty(key)); -//Debug.println("unknown class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "unknown class: " + StringUtil.getClassName(clazz)); unknownMessageConstructor1 = clazz.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); unknownMessageConstructor2 = clazz.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, byte[].class); } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java b/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java index ef5cf2d..ddb77ba 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviMfiDeviceProvider.java @@ -7,6 +7,8 @@ package vavi.sound.mfi.vavi; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -15,7 +17,8 @@ import vavi.sound.mfi.MfiDevice; import vavi.sound.mfi.spi.MfiDeviceProvider; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,6 +31,8 @@ */ public class VaviMfiDeviceProvider extends MfiDeviceProvider { + private static final Logger logger = getLogger(VaviMfiDeviceProvider.class.getName()); + static { try { try (InputStream is = VaviMfiDeviceProvider.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound/pom.properties")) { @@ -94,7 +99,7 @@ public static MfiDevice getMfiDevice(MfiDevice.Info mfiDeviceInfo) { try { return deviceMap.get(mfiDeviceInfo).getDeclaredConstructor().newInstance(); } catch (Exception e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); } } @@ -102,7 +107,7 @@ public static MfiDevice getMfiDevice(MfiDevice.Info mfiDeviceInfo) { } /** */ - private static Map> deviceMap = new HashMap<>(); + private static final Map> deviceMap = new HashMap<>(); /* */ static { @@ -118,14 +123,14 @@ public static MfiDevice getMfiDevice(MfiDevice.Info mfiDeviceInfo) { if (key.startsWith("mfi.device.")) { @SuppressWarnings("unchecked") Class deviceClass = (Class) Class.forName(props.getProperty(key)); -//Debug.println("mfi device class: " + StringUtil.getClassName(deviceClass)); +//logger.log(Level.DEBUG, "mfi device class: " + StringUtil.getClassName(deviceClass)); MfiDevice.Info mfiDeviceInfo = deviceClass.getDeclaredConstructor().newInstance().getDeviceInfo(); deviceMap.put(mfiDeviceInfo, deviceClass); } } } catch (Exception e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileFormat.java b/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileFormat.java index b2ce2b8..bd5fb48 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileFormat.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileFormat.java @@ -9,11 +9,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MfiEvent; @@ -28,7 +29,8 @@ import vavi.sound.mfi.vavi.header.SorcMessage; import vavi.sound.mfi.vavi.header.TitlMessage; import vavi.sound.mfi.vavi.header.VersMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -81,6 +83,8 @@ */ public class VaviMfiFileFormat extends MfiFileFormat { + private static final Logger logger = getLogger(VaviMfiFileFormat.class.getName()); + /** * MIDI file type * @see "vavi/sound/midi/package.html" @@ -88,7 +92,7 @@ public class VaviMfiFileFormat extends MfiFileFormat { public static final int FILE_TYPE = 0x88; /** MFi data store of this class */ - private Sequence sequence; + private final Sequence sequence; /** */ private HeaderChunk headerChunk; @@ -119,7 +123,7 @@ public void init(Map subChunks) { MfiEvent event = track.get(j); MfiMessage message = event.getMessage(); if (message instanceof SubMessage subChunk) { - //Debug.println(infoMessage); + //logger.log(Level.DEBUG, infoMessage); subChunks.put(subChunk.getSubType(), subChunk); } } @@ -174,7 +178,7 @@ private int getAudioDataLength() { audioDataLength += message.getLength(); } } -Debug.println(Level.FINE, "audioDataLength: " + audioDataLength); +logger.log(Level.DEBUG, "audioDataLength: " + audioDataLength); return audioDataLength; } @@ -264,7 +268,7 @@ public static VaviMfiFileFormat readFrom(InputStream is) throws InvalidMfiDataEx // 2. audio data for (int audioDataNumber = 0; audioDataNumber < audioDataCount; audioDataNumber++) { -Debug.println(Level.FINE, "audio data number: " + audioDataNumber); +logger.log(Level.DEBUG, "audio data number: " + audioDataNumber); AudioDataMessage audioDataChunk = new AudioDataMessage(audioDataNumber); audioDataChunk.readFrom(is); @@ -272,12 +276,12 @@ public static VaviMfiFileFormat readFrom(InputStream is) throws InvalidMfiDataEx audioDataChunks.add(audioDataChunk); l += audioDataChunk.getLength(); -Debug.println(Level.FINE, "adat length sum: " + l + " / " + dataLength); +logger.log(Level.DEBUG, "adat length sum: " + l + " / " + dataLength); } // 3. track for (int trackNumber = 0; trackNumber < tracksCount; trackNumber++) { -Debug.println(Level.FINE, "track number: " + trackNumber); +logger.log(Level.DEBUG, "track number: " + trackNumber); Track track = mff.sequence.createTrack(); @@ -292,10 +296,10 @@ public static VaviMfiFileFormat readFrom(InputStream is) throws InvalidMfiDataEx trackChunk.readFrom(is); l += trackChunk.getLength(); -Debug.println(Level.FINE, "trac length sum: " + l + " / " + dataLength); +logger.log(Level.DEBUG, "trac length sum: " + l + " / " + dataLength); } -Debug.println(Level.FINE, "is rest: " + is.available()); +logger.log(Level.DEBUG, "is rest: " + is.available()); return mff; } @@ -359,7 +363,7 @@ public int getNoteLength() { if (subChunk != null) { return subChunk.getNoteLength(); } else { -Debug.println(Level.INFO, "no note info, use 0"); +logger.log(Level.INFO, "no note info, use 0"); return 0; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileWriter.java b/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileWriter.java index ef67dec..475f29e 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileWriter.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviMfiFileWriter.java @@ -10,15 +10,17 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.file.Files; import java.util.NoSuchElementException; import java.util.Properties; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.Sequence; import vavi.sound.mfi.spi.MfiFileWriter; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,8 +33,10 @@ */ public class VaviMfiFileWriter extends MfiFileWriter { + private static final Logger logger = getLogger(VaviMfiFileWriter.class.getName()); + /** mfi file types */ - private static int[] types = { VaviMfiFileFormat.FILE_TYPE }; + private static final int[] types = { VaviMfiFileFormat.FILE_TYPE }; /** MFi major version */ private static int defaultMajorType = HeaderChunk.MAJOR_TYPE_RING_TONE; @@ -86,7 +90,7 @@ public boolean isFileTypeSupported(int fileType, Sequence sequence) { public int write(Sequence in, int fileType, OutputStream out) throws IOException { if (!isFileTypeSupported(fileType)) { -Debug.println(Level.WARNING, "unsupported fileType: " + fileType); +logger.log(Level.WARNING, "unsupported fileType: " + fileType); return 0; } @@ -126,7 +130,7 @@ public int write(Sequence in, int fileType, OutputStream out) throws IOException try { ff.writeTo(out); } catch (InvalidMfiDataException e) { -Debug.printStackTrace(Level.WARNING, e); +logger.log(Level.WARNING, e.getMessage(), e); return 0; } @@ -152,34 +156,34 @@ public int write(Sequence in, int fileType, File out) String value = props.getProperty("format.type.major"); if (value != null) { defaultMajorType = Integer.parseInt(value); -Debug.println(Level.FINE, "major: " + defaultMajorType); +logger.log(Level.DEBUG, "major: " + defaultMajorType); } value = props.getProperty("format.type.minor"); if (value != null) { defaultMinorType = Integer.parseInt(value); -Debug.println(Level.FINE, "minor: " + defaultMinorType); +logger.log(Level.DEBUG, "minor: " + defaultMinorType); } value = props.getProperty("format.header.titl"); if (value != null) { defaultTitle = value; -Debug.println(Level.FINE, "titl: " + defaultTitle); +logger.log(Level.DEBUG, "titl: " + defaultTitle); } value = props.getProperty("format.header.prot"); if (value != null) { defaultCreator = value; -Debug.println(Level.FINE, "prot: " + defaultCreator); +logger.log(Level.DEBUG, "prot: " + defaultCreator); } value = props.getProperty("format.header.vers"); if (value != null) { defaultVersion = value; -Debug.println(Level.FINE, "vers: " + defaultVersion); +logger.log(Level.DEBUG, "vers: " + defaultVersion); } } catch (Exception e) { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviMidiConverter.java b/src/main/java/vavi/sound/mfi/vavi/VaviMidiConverter.java index 3ffc085..d534838 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviMidiConverter.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviMidiConverter.java @@ -7,10 +7,10 @@ package vavi.sound.mfi.vavi; import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.HashSet; import java.util.Set; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -29,7 +29,8 @@ import vavi.sound.mfi.vavi.track.NopMessage; import vavi.sound.midi.MidiUtil; import vavi.sound.midi.mfi.MfiVaviSequence; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -44,6 +45,8 @@ */ class VaviMidiConverter implements MidiConverter { + private static final Logger logger = getLogger(VaviMidiConverter.class.getName()); + /** the device information */ private static final MfiDevice.Info info = new MfiDevice.Info( "Java MIDI, MFi Sequence Converter", @@ -94,22 +97,22 @@ public vavi.sound.mfi.Sequence toMfiSequence(Sequence midiSequence, int fileType try { return convert(midiSequence, fileType); } catch (IOException | InvalidMfiDataException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw (InvalidMidiDataException) new InvalidMidiDataException().initCause(e); } } /* debug */ -private static Set uc = new HashSet<>(); +private static final Set uc = new HashSet<>(); /** Converts midi sequence to mfi sequence */ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) throws InvalidMfiDataException, IOException { -Debug.println(Level.FINE, "divisionType: " + midiSequence.getDivisionType()); -Debug.println(Level.FINE, "microsecondLength: " + midiSequence.getMicrosecondLength()); -Debug.println(Level.FINE, "resolution: " + midiSequence.getResolution()); -Debug.println(Level.FINE, "tickLength: " + midiSequence.getTickLength()); +logger.log(Level.DEBUG, "divisionType: " + midiSequence.getDivisionType()); +logger.log(Level.DEBUG, "microsecondLength: " + midiSequence.getMicrosecondLength()); +logger.log(Level.DEBUG, "resolution: " + midiSequence.getResolution()); +logger.log(Level.DEBUG, "tickLength: " + midiSequence.getTickLength()); // vavi.sound.mfi.Sequence mfiSequence = new vavi.sound.mfi.Sequence(); @@ -144,7 +147,7 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) for (int j = maxTracks; j <= mfiTrackNumber; j++) { mfiSequence.createTrack(); -Debug.println(Level.FINE, ">>>> create MFi track: " + j); +logger.log(Level.DEBUG, ">>>> create MFi track: " + j); mfiTracks = mfiSequence.getTracks(); maxTracks = mfiTracks.length; } @@ -170,7 +173,7 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) // master volume if (maxTracks == 0) { mfiSequence.createTrack(); -Debug.println(Level.FINE, "create MFi track: 0"); +logger.log(Level.DEBUG, "create MFi track: 0"); mfiTracks = mfiSequence.getTracks(); maxTracks = mfiTracks.length; } @@ -189,7 +192,7 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) if (maxTracks == 0) { mfiSequence.createTrack(); -Debug.println(Level.FINE, "create MFi track: 0"); +logger.log(Level.DEBUG, "create MFi track: 0"); mfiTracks = mfiSequence.getTracks(); maxTracks = mfiTracks.length; } @@ -204,7 +207,7 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) MfiConvertible converter = MfiConvertible.factory.get(key); if (converter == null) { if (!uc.contains(key)) { - Debug.println(Level.WARNING, "no converter for: [" + key + "]"); + logger.log(Level.WARNING, "no converter for: [" + key + "]"); uc.add(key); } } else if (converter instanceof EndOfTrackMessage) { // TODO ??? @@ -224,10 +227,10 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) mfiTracks[t].add(mfiEvents[t]); mfiContext.setEofSet(t, true); } else { -//Debug.println("EOF already set[" + t + "]"); +//logger.log(Level.DEBUG, "EOF already set[" + t + "]"); } } else { -Debug.println(Level.FINE, "message is null[" + mfiTracks[t].size() + "]: " + midiMessage); +logger.log(Level.DEBUG, "message is null[" + mfiTracks[t].size() + "]: " + midiMessage); } } } else { @@ -236,7 +239,7 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) if (mfiEvents != null) { for (MfiEvent mfiEvent : mfiEvents) { if (mfiEvent == null) { - Debug.println(Level.WARNING, "NOP is null[" + mfiTracks[mfiTrackNumber].size() + "]: " + MidiUtil.paramString(midiMessage)); + logger.log(Level.WARNING, "NOP is null[" + mfiTracks[mfiTrackNumber].size() + "]: " + MidiUtil.paramString(midiMessage)); } addEventToTrack(mfiContext, midiEvent.getTick(), mfiTracks[mfiTrackNumber], mfiTrackNumber, mfiEvent); } @@ -247,36 +250,38 @@ protected vavi.sound.mfi.Sequence convert(Sequence midiSequence, int fileType) if (mfiEvents != null) { for (MfiEvent mfiEvent : mfiEvents) { if (mfiEvent == null) { - Debug.println(Level.WARNING, "event is null[" + mfiTracks[mfiTrackNumber].size() + ", " + mfiEvents.length + "]: " + converter.getClass() + ", " + MidiUtil.paramString(midiMessage)); + logger.log(Level.WARNING, "event is null[" + mfiTracks[mfiTrackNumber].size() + ", " + mfiEvents.length + "]: " + converter.getClass() + ", " + MidiUtil.paramString(midiMessage)); } addEventToTrack(mfiContext, midiEvent.getTick(), mfiTracks[mfiTrackNumber], mfiTrackNumber, mfiEvent); } } } } catch (IllegalArgumentException e) { - Debug.println(Level.WARNING, e); + logger.log(Level.WARNING, e); } } return mfiSequence; } -private int[] deltas = new int[4]; - -private void addEventToTrack(MfiContext mfiContext, long tick, Track mfiTrack, int mfiTrackNumber, MfiEvent mfiEvent) { - MfiMessage mfiMessage = mfiEvent.getMessage(); - deltas[mfiTrackNumber] += mfiMessage.getDelta(); - double tickDash = deltas[mfiTrackNumber] * mfiContext.getScale(); - if ((tickDash / tick) * 100 < 95 && (tickDash / tick) * 100 != 0 && !(mfiMessage instanceof NopMessage)) -Debug.printf(Level.SEVERE, "XXXXX track: %d, tick: %d, tick': %.2f (%.2f), %d, %s\n", - mfiTrackNumber, - tick, - tickDash, - tick != 0 ? (tickDash / tick) * 100 : 0, - mfiContext.getPreviousTick(mfiTrackNumber), - mfiMessage); - mfiTrack.add(mfiEvent); +private final int[] deltas = new int[4]; + + private void addEventToTrack(MfiContext mfiContext, long tick, Track mfiTrack, int mfiTrackNumber, MfiEvent mfiEvent) { + MfiMessage mfiMessage = mfiEvent.getMessage(); + deltas[mfiTrackNumber] += mfiMessage.getDelta(); + double tickDash = deltas[mfiTrackNumber] * mfiContext.getScale(); +if ((tickDash / tick) * 100 < 95 && (tickDash / tick) * 100 != 0 && !(mfiMessage instanceof NopMessage)) { + logger.log(Level.ERROR, "XXXXX track: %d, tick: %d, tick': %.2f (%.2f), %d, %s", + mfiTrackNumber, + tick, + tickDash, + tick != 0 ? (tickDash / tick) * 100 : 0, + mfiContext.getPreviousTick(mfiTrackNumber), + mfiMessage); } + mfiTrack.add(mfiEvent); + } + //---- /** Converts mfi sequence to midi sequence */ @@ -287,7 +292,7 @@ public Sequence toMidiSequence(vavi.sound.mfi.Sequence mfiSequence) try { return convert(mfiSequence); } catch (IOException | InvalidMidiDataException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new InvalidMfiDataException(e); } } @@ -303,7 +308,7 @@ protected Sequence convert(vavi.sound.mfi.Sequence mfiSequence) MidiContext midiContext = new MidiContext(); int resolution = midiContext.getResolution(mfiTracks); -Debug.println(Level.FINE, "resolution: " + resolution); +logger.log(Level.DEBUG, "resolution: " + resolution); Sequence midiSequence = new MfiVaviSequence(Sequence.PPQ, resolution, 1); javax.sound.midi.Track midiTrack = midiSequence.getTracks()[0]; @@ -321,7 +326,7 @@ protected Sequence convert(vavi.sound.mfi.Sequence mfiSequence) midiContext.addCurrent(mfiMessage.getDelta()); if (mfiMessage instanceof MidiConvertible) { -//Debug.println("midi convertible: " + message); +//logger.log(Level.DEBUG, "midi convertible: " + message); MidiEvent[] midiEvents = ((MidiConvertible) mfiMessage).getMidiEvents(midiContext); if (midiEvents != null) { for (MidiEvent midiEvent : midiEvents) { @@ -329,9 +334,9 @@ protected Sequence convert(vavi.sound.mfi.Sequence mfiSequence) } } } else if (mfiMessage instanceof SubMessage) { -Debug.println(Level.WARNING, "ignore sequence: " + mfiMessage); +logger.log(Level.WARNING, "ignore sequence: " + mfiMessage); } else { -Debug.println(Level.WARNING, "unknown sequence: " + mfiMessage); +logger.log(Level.WARNING, "unknown sequence: " + mfiMessage); } } } diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviNoteMessage.java b/src/main/java/vavi/sound/mfi/vavi/VaviNoteMessage.java index c933351..49576e4 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviNoteMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviNoteMessage.java @@ -6,9 +6,9 @@ package vavi.sound.mfi.vavi; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.NoSuchElementException; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiEvent; import javax.sound.midi.ShortMessage; @@ -17,7 +17,8 @@ import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.NoteMessage; import vavi.sound.midi.MidiUtil; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,6 +31,8 @@ public class VaviNoteMessage extends NoteMessage implements MidiConvertible, MfiConvertible { + private static final Logger logger = getLogger(VaviNoteMessage.class.getName()); + /** MFi */ public VaviNoteMessage(int delta, int status, int data) { super(delta, status, data); @@ -64,7 +67,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) channel, pitch, velocity); -//Debug.println("note: " + channel + ": " + pitch); +//logger.log(Level.DEBUG, "note: " + channel + ": " + pitch); events[0] = new MidiEvent(shortMessage, context.getCurrent()); shortMessage = new ShortMessage(); @@ -91,14 +94,14 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) int command = shortMessage.getCommand(); int data1 = shortMessage.getData1(); int data2 = shortMessage.getData2(); -//Debug.println(midiEvent.getTick() + ", " + channel + ", " + command + ", " + (context.retrievePitch(channel, data1) + 45) + ", " + (data2 / 2)); +//logger.log(Level.DEBUG, midiEvent.getTick() + ", " + channel + ", " + command + ", " + (context.retrievePitch(channel, data1) + 45) + ", " + (data2 / 2)); if (command == ShortMessage.NOTE_OFF || // note on with velocity 0 (command == ShortMessage.NOTE_ON && data2 == 0)) { if (!context.isNoteOffEventUsed()) { -Debug.println(Level.INFO, "[" + context.getMidiEventIndex() + "] no pair of ON for: " + channel + "ch, " + data1); +logger.log(Level.INFO, "[" + context.getMidiEventIndex() + "] no pair of ON for: " + channel + "ch, " + data1); } return null; @@ -109,7 +112,7 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) try { noteOffEvent = context.getNoteOffMidiEvent(); } catch (NoSuchElementException e) { -Debug.println(Level.WARNING, "[" + context.getMidiEventIndex() + "] no pair of OFF for: " + channel + "ch, " + data1); +logger.log(Level.WARNING, "[" + context.getMidiEventIndex() + "] no pair of OFF for: " + channel + "ch, " + data1); return null; } @@ -127,24 +130,24 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) // long nextTick = nextMidiEvent.getTick(); // int nextDelta = Math.round((nextTick - currentTick) /scale); // if (length <= nextDelta) { -// Debug.println(channel + "ch, " + data1 + " len(all): " + length + ", next: " + nextDelta); +// logger.log(Level.DEBUG, channel + "ch, " + data1 + " len(all): " + length + ", next: " + nextDelta); // } else { -// Debug.println(channel + "ch, " + data1 + " len(cut): " + length + ", next: " + nextDelta); +// logger.log(Level.DEBUG, channel + "ch, " + data1 + " len(cut): " + length + ", next: " + nextDelta); // length = nextDelta; // } // } catch (NoSuchElementException e) { -// Debug.println(channel + "ch, " + data1 + " len(last): " + length); +// logger.log(Level.DEBUG, channel + "ch, " + data1 + " len(last): " + length); // } //} if (length == 0) { // if ((noteOffTick - currentTick) / scale > 0f) { - Debug.println(Level.WARNING, "length is 0 ~ 1, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); + logger.log(Level.WARNING, "length is 0 ~ 1, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); // length = 1; // } else { -// Debug.println(Level.WARNING, "length is 0, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); +// logger.log(Level.WARNING, "length is 0, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); // } } else if (length < 0) { - Debug.println(Level.WARNING, "length < 0, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); + logger.log(Level.WARNING, "length < 0, " + MidiUtil.paramString(shortMessage) + ", " + ((noteOffTick - currentTick) / scale)); } int delta = context.getDelta(context.retrieveMfiTrack(channel)); @@ -159,12 +162,12 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) mfiMessage.setGateTime(i == onLength - 1 ? length % 255 : 255); mfiMessage.setVelocity(data2 / 2); if (length >= 255) { - Debug.println(Level.INFO, channel + "ch, " + mfiMessage.getNote() + ", " + mfiMessage.getDelta() + ":[" + i + "]:" + (i == onLength - 1 ? length % 255 : 255) + "/" + length); + logger.log(Level.INFO, channel + "ch, " + mfiMessage.getNote() + ", " + mfiMessage.getDelta() + ":[" + i + "]:" + (i == onLength - 1 ? length % 255 : 255) + "/" + length); } -//Debug.println(channel + ", " + mfiMessage.getVoice() + ", " + ((mfiMessage.getMessage()[1] & 0xc0) >> 6)); +//logger.log(Level.DEBUG, channel + ", " + mfiMessage.getVoice() + ", " + ((mfiMessage.getMessage()[1] & 0xc0) >> 6)); mfiEvents[i] = new MfiEvent(mfiMessage, 0L); // TODO 0l //if (mfiEvents[i] == null) { -// Debug.println("[" + i + "]: " + mfiEvents[i]); +// logger.log(Level.DEBUG, "[" + i + "]: " + mfiEvents[i]); //} if (i == 0) { diff --git a/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java b/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java index 2a8cd85..3e8a074 100644 --- a/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/VaviSequencer.java @@ -8,8 +8,8 @@ import java.io.IOException; import java.io.InputStream; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.Instrument; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiChannel; @@ -28,7 +28,8 @@ import vavi.sound.mfi.Sequencer; import vavi.sound.mfi.Synthesizer; import vavi.sound.midi.MidiUtil; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -47,6 +48,8 @@ */ class VaviSequencer implements Sequencer, Synthesizer { + private static final Logger logger = getLogger(VaviSequencer.class.getName()); + /** the device information */ private static final MfiDevice.Info info = new MfiDevice.Info("Java MFi Sound Sequencer", @@ -76,7 +79,7 @@ public void close() { midiSequencer.close(); midiSynthesizer.close(); off(); -Debug.println("★0 close: " + midiSequencer.hashCode()); +logger.log(Level.DEBUG, "★0 close: " + midiSequencer.hashCode()); } @Override @@ -88,7 +91,7 @@ public boolean isOpen() { } /** ADPCM sequencer, TODO should be {@link javax.sound.midi.Transmitter} */ - private javax.sound.midi.MetaEventListener mea = new MetaEventAdapter(); + private final javax.sound.midi.MetaEventListener mea = new MetaEventAdapter(); @Override public void open() throws MfiUnavailableException { @@ -96,17 +99,17 @@ public void open() throws MfiUnavailableException { if (this.midiSequencer == null) { this.midiSequencer = MidiUtil.getDefaultSequencer(vavi.sound.midi.VaviMidiDeviceProvider.class); this.midiSynthesizer = MidiSystem.getSynthesizer(); -Debug.println(Level.FINE, "midiSequencer: " + midiSequencer.getClass().getName()); -Debug.println(Level.FINE, "midiSynthesizer: " + midiSynthesizer.getClass().getName()); -Debug.println("★0 init: " + midiSequencer.hashCode()); +logger.log(Level.DEBUG, "midiSequencer: " + midiSequencer.getClass().getName()); +logger.log(Level.DEBUG, "midiSynthesizer: " + midiSynthesizer.getClass().getName()); +logger.log(Level.DEBUG, "★0 init: " + midiSequencer.hashCode()); } -Debug.println("★0 open: " + midiSequencer.hashCode()); +logger.log(Level.DEBUG, "★0 open: " + midiSequencer.hashCode()); midiSequencer.open(); midiSynthesizer.open(); midiSequencer.getTransmitter().setReceiver(midiSynthesizer.getReceiver()); } catch (MidiUnavailableException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new MfiUnavailableException(e); } } @@ -120,10 +123,10 @@ public void setSequence(Sequence sequence) try { midiSequencer.setSequence(MfiSystem.toMidiSequence(sequence)); } catch (InvalidMidiDataException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new InvalidMfiDataException(e); } catch (MfiUnavailableException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -171,20 +174,20 @@ public boolean isRunning() { private void on() { midiSequencer.addMetaEventListener(mel); midiSequencer.addMetaEventListener(mea); -Debug.println("★0 on: " + midiSequencer.hashCode()); +logger.log(Level.DEBUG, "★0 on: " + midiSequencer.hashCode()); } /** */ private void off() { midiSequencer.removeMetaEventListener(mel); midiSequencer.removeMetaEventListener(mea); -Debug.println("★0 off: " + midiSequencer.hashCode()); +logger.log(Level.DEBUG, "★0 off: " + midiSequencer.hashCode()); } //------------------------------------------------------------------------- /** @see vavi.sound.mfi.MetaMessage MetaEvent */ - private MetaSupport metaSupport = new MetaSupport(); + private final MetaSupport metaSupport = new MetaSupport(); @Override public void addMetaEventListener(MetaEventListener l) { @@ -202,8 +205,8 @@ protected void fireMeta(MetaMessage meta) { } /** meta 0x2f listener */ - private javax.sound.midi.MetaEventListener mel = message -> { -Debug.println("★0 meta: type: " + message.getType()); + private final javax.sound.midi.MetaEventListener mel = message -> { +logger.log(Level.DEBUG, "★0 meta: type: " + message.getType()); switch (message.getType()) { case 0x2f: // java midi sequencer adds automatically try { @@ -212,10 +215,10 @@ protected void fireMeta(MetaMessage meta) { fireMeta(metaMessage); off(); } catch (InvalidMfiDataException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); } catch (RuntimeException | Error e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw e; } break; diff --git a/src/main/java/vavi/sound/mfi/vavi/audio/CommonAudioMessage.java b/src/main/java/vavi/sound/mfi/vavi/audio/CommonAudioMessage.java index 94a0d19..9e9642e 100644 --- a/src/main/java/vavi/sound/mfi/vavi/audio/CommonAudioMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/audio/CommonAudioMessage.java @@ -6,9 +6,10 @@ package vavi.sound.mfi.vavi.audio; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.MfiMessage; @@ -24,7 +25,8 @@ import vavi.sound.mfi.vavi.track.Nop2Message; import vavi.sound.mfi.vavi.track.TempoMessage; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -35,6 +37,8 @@ */ public class CommonAudioMessage { + private static final Logger logger = getLogger(CommonAudioMessage.class.getName()); + /** */ protected static final int maxMasterVolume = 0x7f; @@ -96,7 +100,7 @@ public static MfiEvent getTempoEvent() { /** */ private static int getDelta(float time) { float aDelta = (60f / tempoMessage.getTempo()) / tempoMessage.getTimeBase(); -Debug.println(Level.FINE, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); +logger.log(Level.DEBUG, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); return Math.round(time / aDelta); } @@ -105,7 +109,7 @@ public static List getNop2Events(float time) { List events = new ArrayList<>(); int delta = getDelta(time); -Debug.println(Level.FINE, "delta: " + delta); +logger.log(Level.DEBUG, "delta: " + delta); for (int i = 0; i < delta / Nop2Message.maxDelta; i++) { events.add(new MfiEvent(new Nop2Message(0xff, 0xff), 0L)); } @@ -117,17 +121,11 @@ public static List getNop2Events(float time) { /** */ public static List getAudioEvents(int format, byte[] data, int sampleRate, int bits, int channels) { - List events; - switch (format) { - case 0x80: - events = getAudioEventsType1(data, sampleRate, bits, channels); - break; - case 0x81: - events = getAudioEventsType2(data, sampleRate, bits, channels); - break; - default: - throw new IllegalArgumentException("undefined format: " + format); - } + List events = switch (format) { + case 0x80 -> getAudioEventsType1(data, sampleRate, bits, channels); + case 0x81 -> getAudioEventsType2(data, sampleRate, bits, channels); + default -> throw new IllegalArgumentException("undefined format: " + format); + }; return events; } diff --git a/src/main/java/vavi/sound/mfi/vavi/audio/FuetrekAudioMessage.java b/src/main/java/vavi/sound/mfi/vavi/audio/FuetrekAudioMessage.java index 28b3548..30464a5 100644 --- a/src/main/java/vavi/sound/mfi/vavi/audio/FuetrekAudioMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/audio/FuetrekAudioMessage.java @@ -6,7 +6,8 @@ package vavi.sound.mfi.vavi.audio; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.MfiMessage; @@ -14,7 +15,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.MasterVolumeMessage; import vavi.sound.mfi.vavi.track.TempoMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -25,6 +27,8 @@ */ public class FuetrekAudioMessage extends MachineDependentMessage { + private static final Logger logger = getLogger(FuetrekAudioMessage.class.getName()); + /** */ protected static final int maxMasterVolume = 0x7f; @@ -63,7 +67,7 @@ private static TempoMessage getTempoMessage(float time, int sampleRate) { float aDelta; TempoMessage message; while (true) { -Debug.printf(Level.FINE, "tempo: %d, timeBase: 0x02x\n", baseTempo, baseTimeBase); +logger.log(Level.DEBUG, String.format("tempo: %d, timeBase: 0x%02x", baseTempo, baseTimeBase)); message = new TempoMessage(0x00, 0xff, baseTimeBase, baseTempo); aDelta = (60f / message.getTempo()) / message.getTimeBase(); if (Math.round(time / aDelta) > 255) { @@ -76,7 +80,7 @@ private static TempoMessage getTempoMessage(float time, int sampleRate) { if ((baseTempo / 2) > 0) { baseTempo /= 2; } else { -Debug.println(Level.INFO, "over limit"); +logger.log(Level.INFO, "over limit"); break; } } @@ -92,7 +96,7 @@ private static TempoMessage getTempoMessage(float time, int sampleRate) { public static int getDelta(float time, int sampleRate) { TempoMessage message = getTempoMessage(time, sampleRate); float aDelta = (60f / message.getTempo()) / message.getTimeBase(); -Debug.println(Level.FINE, "a delta: " + aDelta + ", tempo: " + message.getTempo() + ", " + message.getTimeBase()); +logger.log(Level.DEBUG, "a delta: " + aDelta + ", tempo: " + message.getTempo() + ", " + message.getTimeBase()); return Math.round(time / aDelta); } @@ -109,7 +113,7 @@ public static MfiEvent getTempoEvent() { /** older version */ public static int getDelta(float time) { float aDelta = (60f / tempoMessageOld.getTempo()) / tempoMessageOld.getTimeBase(); -Debug.println(Level.FINE, "a delta: " + aDelta + ", tempo: " + tempoMessageOld.getTempo() + ", " + tempoMessageOld.getTimeBase()); +logger.log(Level.DEBUG, "a delta: " + aDelta + ", tempo: " + tempoMessageOld.getTempo() + ", " + tempoMessageOld.getTimeBase()); return Math.round(time / aDelta); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/audio/RohmAudioMessage.java b/src/main/java/vavi/sound/mfi/vavi/audio/RohmAudioMessage.java index 571a5e0..a4cb1dc 100644 --- a/src/main/java/vavi/sound/mfi/vavi/audio/RohmAudioMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/audio/RohmAudioMessage.java @@ -6,14 +6,16 @@ package vavi.sound.mfi.vavi.audio; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.MfiMessage; import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.MasterVolumeMessage; import vavi.sound.mfi.vavi.track.TempoMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -24,6 +26,8 @@ */ public class RohmAudioMessage extends MachineDependentMessage { + private static final Logger logger = getLogger(RohmAudioMessage.class.getName()); + /** */ protected static final int maxMasterVolume = 0x7f; @@ -51,7 +55,7 @@ public static MfiEvent getTempoEvent() { /** */ public static int getDelta(float time) { float aDelta = (60f / tempoMessage.getTempo()) / tempoMessage.getTimeBase(); -Debug.println(Level.FINE, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); +logger.log(Level.DEBUG, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); return Math.round(time / aDelta); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/audio/YamahaAudioMessage.java b/src/main/java/vavi/sound/mfi/vavi/audio/YamahaAudioMessage.java index 4d6b8f7..e081ac7 100644 --- a/src/main/java/vavi/sound/mfi/vavi/audio/YamahaAudioMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/audio/YamahaAudioMessage.java @@ -6,14 +6,16 @@ package vavi.sound.mfi.vavi.audio; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.MfiEvent; import vavi.sound.mfi.MfiMessage; import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.MasterVolumeMessage; import vavi.sound.mfi.vavi.track.TempoMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -24,6 +26,8 @@ */ public class YamahaAudioMessage extends MachineDependentMessage { + private static final Logger logger = getLogger(YamahaAudioMessage.class.getName()); + /** */ protected static final int maxMasterVolume = 0x7f; @@ -51,7 +55,7 @@ public static MfiEvent getTempoEvent() { /** */ public static int getDelta(float time) { float aDelta = (60f / tempoMessage.getTempo()) / tempoMessage.getTimeBase(); -Debug.println(Level.FINE, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); +logger.log(Level.DEBUG, "a delta: " + aDelta + ", tempo: " + tempoMessage.getTempo() + ", " + tempoMessage.getTimeBase()); return Math.round(time / aDelta); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/header/AinfMessage.java b/src/main/java/vavi/sound/mfi/vavi/header/AinfMessage.java index f4d1fc7..0851e3e 100644 --- a/src/main/java/vavi/sound/mfi/vavi/header/AinfMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/header/AinfMessage.java @@ -46,7 +46,7 @@ public class AinfMessage extends SubMessage { public static final String TYPE = "ainf"; /** */ - private List audioInfos = new ArrayList<>(); + private final List audioInfos = new ArrayList<>(); /** * for {@link SubMessage#readFrom(java.io.InputStream)} @@ -112,11 +112,11 @@ public static class AudioInfo { /** for {@link #toString()} */ private int index; /** */ - private int format; + private final int format; /** */ - private int length; + private final int length; /** */ - private byte[] data; + private final byte[] data; /** for creation */ public AudioInfo(int format, byte[] data) { this.format = format; diff --git a/src/main/java/vavi/sound/mfi/vavi/header/NoteMessage.java b/src/main/java/vavi/sound/mfi/vavi/header/NoteMessage.java index f71966f..3d6a67f 100644 --- a/src/main/java/vavi/sound/mfi/vavi/header/NoteMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/header/NoteMessage.java @@ -44,7 +44,7 @@ public NoteMessage(int data) { /** Length of {@link vavi.sound.mfi.NoteMessage} 1: 4byte */ public int getNoteLength() { byte[] data = getData(); -//Debug.println(data[0] * 0xff + data[1]); +//logger.log(Level.DEBUG, data[0] * 0xff + data[1]); return data[0] * 0xff + data[1]; } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function1.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function1.java index 22087d6..a14f9b9 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function1.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function1.java @@ -6,12 +6,14 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -22,6 +24,8 @@ */ public class Function1 implements MachineDependentFunction { + private static final Logger logger = getLogger(Function1.class.getName()); + /** * 0x01 Pitch Bend MFi2 only * @@ -45,6 +49,6 @@ public void process(MachineDependentMessage message) int pitchBend = data[7] & 0x3f; // -32 ~ 31 pitchBend *= (data[7] & 0x20) != 0 ? -1 : 0; // pitchBend * Pitch Bend Range * 100 / 32 [cent] -Debug.printf(Level.FINE, "Pitch Bend: %02x %d\n", voice, pitchBend); +logger.log(Level.DEBUG, String.format("Pitch Bend: %02x %d", voice, pitchBend)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function129.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function129.java index e8c9859..66afdc6 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function129.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function129.java @@ -6,12 +6,14 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -22,6 +24,8 @@ */ public class Function129 implements MachineDependentFunction { + private static final Logger logger = getLogger(Function129.class.getName()); + /** * 0x81 ADPCM volume MFi2, MFi3 * @@ -43,7 +47,7 @@ public void process(MachineDependentMessage message) this.channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 this.volume = data[7] & 0x3f; // -Debug.printf(Level.FINE, "ADPCM volume: %dch %02x\n", channel, volume); +logger.log(Level.DEBUG, String.format("ADPCM volume: %dch %02x\n", channel, volume)); } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function130.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function130.java index 468f2b2..5b6577b 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function130.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function130.java @@ -6,12 +6,14 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -22,6 +24,8 @@ */ public class Function130 implements MachineDependentFunction { + private static final Logger logger = getLogger(Function130.class.getName()); + /** * 0x82 ADPCM pan MFi2, MFi3 * @@ -43,7 +47,7 @@ public void process(MachineDependentMessage message) this.channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 this.panpot = data[7] & 0x3f; // 0x20 center -Debug.printf(Level.FINE, "ADPCM pan: %dch %02x\n", channel, panpot); +logger.log(Level.DEBUG, String.format("ADPCM pan: %dch %02x", channel, panpot)); } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function131.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function131.java index 0cc9622..b03a4a5 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function131.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function131.java @@ -6,15 +6,17 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * Mitsubishi System exclusive message function 0x83 processor. @@ -25,6 +27,8 @@ */ public class Function131 implements MachineDependentFunction { + private static final Logger logger = getLogger(Function131.class.getName()); + /** not use data immediately, store temporarily */ public static final int MODE_STORE = 0; /** use data immediately */ @@ -77,12 +81,12 @@ public void process(MachineDependentMessage message) this.continued = (data[9] & 0x01) == 1; // int adpcmLength = data.length - HEADER_LENGTH; -Debug.printf(Level.FINE, "ADPCM voice: %dch, No.%d, mode=%d, continued=%d, %d\n", channel, packetId, mode, continued, adpcmLength); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, String.format("ADPCM voice: %dch, No.%d, mode=%d, continued=%s, %d", channel, packetId, mode, continued, adpcmLength)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 32)); this.sampleRate = getSamplingRateInternal(format1); this.bits = getSamplingBitsInternal(format2); -Debug.printf(Level.FINE, "sampling: %02x: rate=%d, bits=%d\n", data[8] & 0x3f, sampleRate, bits); +logger.log(Level.DEBUG, String.format("sampling: %02x: rate=%d, bits=%d", data[8] & 0x3f, sampleRate, bits)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); @@ -140,7 +144,7 @@ protected int getSamplingRateInternal(int format1) { sampleRate = 32000; break; default: -Debug.println(Level.WARNING, "unknown sampling rate: " + format1); +logger.log(Level.WARNING, "unknown sampling rate: " + format1); break; } return sampleRate; @@ -157,7 +161,7 @@ protected int getSamplingBitsInternal(int format2) { bits = 4; break; default: -Debug.println(Level.WARNING, "unknown bits: " + format2); +logger.log(Level.WARNING, "unknown bits: " + format2); break; } return bits; @@ -202,35 +206,23 @@ public void setAdpcm(byte[] adpcm) { /** */ protected int getSamplingRateInternal() { - int format1 = 0x04; - switch (this.sampleRate) { - case 32000: - format1 = 0x14; - break; - case 16000: - format1 = 0x0c; - break; - case 8000: - format1 = 0x04; - break; - case 4000: - format1 = 0x00; - break; - } + int format1 = switch (this.sampleRate) { + case 32000 -> 0x14; + case 16000 -> 0x0c; + case 8000 -> 0x04; + case 4000 -> 0x00; + default -> 0x04; + }; return format1; } /** */ protected int getSamplingBitsInternal() { - int format2 = 0x1; - switch (this.bits) { - case 4: - format2 = 0x1; - break; - case 2: - format2 = 0x0; - break; - } + int format2 = switch (this.bits) { + case 4 -> 0x1; + case 2 -> 0x0; + default -> 0x1; + }; return format2; } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function132.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function132.java index a63844c..2440ab3 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function132.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function132.java @@ -6,13 +6,15 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * Mitsubishi System exclusive message function 0x84 processor. @@ -24,6 +26,8 @@ */ public class Function132 extends Function131 { + private static final Logger logger = getLogger(Function132.class.getName()); + /** header length of this data */ @SuppressWarnings("hiding") public static final int HEADER_LENGTH = 14; @@ -63,12 +67,12 @@ public void process(MachineDependentMessage message) data[13]; int adpcmLength = data.length - HEADER_LENGTH; -Debug.printf(Level.FINE, "ADPCM voice: " + channel + "ch, No.%d, mode=%d, continued=%d, playSize=%d, %d\n", packetId, mode, continued, length, adpcmLength); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, String.format("ADPCM voice: " + channel + "ch, No.%d, mode=%d, continued=%d, playSize=%d, %d", packetId, mode, continued, length, adpcmLength)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 32)); this.sampleRate = getSamplingRateInternal(format1); this.bits = getSamplingBitsInternal(format2); -Debug.printf(Level.FINE, "sampling: %02x: rate=%d, bits=%d\n", data[8] & 0x3f, sampleRate, bits); +logger.log(Level.DEBUG, String.format("sampling: %02x: rate=%d, bits=%d", data[8] & 0x3f, sampleRate, bits)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function143.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function143.java index bcf2c5e..5cba459 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function143.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function143.java @@ -6,14 +6,13 @@ package vavi.sound.mfi.vavi.mitsubishi; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -54,12 +53,11 @@ public void process(MachineDependentMessage message) byte[] subIdData = new byte[subIdLength]; System.arraycopy(data, index, subIdData, 0, subIdLength); index += subIdLength; -Debug.printf(Level.FINE, "ADPCM subId: %02x\n%s\n", subId, StringUtil.getDump(subIdData)); +logger.log(Level.DEBUG, String.format("ADPCM subId: %02x\n%s", subId, StringUtil.getDump(subIdData))); subIds.add(new SubIdChunk(subId, subIdData)); } } - /** */ private enum SubId { /** 1byte, 0x01: 8kHz, 0x02: 16kHz, 0x03: 32kHz */ @@ -129,7 +127,7 @@ public void setMaxParallelCue(int sample) { } /** */ - private List subIds = new ArrayList<>(); + private final List subIds = new ArrayList<>(); /** */ private static class SubIdChunk { @@ -142,19 +140,19 @@ private static class SubIdChunk { this.data = data; } /** */ - int id; + final int id; /** */ - byte[] data; + final byte[] data; } /** */ private int getSubIdsLength() { -Debug.println(Level.FINE, "subIds: " + subIds.size()); +logger.log(Level.DEBUG, "subIds: " + subIds.size()); int length = 0; for (SubIdChunk subId : subIds) { length += (1 + 1 + subId.data.length); } -Debug.println(Level.FINE, "subIds length: " + length); +logger.log(Level.DEBUG, "subIds length: " + length); return length; } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function16.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function16.java index 2bb4661..a1c2101 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function16.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function16.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -43,6 +42,6 @@ public void process(MachineDependentMessage message) int channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 int f2 = data[7] & 0x3f; // 0 ~ 31 -Debug.printf(Level.FINE, "0x10: %02x %02x\n", channel, f2); +logger.log(Level.DEBUG, String.format("0x10: %02x %02x", channel, f2)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function17.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function17.java index 72a1b1c..25b1b34 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function17.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function17.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -43,6 +42,6 @@ public void process(MachineDependentMessage message) int channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 int f2 = data[7] & 0x3f; // 0 ~ 31 -Debug.printf(Level.FINE, "0x11: %02x %02x\n", channel, f2); +logger.log(Level.DEBUG, String.format("0x11: %02x %02x", channel, f2)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function2.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function2.java index 6f829b7..68817ab 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function2.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function2.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -43,6 +42,6 @@ public void process(MachineDependentMessage message) int voice = (data[7] & 0xc0) >> 6; // 0 ~ 3 int pitchBendRange = data[7] & 0x3f; // 0 ~ 16 -Debug.printf(Level.FINE, "Pitch Bend Range: %02x %02x\n", voice, pitchBendRange); +logger.log(Level.DEBUG, String.format("Pitch Bend Range: %02x %02x", voice, pitchBendRange)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function3.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function3.java index daefa6a..b232f30 100755 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function3.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/Function3.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -43,6 +42,6 @@ public void process(MachineDependentMessage message) int voice = (data[7] & 0xc0) >> 6; // 0 ~ 3 int modulation = data[7] & 0x3f; // 0 ~ 63 -Debug.printf(Level.FINE, "Vibrato: %d %02x\n", voice, modulation); +logger.log(Level.DEBUG, String.format("Vibrato: %d %02x", voice, modulation)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiMessage.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiMessage.java index 52f9053..7d744e7 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiMessage.java @@ -6,9 +6,10 @@ package vavi.sound.mfi.vavi.mitsubishi; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MfiEvent; @@ -16,7 +17,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.Nop2Message; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,6 +33,8 @@ */ public final class MitsubishiMessage extends FuetrekAudioMessage { + private static final Logger logger = getLogger(MitsubishiMessage.class.getName()); + /** wave length, use 0x83, 4bit in ADPCM, mono */ private static final int MAX_BLOCK = 0xffff - Function131.HEADER_LENGTH; @@ -51,19 +55,19 @@ public final class MitsubishiMessage extends FuetrekAudioMessage { */ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRate, int bits, int channels) throws InvalidMfiDataException { int delta = getDelta(time); -Debug.println(Level.FINE, "delta: " + delta); +logger.log(Level.DEBUG, "delta: " + delta); AudioEngine audioEngine = MitsubishiSequencer.getAudioEngine(); byte[] adpcm = audioEngine.encode(bits, channels, pcm); -Debug.println(Level.FINE, "adpcm mono length: " + adpcm.length); +logger.log(Level.DEBUG, "adpcm mono length: " + adpcm.length); List events = new ArrayList<>(); if (channels == 1) { -Debug.println(Level.FINE, "adpcm length: " + adpcm.length); +logger.log(Level.DEBUG, "adpcm length: " + adpcm.length); events.addAll(getAdpcmEventsSub(L, 0, sampleRate, bits, adpcm)); // 0x83 adpcm recycle events.add(getWaveEvent(L, 0, sampleRate, bits)); } else { byte[] temp = new byte[adpcm.length / 2]; -Debug.println(Level.FINE, "adpcm L, R length: " + temp.length); +logger.log(Level.DEBUG, "adpcm L, R length: " + temp.length); System.arraycopy(adpcm, 0, temp, 0, adpcm.length / 2); events.addAll(getAdpcmEventsSub(L, 0, sampleRate, bits, temp)); System.arraycopy(adpcm, adpcm.length / 2, temp, 0, adpcm.length / 2); @@ -98,7 +102,7 @@ private static List getAdpcmEventsSub(int channel, int packetId, int s for (int i = 0; i < numberOfChunks; i++) { byte[] chunk = new byte[MAX_BLOCK]; System.arraycopy(adpcm, MAX_BLOCK * i, chunk, 0, MAX_BLOCK); -Debug.println(Level.FINE, "wave chunk(" + i + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + i + "): " + chunk.length); // 0x83 adpcm data events.add(getWaveEvent(channel, packetId, sampleRate, bits, !(i == (numberOfChunks - 1) && moduloOfChunks == 0), chunk)); @@ -106,7 +110,7 @@ private static List getAdpcmEventsSub(int channel, int packetId, int s if (moduloOfChunks != 0) { byte[] chunk = new byte[moduloOfChunks]; System.arraycopy(adpcm, MAX_BLOCK * numberOfChunks, chunk, 0, moduloOfChunks); -Debug.println(Level.FINE, "wave chunk(" + numberOfChunks + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + numberOfChunks + "): " + chunk.length); // 0x83 adpcm data events.add(getWaveEvent(channel, packetId, sampleRate, bits, false, chunk)); diff --git a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiSequencer.java b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiSequencer.java index 5cea042..936ac75 100644 --- a/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/mitsubishi/MitsubishiSequencer.java @@ -6,7 +6,8 @@ package vavi.sound.mfi.vavi.mitsubishi; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; @@ -14,7 +15,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; import vavi.sound.mobile.FuetrekAudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,6 +33,8 @@ */ public class MitsubishiSequencer implements MachineDependentSequencer { + private static final Logger logger = getLogger(MitsubishiSequencer.class.getName()); + /** * * @param message see below @@ -41,20 +45,20 @@ public void sequence(MachineDependentMessage message) byte[] data = message.getMessage(); int function = data[6] & 0xff; -Debug.printf(Level.FINER, "function: 0x%02x", function); +logger.log(Level.TRACE, String.format("function: 0x%02x", function)); MachineDependentFunction mdf = factory.getFunction(String.valueOf(function)); if (mdf != null) { mdf.process(message); } else { -Debug.printf(Level.WARNING, "unsupported function: 0x%02x", function); +logger.log(Level.WARNING, String.format("unsupported function: 0x%02x", function)); } } //------------------------------------------------------------------------- /** */ - private static AudioEngine player = new FuetrekAudioEngine(); + private static final AudioEngine player = new FuetrekAudioEngine(); /** */ static AudioEngine getAudioEngine() { @@ -64,6 +68,6 @@ static AudioEngine getAudioEngine() { //------------------------------------------------------------------------- /** */ - private static MachineDependentFunction.Factory factory = + private static final MachineDependentFunction.Factory factory = new MachineDependentFunction.Factory("/vavi/sound/mfi/vavi/mitsubishi/mitsubishi.properties"); } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_240_7.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_240_7.java index cd192e4..66b11f3 100755 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_240_7.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_240_7.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -65,8 +64,8 @@ public void process(MachineDependentMessage message) this.sampleRate = ((data[11] & 0xff) << 8) + (data[12] & 0xff); // 4000 ~ 16000 (make it half when stereo) int adpcmLength = data.length - HEADER_LENGTH; -Debug.println(Level.FINE, "ADPCM: No." + streamNumber + ", " + sampleRate + "Hz, " + adpcmLength + " bytes, " + (mono ? "mono" : "stereo") + ", " + format); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, "ADPCM: No." + streamNumber + ", " + sampleRate + "Hz, " + adpcmLength + " bytes, " + (mono ? "mono" : "stereo") + ", " + format); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 32)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_3.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_3.java index 65af971..6413385 100755 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_3.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_3.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -55,7 +54,7 @@ public void process(MachineDependentMessage message) this.streamNumber = data[ 9] & 0x1f; // stream number 0 ~ 31 this.velocity = data[10] & 0x7f; // 0 ~ 127 -Debug.println(Level.FINE, "StreamOn: " + channel + "ch, No." + streamNumber + ", velocity=" + velocity); +logger.log(Level.DEBUG, "StreamOn: " + channel + "ch, No." + streamNumber + ", velocity=" + velocity); NecSequencer.getAudioEngine().start(streamNumber); } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_4.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_4.java index 827516f..80161c6 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_4.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_4.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -55,7 +54,7 @@ public void process(MachineDependentMessage message) this.streamNumber = data[ 9] & 0x1f; // stream number 0 ~ 31 this.velocity = data[10] & 0x7f; // 0 ~ 127 -Debug.println(Level.FINE, "StreamSlaveOn: " + channel + "ch, No." + streamNumber + ", velocity=" + velocity); +logger.log(Level.DEBUG, "StreamSlaveOn: " + channel + "ch, No." + streamNumber + ", velocity=" + velocity); NecSequencer.getAudioEngine().start(streamNumber); } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_5.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_5.java index 8ee4186..1e4ab22 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_5.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_5.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -51,7 +50,7 @@ public void process(MachineDependentMessage message) this.channel = (data[8] & 0xc0) >> 6; // this.streamNumber = data[9] & 0x1f; // stream number 0 ~ 31 -Debug.println(Level.FINE, "StreamOff: " + channel + "ch, No." + streamNumber); +logger.log(Level.DEBUG, "StreamOff: " + channel + "ch, No." + streamNumber); NecSequencer.getAudioEngine().stop(streamNumber); // TODO channel ??? } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_6.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_6.java index cb614d3..cb4ed6c 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_6.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_241_6.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -53,7 +52,7 @@ public void process(MachineDependentMessage message) this.streamNumber = data[ 9] & 0x1f; // stream number 0 ~ 31 this.pan = data[10]; // pan -Debug.println(Level.FINE, "StreamPan: " + channel + "ch, No." + streamNumber + ", pan: " + pan); +logger.log(Level.DEBUG, "StreamPan: " + channel + "ch, No." + streamNumber + ", pan: " + pan); } /** channel 0 ~ 3 */ diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_3.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_3.java index d5c9b1e..186db1f 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_3.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_3.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -51,7 +50,7 @@ public void process(MachineDependentMessage message) this.maxGain = data[9]; -Debug.println(Level.FINE, "MaxGain: " + maxGain); +logger.log(Level.DEBUG, "MaxGain: " + maxGain); } /** 0 ~ 96 (-96db) */ diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_4.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_4.java index b6aac30..010564a 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_4.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function1_243_4.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -52,7 +51,7 @@ public void process(MachineDependentMessage message) this.maxStreamNumber = data[9] & 0x03; -Debug.println(Level.FINE, "maxStreamNumber: " + maxStreamNumber); +logger.log(Level.DEBUG, "maxStreamNumber: " + maxStreamNumber); } /** 0 ~ 2, default 0 */ diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function240_1.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function240_1.java index abbb9f6..9120709 100755 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function240_1.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function240_1.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -45,7 +44,7 @@ public void process(MachineDependentMessage message) byte[] data = message.getMessage(); int channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 -Debug.println(Level.FINE, "FM voice change: " + channel); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, "FM voice change: " + channel); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 32)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function240_2.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function240_2.java index 58d7d4e..2eedb53 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function240_2.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function240_2.java @@ -6,13 +6,12 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -66,8 +65,8 @@ public void process(MachineDependentMessage message) } int adpcmLength = data.length - HEADER_LENGTH; -Debug.println(Level.FINE, "ADPCM data: No." + streamNumber + ", " + sampleRate + "Hz, " + adpcmLength); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 64)); +logger.log(Level.DEBUG, "ADPCM data: No." + streamNumber + ", " + sampleRate + "Hz, " + adpcmLength); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 64)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); @@ -105,7 +104,7 @@ public byte[] getMessage() throws InvalidMfiDataException { AudioEngine audioEngine = NecSequencer.getAudioEngine(); adpcm = audioEngine.encode(4, 1, pcm); // TODO bits, channel -Debug.println(Level.FINE, "adpcm length: " + adpcm.length); +logger.log(Level.DEBUG, "adpcm length: " + adpcm.length); // [10~] byte[] tmp = new byte[adpcm.length + 5]; diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_0.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_0.java index 5503319..cdaf05d 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_0.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_0.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -44,7 +43,7 @@ public void process(MachineDependentMessage message) throws InvalidMfiDataException { byte[] data = message.getMessage(); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(data, 64)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 64)); this.channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 this.streamNumber = data[8] & 0xff; // stream number 0 ~ 31 diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_1.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_1.java index 529c7dc..73964d2 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_1.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_1.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -46,7 +45,7 @@ public void process(MachineDependentMessage message) int channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 // 8 vibrato -Debug.println(Level.FINE, "Vibrato: " + channel + ", " + data[8]); -Debug.println(Level.FINEST, "\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, "Vibrato: " + channel + ", " + data[8]); +logger.log(Level.TRACE, "\n" + StringUtil.getDump(data, 32)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_2.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_2.java index 61937bd..a38309d 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function241_2.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function241_2.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -46,7 +45,7 @@ public void process(MachineDependentMessage message) int channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 // 8 pitch bend -Debug.println(Level.FINE, "Pitch Bend: " + channel + ", " + data[8]); -Debug.println(Level.FINEST, StringUtil.getDump(data)); +logger.log(Level.DEBUG, "Pitch Bend: " + channel + ", " + data[8]); +logger.log(Level.TRACE, StringUtil.getDump(data)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_1.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_1.java index 5bf0800..172e2d8 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_1.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_1.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -48,7 +47,7 @@ public void process(MachineDependentMessage message) this.volume = data[8] & 0x3f; // // 8 volume -Debug.println(Level.FINE, "ADPCM volume: " + volume); +logger.log(Level.DEBUG, "ADPCM volume: " + volume); } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_4.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_4.java index 1969e72..06342b4 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_4.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_4.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -47,7 +46,7 @@ public void process(MachineDependentMessage message) // 8 ? // 9 ? 00 -Debug.println(Level.FINE, "Vibrator: " + channel); -Debug.println(Level.FINEST, StringUtil.getDump(data)); +logger.log(Level.DEBUG, "Vibrator: " + channel); +logger.log(Level.TRACE, StringUtil.getDump(data)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_5.java b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_5.java index 1404ff1..9bd725b 100755 --- a/src/main/java/vavi/sound/mfi/vavi/nec/Function242_5.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/Function242_5.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -47,7 +46,7 @@ public void process(MachineDependentMessage message) // 8 ? // 9 ? 00 -Debug.println(Level.FINE, "LED: " + channel); -Debug.println(Level.FINE, StringUtil.getDump(data)); +logger.log(Level.DEBUG, "LED: " + channel); +logger.log(Level.DEBUG, StringUtil.getDump(data)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/NecMessage.java b/src/main/java/vavi/sound/mfi/vavi/nec/NecMessage.java index f12a2b3..d79de79 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/NecMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/NecMessage.java @@ -6,9 +6,10 @@ package vavi.sound.mfi.vavi.nec; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MfiEvent; @@ -16,7 +17,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.Nop2Message; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,17 +30,19 @@ */ public class NecMessage extends YamahaAudioMessage { + private static final Logger logger = getLogger(NecMessage.class.getName()); + /** wave length, use (0x01, 0xf0, 0x07), 4bit in ADPCM, mono */ - private static int MAX_BLOCK = 0xffff - Function1_240_7.HEADER_LENGTH; + private static final int MAX_BLOCK = 0xffff - Function1_240_7.HEADER_LENGTH; /** */ - private static ThreadLocal sequence = new ThreadLocal<>(); + private static final ThreadLocal sequence = new ThreadLocal<>(); /** thread local sequence */ private static void initSequence() { if (sequence.get() == null) { sequence.set(0); -Debug.println(Level.FINER, "thread local sequence: init"); +logger.log(Level.TRACE, "thread local sequence: init"); } } @@ -50,7 +54,7 @@ private static MfiEvent getStreamOn(int streamNumber, int velocity) throws Inval } /** */ - private static int PCM_MAX_BLOCK = MAX_BLOCK * 4; + private static final int PCM_MAX_BLOCK = MAX_BLOCK * 4; /** */ private static final int maxVelocity = 0x7f; @@ -71,7 +75,7 @@ private static MfiEvent getStreamOn(int streamNumber, int velocity) throws Inval */ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRate, int bits, int channels, int adpcmVolume) throws InvalidMfiDataException { int delta = getDelta(time); -Debug.println(Level.FINE, "delta: " + delta + ", time: " + time); +logger.log(Level.DEBUG, "delta: " + delta + ", time: " + time); int velocity = (int) (adpcmVolume * maxVelocity / 100f); AudioEngine audioEngine = NecSequencer.getAudioEngine(); @@ -88,7 +92,7 @@ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRa System.arraycopy(pcm, (PCM_MAX_BLOCK * channels) * i, temp, 0, PCM_MAX_BLOCK * channels); byte[] chunk = audioEngine.encode(4, channels, temp); if (channels == 1) { -Debug.println(Level.FINE, "wave chunk(" + i + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + i + "): " + chunk.length); // adpcm data events.add(getVoiceEvent(streamNumber++, channels, sampleRate, chunk)); @@ -97,13 +101,13 @@ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRa byte[] chunkM = new byte[chunk.length / 2]; System.arraycopy(chunk, 0, chunkM, 0, chunkM.length); -Debug.println(Level.FINE, "wave l chunk(" + i + "): " + chunkM.length); +logger.log(Level.DEBUG, "wave l chunk(" + i + "): " + chunkM.length); // adpcm data L events.add(getVoiceEvent(streamNumber++, 1, sampleRate, chunkM)); // TODO channel is 1 System.arraycopy(chunk, chunkM.length, chunkM, 0, chunkM.length); -Debug.println(Level.FINE, "wave r chunk(" + i + "): " + chunkM.length); +logger.log(Level.DEBUG, "wave r chunk(" + i + "): " + chunkM.length); // adpcm data R events.add(getVoiceEvent(streamNumber++, 1, sampleRate, chunkM)); // TODO channel is 1 @@ -114,7 +118,7 @@ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRa System.arraycopy(pcm, (PCM_MAX_BLOCK * channels) * numberOfChunks, temp, 0, moduloOfChunks); byte[] chunk = audioEngine.encode(4, channels, temp); if (channels == 1) { -Debug.println(Level.FINE, "wave chunk(" + numberOfChunks + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + numberOfChunks + "): " + chunk.length); // adpcm data events.add(getVoiceEvent(streamNumber++, channels, sampleRate, chunk)); @@ -123,13 +127,13 @@ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRa byte[] chunkM = new byte[chunk.length / 2]; System.arraycopy(chunk, 0, chunkM, 0, chunkM.length); -Debug.println(Level.FINE, "wave l chunk(" + numberOfChunks + "): " + chunkM.length); +logger.log(Level.DEBUG, "wave l chunk(" + numberOfChunks + "): " + chunkM.length); // adpcm data L events.add(getVoiceEvent(streamNumber++, 1, sampleRate, chunkM)); // TODO channel is 1 System.arraycopy(chunk, chunkM.length, chunkM, 0, chunkM.length); -Debug.println(Level.FINE, "wave r chunk(" + numberOfChunks + "): " + chunkM.length); +logger.log(Level.DEBUG, "wave r chunk(" + numberOfChunks + "): " + chunkM.length); // adpcm data R events.add(getVoiceEvent(streamNumber++, 1, sampleRate, chunkM)); // TODO channel is 1 @@ -319,14 +323,14 @@ public static MfiEvent getPanEvent(int channel, int streamNumber, int pan) throw */ public static List getAdpcmEventsEx(byte[] pcm, float time, int sampleRate, int bits, int channels, int adpcmVolume) throws InvalidMfiDataException { int delta = getDelta(time); -Debug.println(Level.FINE, "delta: " + delta + ", time: " + time); +logger.log(Level.DEBUG, "delta: " + delta + ", time: " + time); int velocity = (int) (adpcmVolume * maxVelocity / 100f); AudioEngine audioEngine = NecSequencer.getAudioEngine(); byte[] adpcm = audioEngine.encode(4, channels, pcm); -Debug.println(Level.FINE, "adpcm length: " + adpcm.length); -//System.err.println("pcm:\n" + StringUtil.getDump(pcm, 64) + "adpcm L:\n" + StringUtil.getDump(adpcm, 64) +"adpcm R:\n" + StringUtil.getDump(adpcm, adpcm.length / 2, 64)); +logger.log(Level.DEBUG, "adpcm length: " + adpcm.length); +//logger.log(Level.DEBUG, "pcm:\n" + StringUtil.getDump(pcm, 64) + "adpcm L:\n" + StringUtil.getDump(adpcm, 64) +"adpcm R:\n" + StringUtil.getDump(adpcm, adpcm.length / 2, 64)); int numberOfChunks = adpcm.length / MAX_BLOCK; int moduloOfChunks = adpcm.length % MAX_BLOCK; @@ -343,7 +347,7 @@ public static List getAdpcmEventsEx(byte[] pcm, float time, int sample System.arraycopy(adpcm, (MAX_BLOCK / 2) * i, chunk, 0, MAX_BLOCK / 2); System.arraycopy(adpcm, (adpcm.length / 2) + (MAX_BLOCK / 2) * i, chunk, MAX_BLOCK / 2, MAX_BLOCK / 2); } -Debug.println(Level.FINE, "wave chunk(" + i + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + i + "): " + chunk.length); // adpcm data events.add(getVoiceEvent(streamNumber++, channels, sampleRate, chunk)); @@ -356,7 +360,7 @@ public static List getAdpcmEventsEx(byte[] pcm, float time, int sample System.arraycopy(adpcm, (MAX_BLOCK / 2) * numberOfChunks, chunk, 0, moduloOfChunks / 2); System.arraycopy(adpcm, (adpcm.length / 2) + (MAX_BLOCK / 2) * numberOfChunks, chunk, moduloOfChunks / 2, moduloOfChunks / 2); } -Debug.println(Level.FINE, "wave chunk(" + numberOfChunks + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + numberOfChunks + "): " + chunk.length); // adpcm data events.add(getVoiceEvent(streamNumber++, channels, sampleRate, chunk)); @@ -368,7 +372,7 @@ public static List getAdpcmEventsEx(byte[] pcm, float time, int sample streamNumber = 0; for (int i = 0; i < numberOfChunks; i++) { // adpcm on -Debug.println(Level.FINER, "thread local sequence: " + sequence.get()); +logger.log(Level.TRACE, "thread local sequence: " + sequence.get()); events.add(getStreamOn(streamNumber++, velocity)); // nop2 for (int j = 0; j < blockDelta / Nop2Message.maxDelta; j++) { @@ -381,7 +385,7 @@ public static List getAdpcmEventsEx(byte[] pcm, float time, int sample } if (moduloOfChunks != 0) { // adpcm on -Debug.println(Level.FINER, "thread local sequence: " + sequence.get()); +logger.log(Level.TRACE, "thread local sequence: " + sequence.get()); events.add(getStreamOn(streamNumber++, velocity)); // nop2 int moduloOfBlockDelta = delta % blockDelta; diff --git a/src/main/java/vavi/sound/mfi/vavi/nec/NecSequencer.java b/src/main/java/vavi/sound/mfi/vavi/nec/NecSequencer.java index bf42f56..0cccfc5 100644 --- a/src/main/java/vavi/sound/mfi/vavi/nec/NecSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/nec/NecSequencer.java @@ -6,7 +6,8 @@ package vavi.sound.mfi.vavi.nec; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; @@ -14,7 +15,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; import vavi.sound.mobile.YamahaAudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -32,6 +34,8 @@ */ public class NecSequencer implements MachineDependentSequencer { + private static final Logger logger = getLogger(NecSequencer.class.getName()); + /** * * @param message see below @@ -60,11 +64,11 @@ public void sequence(MachineDependentMessage message) if (f1 == 0x01) { f2 = data[7] & 0xff; // 0 ~ 32 int f3 = data[8] & 0x0f; // 0 ~ 16 -Debug.printf(Level.FINE, "%02x %02x %02x\n", f1, f2, f3); +logger.log(Level.DEBUG, String.format("%02x %02x %02x", f1, f2, f3)); key = f1 + "." + f2 + "." + f3; } else { f2 = data[7] & 0x0f; // 0 ~ 16 -Debug.printf(Level.FINE, "%02x %02x\n", f1, f2); +logger.log(Level.DEBUG, String.format("%02x %02x", f1, f2)); key = f1 + "." + f2; } @@ -72,14 +76,14 @@ public void sequence(MachineDependentMessage message) if (mdf != null) { mdf.process(message); } else { -Debug.printf(Level.WARNING, "unsupported function: %s", key); +logger.log(Level.WARNING, String.format("unsupported function: %s", key)); } } //------------------------------------------------------------------------- /** */ - private static AudioEngine player = new YamahaAudioEngine(); + private static final AudioEngine player = new YamahaAudioEngine(); /** */ static AudioEngine getAudioEngine() { @@ -89,6 +93,6 @@ static AudioEngine getAudioEngine() { //------------------------------------------------------------------------- /** */ - private static MachineDependentFunction.Factory factory = + private static final MachineDependentFunction.Factory factory = new MachineDependentFunction.Factory("/vavi/sound/mfi/vavi/nec/nec.properties"); } diff --git a/src/main/java/vavi/sound/mfi/vavi/sequencer/AudioDataSequencer.java b/src/main/java/vavi/sound/mfi/vavi/sequencer/AudioDataSequencer.java index dcc3d98..a07618a 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sequencer/AudioDataSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/sequencer/AudioDataSequencer.java @@ -34,7 +34,7 @@ public interface AudioDataSequencer { class Factory extends PrefixedClassPropertiesFactory { /** */ - private static ThreadLocal audioEngineStore = new ThreadLocal<>(); + private static final ThreadLocal audioEngineStore = new ThreadLocal<>(); /** * Second time or later. @@ -55,7 +55,7 @@ public static AudioEngine getAudioEngine(int format) { } /** */ - private static Factory instance = new Factory(); + private static final Factory instance = new Factory(); /** */ private Factory() { diff --git a/src/main/java/vavi/sound/mfi/vavi/sequencer/MachineDependentFunction.java b/src/main/java/vavi/sound/mfi/vavi/sequencer/MachineDependentFunction.java index 8cc20f2..196ac60 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sequencer/MachineDependentFunction.java +++ b/src/main/java/vavi/sound/mfi/vavi/sequencer/MachineDependentFunction.java @@ -6,13 +6,15 @@ package vavi.sound.mfi.vavi.sequencer; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.properties.PrefixedClassPropertiesFactory; +import static java.lang.System.getLogger; + /** * Sub sequencer for machine dependent system exclusive message. @@ -30,6 +32,8 @@ */ public interface MachineDependentFunction { + Logger logger = getLogger(MachineDependentFunction.class.getName()); + int VENDOR_NEC = 0x10; // N int VENDOR_FUJITSU = 0x20; // F int VENDOR_SONY = 0x30; // SO @@ -60,8 +64,8 @@ public MachineDependentFunction getFunction(String key) { try { return get(key); } catch (IllegalArgumentException e) { -Debug.println(Level.WARNING, key); -Debug.printStackTrace(Level.WARNING, e); +logger.log(Level.WARNING, key); +logger.log(Level.WARNING, e.getMessage(), e); return new UndefinedFunction(); // TODO should throw exception or not? } } diff --git a/src/main/java/vavi/sound/mfi/vavi/sequencer/MfiMessageStore.java b/src/main/java/vavi/sound/mfi/vavi/sequencer/MfiMessageStore.java index da28993..e1745fe 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sequencer/MfiMessageStore.java +++ b/src/main/java/vavi/sound/mfi/vavi/sequencer/MfiMessageStore.java @@ -27,7 +27,7 @@ public class MfiMessageStore { private static int currentId = 0; /** */ - private static Map stores = new HashMap<>(); + private static final Map stores = new HashMap<>(); private MfiMessageStore() { } diff --git a/src/main/java/vavi/sound/mfi/vavi/sequencer/UndefinedFunction.java b/src/main/java/vavi/sound/mfi/vavi/sequencer/UndefinedFunction.java index 329dc54..9c7f9e2 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sequencer/UndefinedFunction.java +++ b/src/main/java/vavi/sound/mfi/vavi/sequencer/UndefinedFunction.java @@ -6,11 +6,11 @@ package vavi.sound.mfi.vavi.sequencer; -import java.util.logging.Level; + +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -45,13 +45,13 @@ public void process(MachineDependentMessage message) int f3; if (data.length > 8) { f3 = data[8] & 0xff; -Debug.printf(Level.INFO, "undefined function: %02x %02x %02x\n", f1, f2, f3); +logger.log(Level.INFO, String.format("undefined function: %02x %02x %02x", f1, f2, f3)); } else if (data.length > 7) { f2 = data[7] & 0xff; -Debug.printf(Level.INFO, "undefined function: %02x %02x\n", f1, f2); +logger.log(Level.INFO, String.format("undefined function: %02x %02x", f1, f2)); } else { -Debug.printf(Level.INFO, "undefined function: %02x \n", f1); +logger.log(Level.INFO, String.format("undefined function: %02x", f1)); } -Debug.println(Level.INFO, StringUtil.getDump(message.getMessage(), 128)); +logger.log(Level.INFO, StringUtil.getDump(message.getMessage(), 128)); } } diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/Function129.java b/src/main/java/vavi/sound/mfi/vavi/sharp/Function129.java index c34a601..d1940e1 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/Function129.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/Function129.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.sharp; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -48,7 +47,7 @@ public void process(MachineDependentMessage message) this.channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 this.volume = data[7] & 0x3f; // -Debug.printf(Level.FINE, "ADPCM volume: %dch %02x\n", channel, volume); +logger.log(Level.DEBUG, String.format("ADPCM volume: %dch %02x", channel, volume)); } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/Function130.java b/src/main/java/vavi/sound/mfi/vavi/sharp/Function130.java index 8660e0d..2ec36be 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/Function130.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/Function130.java @@ -6,12 +6,11 @@ package vavi.sound.mfi.vavi.sharp; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; /** @@ -48,7 +47,7 @@ public void process(MachineDependentMessage message) this.channel = (data[7] & 0xc0) >> 6; // 0 ~ 3 this.panpot = data[7] & 0x3f; // 0x20 center -Debug.printf(Level.FINE, "ADPCM pan: %dch %02x\n", channel, panpot); +logger.log(Level.DEBUG, String.format("ADPCM pan: %dch %02x", channel, panpot)); } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/Function131.java b/src/main/java/vavi/sound/mfi/vavi/sharp/Function131.java index e6b7b35..e15d905 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/Function131.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/Function131.java @@ -6,13 +6,12 @@ package vavi.sound.mfi.vavi.sharp; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -77,12 +76,12 @@ public void process(MachineDependentMessage message) this.continued = (data[9] & 0x01) == 1; // int adpcmLength = data.length - HEADER_LENGTH; -Debug.printf(Level.FINE, "ADPCM voice: %dch, No.%d, mode=%d, continued=%d, %d\n", channel, packetId, mode, continued, adpcmLength); -Debug.println(Level.FINER, "data:\n" + StringUtil.getDump(data)); +logger.log(Level.DEBUG, String.format("ADPCM voice: %dch, No.%d, mode=%d, continued=%s, %d", channel, packetId, mode, continued, adpcmLength)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data)); this.sampleRate = getSamplingRateInternal(format1); this.bits = getSamplingBitsInternal(format2); -Debug.printf(Level.FINE, "sampling: %02x: rate=%d, bits=%d\n", data[8] & 0x3f, sampleRate, bits); +logger.log(Level.DEBUG, String.format("sampling: %02x: rate=%d, bits=%d", data[8] & 0x3f, sampleRate, bits)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); @@ -140,7 +139,7 @@ protected int getSamplingRateInternal(int format1) { sampleRate = 32000; break; default: -Debug.println(Level.WARNING, "unknown sampling rate: " + format1); +logger.log(Level.WARNING, "unknown sampling rate: " + format1); break; } return sampleRate; @@ -157,7 +156,7 @@ protected int getSamplingBitsInternal(int format2) { bits = 4; break; default: -Debug.println(Level.WARNING, "unknown bits: " + format2); +logger.log(Level.WARNING, "unknown bits: " + format2); break; } return bits; @@ -202,35 +201,23 @@ public void setAdpcm(byte[] adpcm) { /** */ protected int getSamplingRateInternal() { - int format1 = 0x04; - switch (this.sampleRate) { - case 32000: - format1 = 0x14; - break; - case 16000: - format1 = 0x0c; - break; - case 8000: - format1 = 0x04; - break; - case 4000: - format1 = 0x00; - break; - } + int format1 = switch (this.sampleRate) { + case 32000 -> 0x14; + case 16000 -> 0x0c; + case 8000 -> 0x04; + case 4000 -> 0x00; + default -> 0x04; + }; return format1; } /** */ protected int getSamplingBitsInternal() { - int format2 = 0x1; - switch (this.bits) { - case 4: - format2 = 0x1; - break; - case 2: - format2 = 0x0; - break; - } + int format2 = switch (this.bits) { + case 4 -> 0x1; + case 2 -> 0x0; + default -> 0x1; + }; return format2; } diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/Function132.java b/src/main/java/vavi/sound/mfi/vavi/sharp/Function132.java index 74e488a..0d1e22a 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/Function132.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/Function132.java @@ -6,11 +6,10 @@ package vavi.sound.mfi.vavi.sharp; -import java.util.logging.Level; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -72,12 +71,12 @@ public void process(MachineDependentMessage message) data[13]; int adpcmLength = data.length - HEADER_LENGTH; -Debug.printf(Level.FINE, "ADPCM voice: %dch, No.%d, mode=%d, continued=%s, %d\n", channel, packetId, mode, continued, adpcmLength); -Debug.println(Level.FINER, "data:\n" + StringUtil.getDump(data, 32)); +logger.log(Level.DEBUG, String.format("ADPCM voice: %dch, No.%d, mode=%d, continued=%s, %d", channel, packetId, mode, continued, adpcmLength)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(data, 32)); this.sampleRate = getSamplingRateInternal(format1); this.bits = getSamplingBitsInternal(format2); -Debug.printf(Level.FINE, "sampling: %02x: rate=%d, bits=%d\n", data[8] & 0x3f, sampleRate, bits); +logger.log(Level.DEBUG, String.format("sampling: %02x: rate=%d, bits=%d", data[8] & 0x3f, sampleRate, bits)); this.adpcm = new byte[adpcmLength]; System.arraycopy(data, HEADER_LENGTH, adpcm, 0, adpcmLength); diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/Function143.java b/src/main/java/vavi/sound/mfi/vavi/sharp/Function143.java index 1303a26..1a28fa3 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/Function143.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/Function143.java @@ -6,14 +6,13 @@ package vavi.sound.mfi.vavi.sharp; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; import vavi.sound.mfi.vavi.track.MachineDependentMessage; -import vavi.util.Debug; import vavi.util.StringUtil; @@ -55,7 +54,7 @@ public void process(MachineDependentMessage message) byte[] subIdData = new byte[subIdLength]; System.arraycopy(data, index, subIdData, 0, subIdLength); index += subIdLength; -Debug.printf(Level.FINER, "ADPCM subId: %d\n%s", subId, StringUtil.getDump(subIdData)); +logger.log(Level.TRACE, String.format("ADPCM subId: %d\n%s", subId, StringUtil.getDump(subIdData))); subIds.add(new SubIdChunk(subId, subIdData)); } } @@ -123,7 +122,7 @@ public void setMaxParallelCue(int sample) { } /** */ - private List subIds = new ArrayList<>(); + private final List subIds = new ArrayList<>(); /** */ private static class SubIdChunk { @@ -136,9 +135,9 @@ private static class SubIdChunk { this.data = data; } /** */ - int id; + final int id; /** */ - byte[] data; + final byte[] data; } /** */ diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/SharpMessage.java b/src/main/java/vavi/sound/mfi/vavi/sharp/SharpMessage.java index 13b734b..c03b808 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/SharpMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/SharpMessage.java @@ -6,9 +6,10 @@ package vavi.sound.mfi.vavi.sharp; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.MfiEvent; @@ -16,7 +17,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mfi.vavi.track.Nop2Message; import vavi.sound.mobile.AudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,6 +29,8 @@ */ public class SharpMessage extends FuetrekAudioMessage { + private static final Logger logger = getLogger(SharpMessage.class.getName()); + /** wave length, use 0x84, 4bit in ADPCM, mono */ private static final int MAX_BLOCK = 0xffff - Function132.HEADER_LENGTH; @@ -45,18 +49,18 @@ public class SharpMessage extends FuetrekAudioMessage { */ public static List getAdpcmEvents(byte[] pcm, float time, int sampleRate, int bits, int channels, boolean fillNop) throws InvalidMfiDataException { int delta = getDelta(time, sampleRate); -Debug.println(Level.FINE, "delta: " + delta); +logger.log(Level.DEBUG, "delta: " + delta); AudioEngine audioEngine = SharpSequencer.getAudioEngine(); byte[] adpcm = audioEngine.encode(bits, channels, pcm); List events = new ArrayList<>(); if (channels == 1) { -Debug.println(Level.FINE, "adpcm mono length: " + adpcm.length); +logger.log(Level.DEBUG, "adpcm mono length: " + adpcm.length); events.addAll(getAdpcmEventsSub(L, 0, sampleRate, bits, adpcm)); // 0x84 adpcm recycle events.add(getWaveEvent(L, 0, sampleRate, bits, adpcm.length)); } else { byte[] temp = new byte[adpcm.length / 2]; -Debug.println(Level.FINE, "adpcm L, R length: " + temp.length); +logger.log(Level.DEBUG, "adpcm L, R length: " + temp.length); System.arraycopy(adpcm, 0, temp, 0, adpcm.length / 2); events.addAll(getAdpcmEventsSub(L, 0, sampleRate, bits, temp)); System.arraycopy(adpcm, adpcm.length / 2, temp, 0, adpcm.length / 2); @@ -89,7 +93,7 @@ private static List getAdpcmEventsSub(int channel, int packetId, int s for (int i = 0; i < numberOfChunks; i++) { byte[] chunk = new byte[MAX_BLOCK]; System.arraycopy(adpcm, MAX_BLOCK * i, chunk, 0, MAX_BLOCK); -Debug.println(Level.FINE, "wave chunk(" + i + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + i + "): " + chunk.length); // 0x84 adpcm data events.add(getWaveEvent(channel, packetId, sampleRate, bits, !(i == (numberOfChunks - 1) && moduloOfChunks == 0), i == 0 ? adpcm.length : 0, chunk)); @@ -97,7 +101,7 @@ private static List getAdpcmEventsSub(int channel, int packetId, int s if (moduloOfChunks != 0) { byte[] chunk = new byte[moduloOfChunks]; System.arraycopy(adpcm, MAX_BLOCK * numberOfChunks, chunk, 0, moduloOfChunks); -Debug.println(Level.FINE, "wave chunk(" + numberOfChunks + "): " + chunk.length); +logger.log(Level.DEBUG, "wave chunk(" + numberOfChunks + "): " + chunk.length); // 0x84 adpcm data events.add(getWaveEvent(channel, packetId, sampleRate, bits, false, numberOfChunks == 0 ? adpcm.length : 0, chunk)); diff --git a/src/main/java/vavi/sound/mfi/vavi/sharp/SharpSequencer.java b/src/main/java/vavi/sound/mfi/vavi/sharp/SharpSequencer.java index 5567d80..e46d42c 100644 --- a/src/main/java/vavi/sound/mfi/vavi/sharp/SharpSequencer.java +++ b/src/main/java/vavi/sound/mfi/vavi/sharp/SharpSequencer.java @@ -6,7 +6,8 @@ package vavi.sound.mfi.vavi.sharp; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.vavi.sequencer.MachineDependentFunction; @@ -14,7 +15,8 @@ import vavi.sound.mfi.vavi.track.MachineDependentMessage; import vavi.sound.mobile.AudioEngine; import vavi.sound.mobile.FuetrekAudioEngine; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,6 +31,8 @@ */ public class SharpSequencer implements MachineDependentSequencer { + private static final Logger logger = getLogger(SharpSequencer.class.getName()); + /** * * @param message see below @@ -39,20 +43,20 @@ public void sequence(MachineDependentMessage message) byte[] data = message.getMessage(); int function = data[6] & 0xff; -Debug.printf(Level.FINER, "function: 0x%02x", function); +logger.log(Level.TRACE, String.format("function: 0x%02x", function)); MachineDependentFunction mdf = factory.getFunction(String.valueOf(function)); if (mdf != null) { mdf.process(message); } else { -Debug.printf(Level.WARNING, "unsupported function: 0x%02x", function); +logger.log(Level.WARNING, String.format("unsupported function: 0x%02x", function)); } } //------------------------------------------------------------------------- /** */ - private static AudioEngine player = new FuetrekAudioEngine(); + private static final AudioEngine player = new FuetrekAudioEngine(); /** */ static AudioEngine getAudioEngine() { @@ -62,6 +66,6 @@ static AudioEngine getAudioEngine() { //------------------------------------------------------------------------- /** */ - private static MachineDependentFunction.Factory factory = + private static final MachineDependentFunction.Factory factory = new MachineDependentFunction.Factory("/vavi/sound/mfi/vavi/sharp/sharp.properties"); } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/AudioPlayMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/AudioPlayMessage.java index d1927c3..da00e71 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/AudioPlayMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/AudioPlayMessage.java @@ -37,7 +37,7 @@ public class AudioPlayMessage extends LongMessage /** */ private int voice; /** */ - private int index; + private final int index; /** */ private int velocity = 63; diff --git a/src/main/java/vavi/sound/mfi/vavi/track/AudioStopMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/AudioStopMessage.java index 7c3b27d..0c1f6f4 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/AudioStopMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/AudioStopMessage.java @@ -37,7 +37,7 @@ public class AudioStopMessage extends LongMessage /** */ private int voice; /** */ - private int index; + private final int index; /** * for {@link vavi.sound.mfi.vavi.TrackMessage} diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ChangeBankMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ChangeBankMessage.java index 0f8a588..1968bce 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ChangeBankMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ChangeBankMessage.java @@ -97,9 +97,9 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataException { int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println("track: "+context.getTrackNumber()+", voice: "+getVoice()); +//logger.log(Level.DEBUG, "track: "+context.getTrackNumber()+", voice: "+getVoice()); -//Debug.println("bank[" + channel + "]: " + getBank()); +//logger.log(Level.DEBUG, "bank[" + channel + "]: " + getBank()); channel = context.setBank(channel, getBank()); return null; diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ChangeVoiceMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ChangeVoiceMessage.java index 9d643d8..05f41c3 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ChangeVoiceMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ChangeVoiceMessage.java @@ -103,7 +103,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println("program[" + channel + "]: " + StringUtil.toHex2(getProgram())); +//logger.log(Level.DEBUG, "program[" + channel + "]: " + StringUtil.toHex2(getProgram())); channel = context.setProgram(channel, getProgram()); ShortMessage shortMessage = new ShortMessage(); @@ -137,7 +137,7 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) changeBankMessage.setBank(((data1 & 0xc0) >> 6) + 2); // TODO 2 ??? context.setPreviousTick(track, midiEvent.getTick()); -//Debug.println(channel + ": " + StringUtil.toHex2(data1) + ", " + StringUtil.toHex2(changeVoiceMessage.getProgram()) + ", " + changeBankMessage.getBank()); +//logger.log(Level.DEBUG, channel + ": " + StringUtil.toHex2(data1) + ", " + StringUtil.toHex2(changeVoiceMessage.getProgram()) + ", " + changeBankMessage.getBank()); return new MfiEvent[] { new MfiEvent(changeBankMessage, midiEvent.getTick()), diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ChannelChangeMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ChannelChangeMessage.java index 7217750..c694167 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ChannelChangeMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ChannelChangeMessage.java @@ -6,13 +6,16 @@ package vavi.sound.mfi.vavi.track; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; + import vavi.sound.mfi.ChannelMessage; import vavi.sound.mfi.ShortMessage; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -32,10 +35,12 @@ public class ChannelChangeMessage extends ShortMessage implements ChannelMessage, MidiConvertible { + private static final Logger logger = getLogger(ChannelChangeMessage.class.getName()); + /** */ private int voice; /** 0 - 15 ch */ - private int channel; + private final int channel; /** * for {@link vavi.sound.mfi.vavi.TrackMessage} @@ -84,7 +89,7 @@ public String toString() { @Override public MidiEvent[] getMidiEvents(MidiContext context) { -Debug.println(Level.INFO, "ignore: " + this); +logger.log(Level.INFO, "ignore: " + this); return null; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ChannelConfigurationMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ChannelConfigurationMessage.java index 7d6d461..97fb526 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ChannelConfigurationMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ChannelConfigurationMessage.java @@ -6,12 +6,15 @@ package vavi.sound.mfi.vavi.track; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; + import vavi.sound.mfi.ShortMessage; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,10 +30,12 @@ public class ChannelConfigurationMessage extends ShortMessage implements MidiConvertible { + private static final Logger logger = getLogger(ChannelConfigurationMessage.class.getName()); + /** */ - private int channel; + private final int channel; /** */ - private boolean drum; + private final boolean drum; /** * for {@link vavi.sound.mfi.vavi.TrackMessage} @@ -76,7 +81,7 @@ public String toString() { */ @Override public MidiEvent[] getMidiEvents(MidiContext context) { -Debug.println(Level.FINE, this); +logger.log(Level.DEBUG, this); context.setDrum(getChannel(), isDrum() ? MidiContext.ChannelConfiguration.PERCUSSION : MidiContext.ChannelConfiguration.SOUND_SET); diff --git a/src/main/java/vavi/sound/mfi/vavi/track/CuePointMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/CuePointMessage.java index 710d180..5d58ea0 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/CuePointMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/CuePointMessage.java @@ -32,7 +32,7 @@ public class CuePointMessage extends ShortMessage implements MidiConvertible { /** 00: start, 01: end */ - private boolean start; + private final boolean start; /** * 0xd0 @@ -92,7 +92,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce // new MidiEvent(sysexMessage, context.getCurrent()) // }; // } else { -//Debug.println("ignore: " + this); +//logger.log(Level.DEBUG, "ignore: " + this); // return null; // } MetaMessage metaMessage = new MetaMessage(); diff --git a/src/main/java/vavi/sound/mfi/vavi/track/EndOfTrackMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/EndOfTrackMessage.java index f696f3a..0a2f963 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/EndOfTrackMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/EndOfTrackMessage.java @@ -75,7 +75,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) { // new MidiEvent(metaMessage, context.getCurrent()) // }; -//Debug.println("ignore: " + this); +//logger.log(Level.DEBUG, "ignore: " + this); return null; } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ExpressionMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ExpressionMessage.java index 296956a..03b221e 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ExpressionMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ExpressionMessage.java @@ -109,7 +109,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println("volume rel: " + channel + ": " + getVolume()); +//logger.log(Level.DEBUG, "volume rel: " + channel + ": " + getVolume()); // context.addVolume(channel, getVolume()); // MidiEvent[] events = new MidiEvent[2]; diff --git a/src/main/java/vavi/sound/mfi/vavi/track/ExtendedEditMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/ExtendedEditMessage.java index 03adc63..709d7ef 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/ExtendedEditMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/ExtendedEditMessage.java @@ -7,13 +7,15 @@ package vavi.sound.mfi.vavi.track; import java.io.DataInputStream; -import java.io.InputStream; import java.io.IOException; -import java.util.logging.Level; +import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.mfi.InvalidMfiDataException; import vavi.sound.mfi.SysexMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,6 +31,8 @@ */ public class ExtendedEditMessage extends SysexMessage { + private static final Logger logger = getLogger(ExtendedEditMessage.class.getName()); + /** */ protected ExtendedEditMessage(byte[] message) { super(message); @@ -49,7 +53,7 @@ public static ExtendedEditMessage readFrom(int delta, int status, int data1, Inp dummy = dis.read(); // 0x01 int part = dis.read(); int zwitch = dis.read(); -Debug.println(Level.FINE, "dummy " + dummy + ", part " + part + ", switch " + zwitch); +logger.log(Level.DEBUG, "dummy " + dummy + ", part " + part + ", switch " + zwitch); throw new InvalidMfiDataException("unsupported: " + 0xf2); } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/LoopPointMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/LoopPointMessage.java index dd43472..f6309e2 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/LoopPointMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/LoopPointMessage.java @@ -6,12 +6,15 @@ package vavi.sound.mfi.vavi.track; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; + import vavi.sound.mfi.ShortMessage; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,12 +32,14 @@ public class LoopPointMessage extends ShortMessage implements MidiConvertible { + private static final Logger logger = getLogger(LoopPointMessage.class.getName()); + /** 0 ~ 3 */ - private int nest; + private final int nest; /** loop times, 01111b means forever */ private int times; /** 00b: start, 01b: end */ - private int start; + private final int start; /** * for {@link vavi.sound.mfi.vavi.TrackMessage} @@ -88,7 +93,7 @@ public String toString() { @Override public MidiEvent[] getMidiEvents(MidiContext context) { -Debug.println(Level.INFO, "ignore: " + this); +logger.log(Level.INFO, "ignore: " + this); return null; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/MachineDependentMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/MachineDependentMessage.java index fc73247..b9be66b 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/MachineDependentMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/MachineDependentMessage.java @@ -10,8 +10,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -23,7 +23,8 @@ import vavi.sound.mfi.vavi.sequencer.MachineDependentSequencer; import vavi.sound.mfi.vavi.sequencer.MfiMessageStore; import vavi.sound.midi.VaviMidiDeviceProvider; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -42,6 +43,8 @@ public class MachineDependentMessage extends SysexMessage implements MidiConvertible, Serializable { + private static final Logger logger = getLogger(MachineDependentMessage.class.getName()); + /** */ protected MachineDependentMessage(byte[] message) { super(message); @@ -61,7 +64,7 @@ public void setMessage(int delta, byte[] message) throws InvalidMfiDataException { byte[] tmp = new byte[5 + message.length]; -//Debug.println("data: " + message.length); +//logger.log(Level.DEBUG, "data: " + message.length); tmp[0] = (byte) (delta & 0xff); tmp[1] = (byte) 0xff; tmp[2] = (byte) 0xff; @@ -70,7 +73,7 @@ public void setMessage(int delta, byte[] message) //Debug.dump(new ByteArrayInputStream(tmp, 0, 5)); System.arraycopy(message, 0, tmp, 5, message.length); -//Debug.println("message: " + tmp.length); +//logger.log(Level.DEBUG, "message: " + tmp.length); super.setMessage(tmp, tmp.length); //Debug.dump(new ByteArrayInputStream(this.data, 0, 10)); } @@ -87,7 +90,7 @@ public static MachineDependentMessage readFrom(int delta, int status, int data1, DataInputStream dis = new DataInputStream(is); int length = dis.readUnsignedShort(); -//Debug.println("length: " + length); +//logger.log(Level.DEBUG, "length: " + length); byte[] data = new byte[length + 5]; @@ -103,7 +106,7 @@ public static MachineDependentMessage readFrom(int delta, int status, int data1, // 5 vendor | carrier // 6 // 7 -Debug.printf(Level.FINE, "MachineDepend: %02x, %02x, %02x %02x %02x %02x %02x\n", data[0], data[5], data[6], data[7], (data.length > 8 ? data[8] : 0), (data.length > 9 ? data[9] : 0), (data.length > 10 ? data[10] : 0)); +logger.log(Level.DEBUG, String.format("MachineDepend: %02x, %02x, %02x %02x %02x %02x %02x", data[0], data[5], data[6], data[7], (data.length > 8 ? data[8] : 0), (data.length > 9 ? data[9] : 0), (data.length > 10 ? data[10] : 0))); MachineDependentMessage message = new MachineDependentMessage(data); return message; } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/MfiConvertibleMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/MfiConvertibleMessage.java index 6828ce2..e72b8c8 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/MfiConvertibleMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/MfiConvertibleMessage.java @@ -25,9 +25,9 @@ public class MfiConvertibleMessage implements MfiConvertible { /** BANK LSB */ - private int[] bankLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] bankLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** BANK MSB */ - private int[] bankMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] bankMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** */ public static final int RPN_PITCH_BEND_SENSITIVITY = 0x0000; @@ -43,14 +43,14 @@ public class MfiConvertibleMessage implements MfiConvertible { public static final int RPN_NULL = 0x7f7f; /** RPN LSB */ - private int[] rpnLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] rpnLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** RPN MSB */ - private int[] rpnMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] rpnMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** NRPN LSB */ - private int[] nrpnLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] nrpnLSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** NRPN MSB */ - private int[] nrpnMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; + private final int[] nrpnMSB = new int[MidiContext.MAX_MIDI_CHANNELS]; /** bank, rpn, nrpn */ @Override @@ -90,13 +90,13 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) // case RPN_PITCH_BEND_SENSITIVITY: // MfiConvertible converter = new vavi.sound.mfi.vavi.channel.PitchBendRangeMessage(); // return converter.getMfiEvents(midiEvent, context); -//Debug.println("rpn: MSB:" + rpnMSB[channel] + ", LSB:" + rpnLSB[channel]); +//logger.log(Level.DEBUG, "rpn: MSB:" + rpnMSB[channel] + ", LSB:" + rpnLSB[channel]); // default: -//Debug.println("data entry: no handler for rpn: " + rpn[channel]); +//logger.log(Level.DEBUG, "data entry: no handler for rpn: " + rpn[channel]); // break; // } default: -//Debug.println("not implemented: " + data1); +//logger.log(Level.DEBUG, "not implemented: " + data1); break; } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/Nop2Message.java b/src/main/java/vavi/sound/mfi/vavi/track/Nop2Message.java index c9e2f97..1dffa27 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/Nop2Message.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/Nop2Message.java @@ -6,13 +6,15 @@ package vavi.sound.mfi.vavi.track; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; import vavi.sound.mfi.ShortMessage; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,6 +31,8 @@ public class Nop2Message extends ShortMessage implements MidiConvertible { + private static final Logger logger = getLogger(Nop2Message.class.getName()); + public static final int maxDelta = 0xff * 0x100 + 0xff; /** @@ -43,7 +47,7 @@ public class Nop2Message extends ShortMessage */ public Nop2Message(int delta, int data2) { super(delta, 0xff, 0xdc, data2); -Debug.println(Level.FINE, "NOP2: delta: " + delta); +logger.log(Level.DEBUG, "NOP2: delta: " + delta); } /** @@ -55,7 +59,7 @@ public Nop2Message(int delta, int data2) { */ public Nop2Message(int delta, int status, int data1, int data2) { super(delta, 0xff, 0xdc, data2); -Debug.println(Level.FINE, "NOP2: delta: " + delta); +logger.log(Level.DEBUG, "NOP2: delta: " + delta); } /** */ @@ -67,7 +71,7 @@ public String toString() { @Override public MidiEvent[] getMidiEvents(MidiContext context) { -//Debug.println("ignore: " + this); +//logger.log(Level.DEBUG, "ignore: " + this); return null; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/NopMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/NopMessage.java index 50345b0..52db685 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/NopMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/NopMessage.java @@ -36,7 +36,7 @@ public class NopMessage extends ShortMessage */ public NopMessage(int delta, int data2) { super(delta, 0xff, 0xde, data2); -//Debug.println("NOP: delta: " + delta); +//logger.log(Level.DEBUG, "NOP: delta: " + delta); } /** @@ -48,7 +48,7 @@ public NopMessage(int delta, int data2) { */ public NopMessage(int delta, int status, int data1, int data2) { super(delta, 0xff, 0xde, data2); -//Debug.println("NOP: delta: " + delta); +//logger.log(Level.DEBUG, "NOP: delta: " + delta); } /** */ @@ -60,7 +60,7 @@ public String toString() { @Override public MidiEvent[] getMidiEvents(MidiContext context) { -//Debug.println("ignore: " + this); +//logger.log(Level.DEBUG, "ignore: " + this); return null; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/PitchBendMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/PitchBendMessage.java index dc79ef7..2070c8c 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/PitchBendMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/PitchBendMessage.java @@ -102,7 +102,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataException { int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println(this); +//logger.log(Level.DEBUG, this); // context.setPitchBend(channel, getPitchBend()); // int pitch = context.retrieveRealPitch(channel); diff --git a/src/main/java/vavi/sound/mfi/vavi/track/PitchBendRangeMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/PitchBendRangeMessage.java index cd5de67..92e41e9 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/PitchBendRangeMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/PitchBendRangeMessage.java @@ -103,7 +103,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataException { int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println(this); +//logger.log(Level.DEBUG, this); // context.setPitchBendRange(channel, getPitchBendRange()); MidiEvent[] events = new MidiEvent[3]; @@ -143,7 +143,7 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) mfiMessage.setDelta(context.getDelta(context.retrieveMfiTrack(channel))); mfiMessage.setVoice(voice); // if (data2 / 2 > 24) { -// Debug.println("range: " + data2 / 2); +// logger.log(Level.DEBUG, "range: " + data2 / 2); // } mfiMessage.setPitchBendRange(Math.min(data2 / 2, 24)); diff --git a/src/main/java/vavi/sound/mfi/vavi/track/TempoMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/TempoMessage.java index 33601dd..37196b0 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/TempoMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/TempoMessage.java @@ -6,10 +6,10 @@ package vavi.sound.mfi.vavi.track; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -21,7 +21,8 @@ import vavi.sound.mfi.vavi.MfiConvertible; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -38,6 +39,8 @@ public class TempoMessage extends ShortMessage implements MidiConvertible, MfiConvertible { + private static final Logger logger = getLogger(TempoMessage.class.getName()); + /** quarter note resolution @see #timeBaseTable */ private int timeBase; /** quarter note count per minute 20 ~ 125 ~ 255 */ @@ -61,7 +64,7 @@ public TempoMessage(int delta, int status, int data1, int data2) { super(delta, 0xff, data1, data2); this.timeBase = timeBaseTable[data1 & 0x0f]; - this.tempo = data2 < 20 ? 20 : data2; + this.tempo = Math.max(data2, 20); } /** for {@link MfiConvertible} */ @@ -84,7 +87,7 @@ public void setTimeBase(int timeBase) { for (int i = 0; i < timeBaseTable.length; i++) { if (timeBase == timeBaseTable[i]) { if (timeBase < 0) { - Debug.println(Level.WARNING, "timeBase < 0: " + timeBase); + logger.log(Level.WARNING, "timeBase < 0: " + timeBase); } this.data[2] = (byte) (0xc0 | i); return; @@ -121,8 +124,8 @@ public MidiEvent[] getMidiEvents(MidiContext context) int timeBase = getTimeBase(); // quarter note length in μsec TODO is round OK?, TODO 48??? (actually 60 * 10^6 / tempo) int l = (int) Math.round(60d * 1000000d / ((48d / timeBase) * tempo)); -//Debug.println(this); -//Debug.println(l + " = " + +//logger.log(Level.DEBUG, this); +//logger.log(Level.DEBUG, l + " = " + // StringUtil.toHex2( ((l / 0x10000) & 0xff)) + ", " + // StringUtil.toHex2((((l % 0x10000) / 0x100) & 0xff)) + ", " + // StringUtil.toHex2( ((l % 0x100) & 0xff))); @@ -145,23 +148,23 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) MetaMessage metaMessage = (MetaMessage) midiEvent.getMessage(); // int type = metaMessage.getType(); byte[] data = metaMessage.getData(); -//Debug.println("data.length: " + data.length); +//logger.log(Level.DEBUG, "data.length: " + data.length); int timeBase = getNearestTimeBase(context.getTimeBase()); int l = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff); -//Debug.println("(CALC) timeBase: " + timeBase + ", tempo: " + tempo + ", l; " + l); +//logger.log(Level.DEBUG, "(CALC) timeBase: " + timeBase + ", tempo: " + tempo + ", l; " + l); // TODO no more change if scale is changed once? if (context.isScaleChanged()) { timeBase = getNearestTimeBase((int) (context.getTimeBase() / context.getScale())); tempo = (int) Math.round(60d * 1000000d / ((48d / timeBase) * l)); -//Debug.println("(SET) tempo > " + MAX_SCALELESS + ": timeBase: " + timeBase + ", tempo: " + tempo); +//logger.log(Level.DEBUG, "(SET) tempo > " + MAX_SCALELESS + ": timeBase: " + timeBase + ", tempo: " + tempo); } else { timeBase = getNearestTimeBase(context.getTimeBase()); tempo = (int) Math.round(60d * 1000000d / ((48d / timeBase) * l)); -//Debug.println("(SET) timeBase: " + timeBase + ", tempo: " + tempo); +//logger.log(Level.DEBUG, "(SET) timeBase: " + timeBase + ", tempo: " + tempo); } TempoMessage mfiMessage = new TempoMessage(); @@ -178,8 +181,8 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) /** for sorting */ private static class Pair { - int index; - int value; + final int index; + final int value; Pair(int index, int value) { this.index = index; this.value = value; @@ -204,9 +207,9 @@ public static int getNearestTimeBase(int timeBase) { return v1 - v2; }); //for (int i = 0; i < table.size(); i++) { -// Debug.println("(" + i + ") timeBaseTable[" + table.get(i).index + "], " + table.get(i).value); +// logger.log(Level.DEBUG, "(" + i + ") timeBaseTable[" + table.get(i).index + "], " + table.get(i).value); //} -//Debug.println("(CHANGE) " + timeBase + " -> " + timeBaseTable[table.get(0).index]); +//logger.log(Level.DEBUG, "(CHANGE) " + timeBase + " -> " + timeBaseTable[table.get(0).index]); return timeBaseTable[table.get(0).index]; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/UndefinedMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/UndefinedMessage.java index 8c5134d..b42ced0 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/UndefinedMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/UndefinedMessage.java @@ -6,14 +6,17 @@ package vavi.sound.mfi.vavi.track; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; import vavi.sound.mfi.MfiMessage; import vavi.sound.mfi.vavi.MidiContext; import vavi.sound.mfi.vavi.MidiConvertible; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * UndefinedMessage @@ -25,6 +28,8 @@ public class UndefinedMessage extends MfiMessage implements MidiConvertible { + private static final Logger logger = getLogger(UndefinedMessage.class.getName()); + /** * * @param delta delta time @@ -61,7 +66,7 @@ public String toString() { @Override public MidiEvent[] getMidiEvents(MidiContext context) { -Debug.println(this); +logger.log(Level.DEBUG, this); return null; } } diff --git a/src/main/java/vavi/sound/mfi/vavi/track/VolumeMessage.java b/src/main/java/vavi/sound/mfi/vavi/track/VolumeMessage.java index afdbf1f..ba0422c 100644 --- a/src/main/java/vavi/sound/mfi/vavi/track/VolumeMessage.java +++ b/src/main/java/vavi/sound/mfi/vavi/track/VolumeMessage.java @@ -102,7 +102,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) int channel = getVoice() + 4 * context.getMfiTrackNumber(); -//Debug.println("volume: " + channel + ": " + getVolume()); +//logger.log(Level.DEBUG, "volume: " + channel + ": " + getVolume()); context.setVolume(channel, volume); MidiEvent[] events = new MidiEvent[1]; @@ -136,7 +136,7 @@ public MfiEvent[] getMfiEvents(MidiEvent midiEvent, MfiContext context) mfiMessage.setDelta(context.getDelta(context.retrieveMfiTrack(channel))); mfiMessage.setVoice(voice); mfiMessage.setVolume(data2 / 2); -//Debug.println(mfiMessage.getVoice() + ", " + ((mfiMessage.getMessage()[3] & 0xc0) >> 6)); +//logger.log(Level.DEBUG, mfiMessage.getVoice() + ", " + ((mfiMessage.getMessage()[3] & 0xc0) >> 6)); context.setPreviousTick(track, midiEvent.getTick()); diff --git a/src/main/java/vavi/sound/midi/BasicMidiFileReader.java b/src/main/java/vavi/sound/midi/BasicMidiFileReader.java index c0f333b..6325a41 100644 --- a/src/main/java/vavi/sound/midi/BasicMidiFileReader.java +++ b/src/main/java/vavi/sound/midi/BasicMidiFileReader.java @@ -12,17 +12,17 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.net.URL; import java.nio.file.Files; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiFileFormat; import javax.sound.midi.MidiSystem; import javax.sound.midi.Sequence; import javax.sound.midi.spi.MidiFileReader; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -33,6 +33,8 @@ */ public abstract class BasicMidiFileReader extends MidiFileReader { + private static final Logger logger = getLogger(BasicMidiFileReader.class.getName()); + /** * Gets MIDI Sequence converted by a method {@link #getSequence(InputStream)} * implemented in a sub class. @@ -44,12 +46,12 @@ public MidiFileFormat getMidiFileFormat(InputStream stream) throws InvalidMidiDataException, IOException { -//Debug.println("here ★"); +//logger.log(Level.DEBUG, "here ★"); Sequence midiSequence = getSequence(stream); ByteArrayOutputStream os = new ByteArrayOutputStream(); MidiSystem.write(midiSequence, 0, os); ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); -//Debug.println("temporary midi:\n" + StringUtil.getDump(os.toByteArray(), 128)); +//logger.log(Level.DEBUG, "temporary midi:\n" + StringUtil.getDump(os.toByteArray(), 128)); MidiFileFormat midiFF = MidiSystem.getMidiFileFormat(is); return midiFF; } @@ -59,7 +61,7 @@ public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException { -Debug.println(Level.FINE, "file: " + file); +logger.log(Level.DEBUG, "file: " + file); InputStream is = new BufferedInputStream(Files.newInputStream(file.toPath())); return getMidiFileFormat(is); } diff --git a/src/main/java/vavi/sound/midi/MidiConstants.java b/src/main/java/vavi/sound/midi/MidiConstants.java index 33c8127..3aef812 100644 --- a/src/main/java/vavi/sound/midi/MidiConstants.java +++ b/src/main/java/vavi/sound/midi/MidiConstants.java @@ -7,12 +7,13 @@ package vavi.sound.midi; import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Properties; -import java.util.logging.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -23,13 +24,15 @@ */ public final class MidiConstants { + private static final Logger logger = getLogger(MidiConstants.class.getName()); + private MidiConstants() { } /** instrument names */ - private static Properties props = new Properties(); + private static final Properties props = new Properties(); - /** */ + /** */ public static String getInstrumentName(int index) { return props.getProperty("midi.inst.gm." + index); } @@ -237,7 +240,7 @@ public static MetaEvent valueOf(int number) { return Arrays.stream(values()).filter(e -> e.number == number).findFirst().get(); } catch (NoSuchElementException e) { META_UNDEFINED.number = number; // TODO evil and not thread safe. - Debug.println(Level.WARNING, "undefined meta: " + number); + logger.log(Level.WARNING, "undefined meta: " + number); return META_UNDEFINED; } } @@ -305,7 +308,7 @@ public String toString() { final Class clazz = MidiConstants.class; props.load(clazz.getResourceAsStream("midi.properties")); } catch (IOException e) { - Debug.println(e); + logger.log(Level.DEBUG, e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/midi/MidiUtil.java b/src/main/java/vavi/sound/midi/MidiUtil.java index 1e8131b..5518522 100644 --- a/src/main/java/vavi/sound/midi/MidiUtil.java +++ b/src/main/java/vavi/sound/midi/MidiUtil.java @@ -10,10 +10,10 @@ import java.io.DataOutput; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Properties; import java.util.ServiceLoader; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiDevice; @@ -27,6 +27,8 @@ import vavi.util.Debug; +import static java.lang.System.getLogger; + /** * MidiUtil. @@ -36,6 +38,8 @@ */ public final class MidiUtil { + private static final Logger logger = getLogger(MidiUtil.class.getName()); + /** */ private MidiUtil() { } @@ -53,8 +57,7 @@ public static void volume(Receiver receiver, float volume) throws InvalidMidiDat /** */ public static String paramString(MidiMessage midiMessage) { String result = null; - if (midiMessage instanceof ShortMessage) { - ShortMessage msg = (ShortMessage) midiMessage; + if (midiMessage instanceof ShortMessage msg) { int channel = msg.getChannel(); int command = msg.getCommand(); int data1 = msg.getData1(); @@ -63,8 +66,7 @@ public static String paramString(MidiMessage midiMessage) { ",event=" + getChannelMessage(command, data1) + ",data1=" + (command == ShortMessage.PROGRAM_CHANGE ? data1 + " " + MidiConstants.getInstrumentName(data1) : String.valueOf(data1)) + ",data2=" + data2; - } else if (midiMessage instanceof SysexMessage) { - SysexMessage msg = (SysexMessage) midiMessage; + } else if (midiMessage instanceof SysexMessage msg) { byte[] data = msg.getData(); StringBuilder sb = new StringBuilder(); for (byte datum : data) { @@ -75,8 +77,7 @@ public static String paramString(MidiMessage midiMessage) { ",event=SYSX" + ",data1=" + sb + ",data2="; - } else if (midiMessage instanceof MetaMessage) { - MetaMessage msg = (MetaMessage) midiMessage; + } else if (midiMessage instanceof MetaMessage msg) { int type = msg.getType(); byte[] data = msg.getData(); StringBuilder sb = new StringBuilder(); @@ -176,12 +177,12 @@ public static String getDecodedMessage(byte[] data, String encoding) { // 01 0x03 ? // 02 length try { -//Debug.println("META: " + data[1] + ", " + data[2] + ", " + StringUtil.getDump(data, start, length)); +//logger.log(Level.DEBUG, "META: " + data[1] + ", " + data[2] + ", " + StringUtil.getDump(data, start, length)); start = 3; length -= 3; return new String(data, start, length, encoding); } catch (UnsupportedEncodingException e) { -Debug.println(Level.WARNING, "unknown cp: " + e.getMessage()); +logger.log(Level.WARNING, "unknown cp: " + e.getMessage()); } } try { @@ -205,7 +206,7 @@ public static byte[] getEncodedMessage(String text, String encoding) { try { textData = text.getBytes(encoding); } catch (UnsupportedEncodingException e) { -Debug.println(Level.WARNING, "unknown cp: " + e.getMessage()); +logger.log(Level.WARNING, "unknown cp: " + e.getMessage()); textData = text.getBytes(); } byte[] data = new byte[textData.length + 3]; @@ -240,20 +241,20 @@ public static byte[] getEncodedMessage(String text, String encoding) { String value = props.getProperty("decodingEncoding"); if (value != null) { decodingEncoding = value; -Debug.println(Level.FINE, "decodingEncoding: " + decodingEncoding); +logger.log(Level.DEBUG, "decodingEncoding: " + decodingEncoding); } value = props.getProperty("encodingEncoding"); if (value != null) { encodingEncoding = value; -Debug.println(Level.FINE, "encodingEncoding: " + encodingEncoding); +logger.log(Level.DEBUG, "encodingEncoding: " + encodingEncoding); } // defaultSequencer value = props.getProperty("defaultSequencer"); if (value != null) { String defaultSequencer = value; -Debug.println(Level.FINE, "defaultSequencer: " + defaultSequencer); +logger.log(Level.DEBUG, "defaultSequencer: " + defaultSequencer); if (defaultSequencer.contains("#")) { String[] pair = defaultSequencer.split("#"); sequencerClassName = pair[0]; @@ -262,14 +263,14 @@ public static byte[] getEncodedMessage(String text, String encoding) { sequencerClassName = defaultSequencer; } } -Debug.println(Level.FINE, "sequencerClassName: " + sequencerClassName); -Debug.println(Level.FINE, "sequencerDeviceName: " + sequencerDeviceName); +logger.log(Level.DEBUG, "sequencerClassName: " + sequencerClassName); +logger.log(Level.DEBUG, "sequencerDeviceName: " + sequencerDeviceName); // defaultSynthesizer value = props.getProperty("defaultSynthesizer"); if (value != null) { String defaultSynthesizer = value; -Debug.println(Level.FINE, "defaultSynthesizer: " + defaultSynthesizer); +logger.log(Level.DEBUG, "defaultSynthesizer: " + defaultSynthesizer); if (defaultSynthesizer.contains("#")) { String[] pair = defaultSynthesizer.split("#"); synthesizerClassName = pair[0]; @@ -278,10 +279,10 @@ public static byte[] getEncodedMessage(String text, String encoding) { synthesizerClassName = defaultSynthesizer; } } -Debug.println(Level.FINE, "sequencerClassName: " + sequencerClassName); -Debug.println(Level.FINE, "sequencerDeviceName: " + sequencerDeviceName); +logger.log(Level.DEBUG, "sequencerClassName: " + sequencerClassName); +logger.log(Level.DEBUG, "sequencerDeviceName: " + sequencerDeviceName); } catch (Exception e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } @@ -301,19 +302,19 @@ public static Synthesizer getDefaultSynthesizer(Class byte[] bytes = info.getName().getBytes("ISO8859-1"); name = new String(bytes /* , "Windows-31J" */); } catch (IOException e) { -Debug.println(e); +logger.log(Level.DEBUG, e); } if (sequencerDeviceName != null) { if (sequencerDeviceName.equals(name)) { MidiDevice device = provider.getDevice(info); -Debug.println(Level.FINE, "default sequencer: " + provider.getClass().getName() + ", " + device.getClass().getName() + ", " + name + ", " + device.hashCode()); +logger.log(Level.DEBUG, "default sequencer: " + provider.getClass().getName() + ", " + device.getClass().getName() + ", " + name + ", " + device.hashCode()); return (Sequencer) device; } } else { MidiDevice device = provider.getDevice(info); if (device instanceof Sequencer) { if (device.getClass().getName().equals(sequencerClassName)) { -Debug.println(Level.FINE, "default sequencer: " + provider.getClass().getName() + ", " + device.getClass().getName() + ", " + name + ", " + device.hashCode()); +logger.log(Level.DEBUG, "default sequencer: " + provider.getClass().getName() + ", " + device.getClass().getName() + ", " + name + ", " + device.hashCode()); return (Sequencer) device; } } @@ -371,11 +372,11 @@ public static Sequencer getDefaultSequencer(Class static { try { providers = ServiceLoader.load(javax.sound.midi.spi.MidiDeviceProvider.class); -if (Debug.isLoggable(Level.FINE)) { +if (Debug.isLoggable(java.util.logging.Level.FINE)) { providers.forEach(provider -> System.err.println(provider.getClass())); } } catch (Throwable t) { -Debug.printStackTrace(Level.FINE, t); +logger.log(Level.DEBUG, t.getMessage(), t); } } } diff --git a/src/main/java/vavi/sound/midi/VaviMidiDeviceProvider.java b/src/main/java/vavi/sound/midi/VaviMidiDeviceProvider.java index dec8a19..abb89e8 100644 --- a/src/main/java/vavi/sound/midi/VaviMidiDeviceProvider.java +++ b/src/main/java/vavi/sound/midi/VaviMidiDeviceProvider.java @@ -6,12 +6,12 @@ package vavi.sound.midi; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiDevice; import javax.sound.midi.spi.MidiDeviceProvider; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -22,6 +22,8 @@ */ public class VaviMidiDeviceProvider extends MidiDeviceProvider { + private static final Logger logger = getLogger(VaviMidiDeviceProvider.class.getName()); + /** * TODO used without asking * TODO 0x5f is occupied by "SD Card Association" @@ -46,11 +48,11 @@ public MidiDevice getDevice(MidiDevice.Info info) { if (info == VaviSequencer.info) { //new Exception("*** DUMMY ***").printStackTrace(); -Debug.println(Level.FINE, "★1 info: " + info); +logger.log(Level.DEBUG, "★1 info: " + info); VaviSequencer wrappedSequencer = new VaviSequencer(); return wrappedSequencer; } else { -Debug.println(Level.FINE, "★1 not suitable for this provider: " + info); +logger.log(Level.DEBUG, "★1 not suitable for this provider: " + info); throw new IllegalArgumentException("info is not suitable for this provider"); } } diff --git a/src/main/java/vavi/sound/midi/VaviSequencer.java b/src/main/java/vavi/sound/midi/VaviSequencer.java index 1df211e..e9b6576 100644 --- a/src/main/java/vavi/sound/midi/VaviSequencer.java +++ b/src/main/java/vavi/sound/midi/VaviSequencer.java @@ -8,10 +8,10 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.List; import java.util.Properties; -import java.util.logging.Level; - import javax.sound.midi.ControllerEventListener; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaEventListener; @@ -23,7 +23,7 @@ import javax.sound.midi.Track; import javax.sound.midi.Transmitter; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -34,6 +34,8 @@ */ class VaviSequencer implements Sequencer { + private static final Logger logger = getLogger(VaviSequencer.class.getName()); + static { try { try (InputStream is = VaviSequencer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound/pom.properties")) { @@ -60,7 +62,7 @@ class VaviSequencer implements Sequencer { "Version " + version) {}; /** */ - private Sequencer sequencer = MidiUtil.getDefaultSequencer(VaviMidiDeviceProvider.class); + private final Sequencer sequencer = MidiUtil.getDefaultSequencer(VaviMidiDeviceProvider.class); /** */ private VaviSequence vaviSequence; @@ -69,31 +71,31 @@ class VaviSequencer implements Sequencer { public void start() { if (vaviSequence != null) { sequencer.addMetaEventListener(vaviSequence.getMetaEventListener()); // TODO more smart way -Debug.println(Level.FINE, "★1 mel: " + vaviSequence); +logger.log(Level.DEBUG, "★1 mel: " + vaviSequence); } sequencer.start(); -Debug.println(Level.FINE, "★1 start: " + sequencer.hashCode()); +logger.log(Level.DEBUG, "★1 start: " + sequencer.hashCode()); } @Override public void stop() { -Debug.println(Level.FINE, "★1 stop: " + sequencer.hashCode()); +logger.log(Level.DEBUG, "★1 stop: " + sequencer.hashCode()); sequencer.stop(); if (vaviSequence != null) { -Debug.println(Level.FINE, "★1 mel: " + vaviSequence); +logger.log(Level.DEBUG, "★1 mel: " + vaviSequence); sequencer.removeMetaEventListener(vaviSequence.getMetaEventListener()); // TODO more smart way } } @Override public void close() { -Debug.println(Level.FINE, "★1 close: " + sequencer.hashCode()); +logger.log(Level.DEBUG, "★1 close: " + sequencer.hashCode()); sequencer.close(); } @Override public void open() throws MidiUnavailableException { -Debug.println(Level.FINE, "★1 open: " + sequencer.hashCode()); +logger.log(Level.DEBUG, "★1 open: " + sequencer.hashCode()); sequencer.open(); } @@ -262,7 +264,7 @@ public void setSequence(Sequence sequence) throws InvalidMidiDataException { private void setVaviSequence() { if (getSequence() instanceof VaviSequence) { vaviSequence = (VaviSequence) getSequence(); -Debug.println(Level.FINE, "vaviSequence: " + vaviSequence); +logger.log(Level.DEBUG, "vaviSequence: " + vaviSequence); } else { vaviSequence = null; } diff --git a/src/main/java/vavi/sound/midi/mfi/MfiMidiFileReader.java b/src/main/java/vavi/sound/midi/mfi/MfiMidiFileReader.java index 20a9255..77c2aac 100644 --- a/src/main/java/vavi/sound/midi/mfi/MfiMidiFileReader.java +++ b/src/main/java/vavi/sound/midi/mfi/MfiMidiFileReader.java @@ -9,9 +9,9 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.Sequence; @@ -19,7 +19,8 @@ import vavi.sound.mfi.MfiSystem; import vavi.sound.mfi.MfiUnavailableException; import vavi.sound.midi.BasicMidiFileReader; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,6 +31,8 @@ */ public class MfiMidiFileReader extends BasicMidiFileReader { + private static final Logger logger = getLogger(MfiMidiFileReader.class.getName()); + /** Gets a MIDI Sequence converted from MFi */ @Override public Sequence getSequence(InputStream is) @@ -57,14 +60,13 @@ public Sequence getSequence(InputStream is) } vavi.sound.mfi.Sequence mfiSequence = MfiSystem.getSequence(is); -//Debug.println(mfiSequence); +//logger.log(Level.DEBUG, mfiSequence); return MfiSystem.toMidiSequence(mfiSequence); } catch (InvalidMfiDataException e) { -Debug.println(Level.FINE, e); -//Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw (InvalidMidiDataException) new InvalidMidiDataException().initCause(e); } catch (MfiUnavailableException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IOException(e); } finally { try { @@ -72,7 +74,7 @@ public Sequence getSequence(InputStream is) is.reset(); } } catch (IOException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); } } } diff --git a/src/main/java/vavi/sound/midi/mfi/MfiMidiFileWriter.java b/src/main/java/vavi/sound/midi/mfi/MfiMidiFileWriter.java index 7125e5c..b9b92f2 100644 --- a/src/main/java/vavi/sound/midi/mfi/MfiMidiFileWriter.java +++ b/src/main/java/vavi/sound/midi/mfi/MfiMidiFileWriter.java @@ -8,16 +8,17 @@ import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.Sequence; import vavi.sound.mfi.MfiSystem; import vavi.sound.mfi.MfiUnavailableException; import vavi.sound.midi.BasicMidiFileWriter; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,23 +31,25 @@ */ public class MfiMidiFileWriter extends BasicMidiFileWriter { + private static final Logger logger = getLogger(MfiMidiFileWriter.class.getName()); + @Override public int[] getMidiFileTypes() { -Debug.println(Level.FINE, "(1): " + Arrays.toString(MfiSystem.getMfiFileTypes())); +logger.log(Level.DEBUG, "(1): " + Arrays.toString(MfiSystem.getMfiFileTypes())); return MfiSystem.getMfiFileTypes(); } /** @param sequence MIDI sequence */ @Override public int[] getMidiFileTypes(Sequence sequence) { -Debug.println(Level.FINE, "(2): " + Arrays.toString(MfiSystem.getMfiFileTypes())); +logger.log(Level.DEBUG, "(2): " + Arrays.toString(MfiSystem.getMfiFileTypes())); return MfiSystem.getMfiFileTypes(); } /** @param fileType supports 0x88:MFi (vavi) */ @Override public boolean isFileTypeSupported(int fileType) { -Debug.println(Level.FINE, "(1): fileType: " + fileType); +logger.log(Level.DEBUG, "(1): fileType: " + fileType); return MfiSystem.isFileTypeSupported(fileType); } @@ -56,8 +59,8 @@ public boolean isFileTypeSupported(int fileType) { */ @Override public boolean isFileTypeSupported(int fileType, Sequence sequence) { -Debug.println(Level.FINE, "(2): fileType: " + fileType); -//Debug.println(sequence); +logger.log(Level.DEBUG, "(2): fileType: " + fileType); +//logger.log(Level.DEBUG, sequence); return MfiSystem.isFileTypeSupported(fileType); } @@ -69,15 +72,15 @@ public boolean isFileTypeSupported(int fileType, Sequence sequence) { @Override public int write(Sequence in, int fileType, OutputStream out) throws IOException { -Debug.println(Level.FINE, "in: " + in); -Debug.println(Level.FINE, "fileType: " + fileType); -Debug.println(Level.FINE, "out: " + out); +logger.log(Level.DEBUG, "in: " + in); +logger.log(Level.DEBUG, "fileType: " + fileType); +logger.log(Level.DEBUG, "out: " + out); try { if (isFileTypeSupported(fileType)) { vavi.sound.mfi.Sequence mfiSequence = MfiSystem.toMfiSequence(in, fileType); return MfiSystem.write(mfiSequence, fileType, out); } else { -Debug.println(Level.WARNING, "unknown fileType: " + fileType); +logger.log(Level.WARNING, "unknown fileType: " + fileType); return 0; } } catch (InvalidMidiDataException | MfiUnavailableException e) { diff --git a/src/main/java/vavi/sound/midi/smaf/SmafMidiFileReader.java b/src/main/java/vavi/sound/midi/smaf/SmafMidiFileReader.java index 77f7383..78385a2 100644 --- a/src/main/java/vavi/sound/midi/smaf/SmafMidiFileReader.java +++ b/src/main/java/vavi/sound/midi/smaf/SmafMidiFileReader.java @@ -9,9 +9,9 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.Sequence; @@ -19,7 +19,8 @@ import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafSystem; import vavi.sound.smaf.SmafUnavailableException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,6 +31,8 @@ */ public class SmafMidiFileReader extends BasicMidiFileReader { + private static final Logger logger = getLogger(SmafMidiFileReader.class.getName()); + @Override public Sequence getSequence(InputStream is) throws InvalidMidiDataException, @@ -56,14 +59,14 @@ public Sequence getSequence(InputStream is) } vavi.sound.smaf.Sequence sequence = SmafSystem.getSequence(is); -//Debug.println(sequence); +//logger.log(Level.DEBUG, sequence); return SmafSystem.toMidiSequence(sequence); } catch (InvalidSmafDataException e) { -Debug.println(Level.INFO, e); -//Debug.printStackTrace(e); +logger.log(Level.INFO, e); +//logger.log(Level.ERROR, e.getMessage(), e); throw (InvalidMidiDataException) new InvalidMidiDataException().initCause(e); } catch (SmafUnavailableException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IOException(e); } finally { try { @@ -71,7 +74,7 @@ public Sequence getSequence(InputStream is) is.reset(); } } catch (IOException e) { -Debug.println(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); } } } diff --git a/src/main/java/vavi/sound/midi/smaf/SmafMidiFileWriter.java b/src/main/java/vavi/sound/midi/smaf/SmafMidiFileWriter.java index 076e392..d5f0005 100644 --- a/src/main/java/vavi/sound/midi/smaf/SmafMidiFileWriter.java +++ b/src/main/java/vavi/sound/midi/smaf/SmafMidiFileWriter.java @@ -8,8 +8,8 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.Sequence; @@ -17,7 +17,8 @@ import vavi.sound.smaf.SmafFileFormat; import vavi.sound.smaf.SmafSystem; import vavi.sound.smaf.SmafUnavailableException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -30,6 +31,8 @@ */ public class SmafMidiFileWriter extends BasicMidiFileWriter { + private static final Logger logger = getLogger(SmafMidiFileWriter.class.getName()); + @Override public int[] getMidiFileTypes() { return new int[] { SmafFileFormat.FILE_TYPE }; @@ -63,15 +66,15 @@ public boolean isFileTypeSupported(int fileType, Sequence sequence) { @Override public int write(Sequence in, int fileType, OutputStream out) throws IOException { -Debug.println(Level.FINE, "in: " + in); -Debug.println(Level.FINE, "fileType: " + fileType); -Debug.println(Level.FINE, "out: " + out); +logger.log(Level.DEBUG, "in: " + in); +logger.log(Level.DEBUG, "fileType: " + fileType); +logger.log(Level.DEBUG, "out: " + out); try { if (isFileTypeSupported(fileType)) { vavi.sound.smaf.Sequence smafSequence = SmafSystem.toSmafSequence(in, fileType); return SmafSystem.write(smafSequence, fileType, out); } else { -Debug.println(Level.WARNING, "unknown fileType: " + fileType); +logger.log(Level.WARNING, "unknown fileType: " + fileType); return 0; } } catch (InvalidMidiDataException | SmafUnavailableException e) { diff --git a/src/main/java/vavi/sound/mobile/BasicAudioEngine.java b/src/main/java/vavi/sound/mobile/BasicAudioEngine.java index f1eb8af..a207567 100644 --- a/src/main/java/vavi/sound/mobile/BasicAudioEngine.java +++ b/src/main/java/vavi/sound/mobile/BasicAudioEngine.java @@ -11,18 +11,18 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; - import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; import static vavi.sound.SoundUtil.volume; @@ -34,6 +34,8 @@ */ public abstract class BasicAudioEngine implements AudioEngine { + private static final Logger logger = getLogger(BasicAudioEngine.class.getName()); + /** */ protected Data[] data; @@ -64,7 +66,7 @@ public void setData(int streamNumber, } datum.continued = continued; this.data[streamNumber] = datum; -// debug1(); +//debug1(); } @Override @@ -82,7 +84,7 @@ public void start(int streamNumber) { int channels = getChannels(streamNumber); if (channels == -1) { -Debug.println(Level.INFO, "always used: no: " + streamNumber + ", ch: " + this.data[streamNumber].channel); +logger.log(Level.INFO, "always used: no: " + streamNumber + ", ch: " + this.data[streamNumber].channel); return; } @@ -94,15 +96,15 @@ public void start(int streamNumber) { 2 * channels, this.data[streamNumber].sampleRate, false); -Debug.println(Level.FINE, audioFormat); +logger.log(Level.DEBUG, audioFormat); try { -//Debug.println(data.length); +//logger.log(Level.DEBUG, data.length); InputStream[] iss = getInputStreams(streamNumber, channels); -//Debug.println("is: " + is.available()); -// OutputStream os = debug2(); +//logger.log(Level.DEBUG, "is: " + is.available()); +//OutputStream os = debug2(); DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); @@ -113,13 +115,13 @@ public void start(int streamNumber) { while (iss[0].available() > 0) { if (channels == 1) { int l = iss[0].read(buf, 0, 1024); -Debug.println(Level.FINEST, "data:\n" + StringUtil.getDump(buf, 64)); +logger.log(Level.TRACE, "data:\n" + StringUtil.getDump(buf, 64)); line.write(buf, 0, l); -// debug3(os); +//debug3(os); } else { int lL = iss[0].read(buf, 0, 512); int lR = iss[1].read(buf, 512, 512); -//System.err.println("l : " + lL + ", r: " + lR); +//logger.log(Level.DEBUG, "l : " + lL + ", r: " + lR); for (int i = 0; i < lL / 2; i++) { byte[] temp = new byte[4]; temp[0] = buf[i * 2]; @@ -133,7 +135,7 @@ public void start(int streamNumber) { line.drain(); line.stop(); line.close(); -// debug4(os); +//debug4(os); } catch (IOException | LineUnavailableException e) { throw new IllegalStateException(e); } @@ -152,11 +154,11 @@ public byte[] encode(int bits, int channels, byte[] pcm) { InputStream is = new ByteArrayInputStream(pcm); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = getOutputStream(baos); -Debug.println(Level.FINE, "pcm length: " + is.available()); +logger.log(Level.DEBUG, "pcm length: " + is.available()); while (is.available() > 0) { int c = is.read(); if (c == -1) { -Debug.println(Level.FINE, "read returns -1"); +logger.log(Level.DEBUG, "read returns -1"); break; } os.write(c); @@ -170,11 +172,11 @@ public byte[] encode(int bits, int channels, byte[] pcm) { InputStream is = new ByteArrayInputStream(monos[0]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = getOutputStream(baos); -Debug.println(Level.FINE, "pcm L length: " + is.available()); +logger.log(Level.DEBUG, "pcm L length: " + is.available()); while (is.available() > 0) { int c = is.read(); if (c == -1) { -Debug.println(Level.FINE, "Illegal EOF L: " + is.available()); +logger.log(Level.DEBUG, "Illegal EOF L: " + is.available()); break; } os.write(c); @@ -184,11 +186,11 @@ public byte[] encode(int bits, int channels, byte[] pcm) { is = new ByteArrayInputStream(monos[1]); baos = new ByteArrayOutputStream(); os = getOutputStream(baos); -Debug.println(Level.FINE, "pcm R length: " + is.available()); +logger.log(Level.DEBUG, "pcm R length: " + is.available()); while (is.available() > 0) { int c = is.read(); if (c == -1) { -Debug.println(Level.FINE, "Illegal EOF R: " + is.available()); +logger.log(Level.DEBUG, "Illegal EOF R: " + is.available()); break; } os.write(c); diff --git a/src/main/java/vavi/sound/mobile/FuetrekAudioEngine.java b/src/main/java/vavi/sound/mobile/FuetrekAudioEngine.java index 1d64f62..a41aaa3 100644 --- a/src/main/java/vavi/sound/mobile/FuetrekAudioEngine.java +++ b/src/main/java/vavi/sound/mobile/FuetrekAudioEngine.java @@ -9,13 +9,15 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteOrder; -import java.util.logging.Level; import vavi.sound.adpcm.ccitt.G721InputStream; import vavi.sound.adpcm.ccitt.G721OutputStream; import vavi.sound.adpcm.ccitt.G723_16InputStream; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,6 +28,8 @@ */ public class FuetrekAudioEngine extends BasicAudioEngine { + private static final Logger logger = getLogger(FuetrekAudioEngine.class.getName()); + /** */ private static final int MAX_ID = 16; @@ -49,7 +53,7 @@ protected int getChannels(int streamNumber) { if (data[streamNumber].channel != -1) { // from MachineDependent if (streamNumber % 2 == 1 && data[streamNumber].channel % 2 == 1 && (data[streamNumber - 1] != null && data[streamNumber - 1].channel % 2 == 0)) { -Debug.println(Level.FINE, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel); +logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel); return -1; } diff --git a/src/main/java/vavi/sound/mobile/PcmAudioEngine.java b/src/main/java/vavi/sound/mobile/PcmAudioEngine.java index 550f102..72f553d 100644 --- a/src/main/java/vavi/sound/mobile/PcmAudioEngine.java +++ b/src/main/java/vavi/sound/mobile/PcmAudioEngine.java @@ -10,15 +10,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; -import vavi.util.Debug; - +import static java.lang.System.getLogger; import static vavi.sound.SoundUtil.volume; @@ -44,6 +44,8 @@ */ public class PcmAudioEngine extends BasicAudioEngine { + private static final Logger logger = getLogger(PcmAudioEngine.class.getName()); + /** *
      *  L0 + L2 + ...
@@ -63,7 +65,7 @@ protected int getChannels(int streamNumber) {
                 channels = 2;
             } else {
                 if (streamNumber % 2 == 1 && data[streamNumber].channels != 2 && (data[streamNumber - 1] != null && data[streamNumber - 1].channels != 2)) {
-Debug.println("always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
+logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
                     return -1;
                 }
 
@@ -75,7 +77,7 @@ protected int getChannels(int streamNumber) {
             // from 240_2, channels always 1
 
             if (streamNumber % 2 == 1 && data[streamNumber].channel % 2 == 1 && (data[streamNumber - 1] != null && data[streamNumber - 1].channel % 2 == 0)) {
-Debug.println("always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
+logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
                 return -1;
             }
 
@@ -117,7 +119,7 @@ public void start(int streamNumber) {
 
         int channels = getChannels(streamNumber);
         if (channels == -1) {
-Debug.println("always used: no: " + streamNumber + ", ch: " + this.data[streamNumber].channel);
+logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + this.data[streamNumber].channel);
             return;
         }
 
@@ -129,14 +131,14 @@ public void start(int streamNumber) {
             1 * channels,
             this.data[streamNumber].sampleRate,
             false);
-Debug.println(audioFormat);
+logger.log(Level.DEBUG, audioFormat);
 
         try {
 
-//Debug.println(data.length);
+//logger.log(Level.DEBUG, data.length);
             InputStream[] iss = getInputStreams(streamNumber, channels);
 
-//Debug.println("is: " + is.available());
+//logger.log(Level.DEBUG, "is: " + is.available());
 // OutputStream os = debug2();
 
             DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
@@ -154,7 +156,7 @@ public void start(int streamNumber) {
                 } else {
                     int lL = iss[0].read(buf, 0, 512);
                     /*int lR = */iss[1].read(buf, 512, 512);
-//System.err.println("l : " + lL + ", r: " + lR);
+//logger.log(Level.DEBUG, "l : " + lL + ", r: " + lR);
                     for (int i = 0; i < lL / 2; i++) {
                         byte[] temp = new byte[4];
                         temp[0] = buf[i * 2];
diff --git a/src/main/java/vavi/sound/mobile/YamahaAudioEngine.java b/src/main/java/vavi/sound/mobile/YamahaAudioEngine.java
index 33b3cab..1ce01f8 100644
--- a/src/main/java/vavi/sound/mobile/YamahaAudioEngine.java
+++ b/src/main/java/vavi/sound/mobile/YamahaAudioEngine.java
@@ -9,11 +9,14 @@
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.nio.ByteOrder;
 
 import vavi.sound.adpcm.ma.MaInputStream;
 import vavi.sound.adpcm.ma.MaOutputStream;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -24,6 +27,8 @@
  */
 public class YamahaAudioEngine extends BasicAudioEngine {
 
+    private static final Logger logger = getLogger(YamahaAudioEngine.class.getName());
+
     /**
      * 
      *  L0 + L2 + ...
@@ -43,7 +48,7 @@ protected int getChannels(int streamNumber) {
                 channels = 2;
             } else {
                 if (streamNumber % 2 == 1 && data[streamNumber].channels != 2 && (data[streamNumber - 1] != null && data[streamNumber - 1].channels != 2)) {
-Debug.println("always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
+logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
                     return -1;
                 }
 
@@ -55,7 +60,7 @@ protected int getChannels(int streamNumber) {
             // from 240_2, channels always 1
 
             if (streamNumber % 2 == 1 && data[streamNumber].channel % 2 == 1 && (data[streamNumber - 1] != null && data[streamNumber - 1].channel % 2 == 0)) {
-Debug.println("always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
+logger.log(Level.DEBUG, "always used: no: " + streamNumber + ", ch: " + data[streamNumber].channel);
                 return -1;
             }
 
diff --git a/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRC.java b/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRC.java
index c8a6a1f..ef560b8 100644
--- a/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRC.java
+++ b/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRC.java
@@ -12,6 +12,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.channels.FileChannel;
@@ -19,10 +21,10 @@
 import java.nio.channels.WritableByteChannel;
 import java.util.Map;
 import java.util.Random;
-import java.util.logging.Logger;
 
 import vavi.util.I0Bessel;
 
+import static java.lang.System.getLogger;
 import static vavi.util.SplitRadixFft.rdft;
 
 
@@ -38,7 +40,7 @@
 public class SSRC {
 
     /** */
-    private static final Logger logger = Logger.getLogger(SSRC.class.getName());
+    private static final Logger logger = getLogger(SSRC.class.getName());
 
     /** */
     private static final ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
@@ -170,7 +172,7 @@ private int initShaper(int freq, int nch, int min, int max, int dType, int pdf,
                 }
             }
             if ((dType == 3 || dType == 4) && i == 6) {
-                logger.warning(String.format("ATH based noise shaping for destination frequency %dHz is not available, using triangular dither\n", freq));
+                logger.log(Level.WARNING, String.format("ATH based noise shaping for destination frequency %dHz is not available, using triangular dither", freq));
             }
             if (dType == 2 || i == 6) {
                 i = 0;
@@ -336,7 +338,7 @@ private void quitShaper(int nch) {
     }
 
     /** */
-    private Shaper shaper = new Shaper();
+    private final Shaper shaper = new Shaper();
 
     /** */
     private static double alpha(double a) {
@@ -548,7 +550,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                 alp = alpha(aa);
                 iza = I0Bessel.value(alp);
-//System.err.printf("iza = %g\n",iza);
+//logger.log(Level.DEBUG, String.format("iza = %g",iza));
 
                 n1y = fs1 / sfrq;
                 n1x = n1 / n1y + 1;
@@ -828,7 +830,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                             buf2[ch][p] = 0;
                         }
 
-//for (i = 0; i < n2b2; i++) { System.err.printf("%d:%g",i,buf2[ch][i]); }
+//for (i = 0; i < n2b2; i++) { logger.log(Level.DEBUG, String.format("%d:%g",i,buf2[ch][i])); }
 
                         rdft(n2b, 1, buf2[ch], fft_ip, fft_w);
 
@@ -841,7 +843,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                             re = stage2[i * 2] * buf2[ch][i * 2] - stage2[i * 2 + 1] * buf2[ch][i * 2 + 1];
                             im = stage2[i * 2 + 1] * buf2[ch][i * 2] + stage2[i * 2] * buf2[ch][i * 2 + 1];
 
-//System.err.printf("%d : %g %g %g %g %g %g\n", i, stage2[i * 2],stage2[i * 2 + 1],buf2[ch][i * 2],buf2[ch][i * 2 + 1], re, im);
+//logger.log(Level.DEBUG, String.format("%d : %g %g %g %g %g %g", i, stage2[i * 2],stage2[i * 2 + 1],buf2[ch][i * 2],buf2[ch][i * 2 + 1], re, im));
 
                             buf2[ch][i * 2] = re;
                             buf2[ch][i * 2 + 1] = im;
@@ -1127,7 +1129,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                 alp = alpha(aa);
 
                 iza = I0Bessel.value(alp);
-//System.err.printf("iza %f, alp: %f\n", iza, alp); // OK
+//logger.log(Level.DEBUG, String.format("iza %f, alp: %f", iza, alp)); // OK
 
                 for (n1b = 1; n1b < n1; n1b *= 2) {
                 }
@@ -1137,7 +1139,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                 for (i = -(n1 / 2); i <= n1 / 2; i++) {
                     stage1[i + n1 / 2] = win(i, n1, alp, iza) * hn_lpf(i, lpf, fs1) * fs1 / sfrq / n1b * 2;
-//System.err.printf("1: %06d: %e\n", i + n1 / 2, stage1[i + n1 / 2]); // OK
+//logger.log(Level.DEBUG, String.format("1: %06d: %e", i + n1 / 2, stage1[i + n1 / 2])); // OK
                 }
 
                 ipsize = (int) (2 + Math.sqrt(n1b));
@@ -1148,13 +1150,13 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                 rdft(n1b, 1, stage1, fft_ip, fft_w);
 //for (i = -(n1 / 2); i <= n1 / 2; i++) {
-// System.err.printf("1': %06d: %e\n", i + n1 / 2, stage1[i + n1 / 2]);
+// logger.log(Level.DEBUG, String.format("1': %06d: %e", i + n1 / 2, stage1[i + n1 / 2]));
 //}
 //for (i = 0; i < ipsize; i++) {
-// System.err.printf("ip: %06d: %d\n", i, fft_ip[i]); // OK
+// logger.log(Level.DEBUG, String.format("ip: %06d: %d", i, fft_ip[i])); // OK
 //}
 //for (i = 0; i < wsize; i++) {
-// System.err.printf("w: %06d: %e\n", i, fft_w[i]); // OK
+// logger.log(Level.DEBUG, String.format("w: %06d: %e", i, fft_w[i])); // OK
 //}
             }
 
@@ -1195,7 +1197,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                 alp = alpha(aa);
                 iza = I0Bessel.value(alp);
-//System.err.printf("iza %f, alp: %f\n", iza, alp); // OK
+//logger.log(Level.DEBUG, String.format("iza %f, alp: %f", iza, alp)); // OK
 
                 n2y = fs2 / fs1; // how many samples are there in fs2 that is not 0?
                 n2x = n2 / n2y + 1;
@@ -1218,10 +1220,10 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                 stage2 = new double[n2y][n2x];
 
-//System.err.printf("n2y: %d, n2: %d\n", n2y, n2);
+//logger.log(Level.DEBUG, String.format("n2y: %d, n2: %d", n2y, n2));
                 for (i = -(n2 / 2); i <= n2 / 2; i++) {
                     stage2[(i + n2 / 2) % n2y][(i + n2 / 2) / n2y] = win(i, n2, alp, iza) * hn_lpf(i, lpf, fs2) * fs2 / fs1;
-//System.err.printf(" stage2[%02d][%02d]: %f\n", (i + n2 / 2) % n2y, (i + n2 / 2) / n2y, win(i, n2, alp, iza) * hn_lpf(i, lpf, fs2) * fs2 / fs1); // OK
+//logger.log(Level.DEBUG, String.format(" stage2[%02d][%02d]: %f", (i + n2 / 2) % n2y, (i + n2 / 2) / n2y, win(i, n2, alp, iza) * hn_lpf(i, lpf, fs2) * fs2 / fs1)); // OK
                 }
             }
 
@@ -1266,7 +1268,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                 buf2 = new double[nch][n2x + 1 + n1b2];
 
                 rawinbuf = ByteBuffer.allocate((nch * (n1b2 / osf + osf + 1)) * bps);
-//System.err.println((double) n1b2 * sfrq / dfrq + 1);
+//logger.log(Level.DEBUG, (double) n1b2 * sfrq / dfrq + 1);
                 rawoutbuf = ByteBuffer.allocate((int) (((double) n1b2 * sfrq / dfrq + 1) * (dbps * nch)));
                 inbuf = new double[nch * (n1b2 / osf + osf + 1)];
                 outbuf = new double[(int) (nch * ((double) n1b2 * sfrq / dfrq + 1))];
@@ -1312,7 +1314,7 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                         for (i = 0; i < nsmplread * nch; i++) {
                             int v = rawinbuf.order(byteOrder).asShortBuffer().get(i);
                             inbuf[nch * inbuflen + i] = (1 / (double) 0x7fff) * v;
-//System.err.printf("I: %f\n", inbuf[nch * inbuflen + i]);
+//logger.log(Level.DEBUG, String.format("I: %f", inbuf[nch * inbuflen + i]));
                         }
                         break;
 
@@ -1418,13 +1420,13 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
 
                             assert ((bp2 - (buf2[0].length * ch)) * (fs2 / fs1) - (rp2 + p * (fs2 / dfrq)) == s2o); // &(buf2[ch][0])
                             for (i = 0; i < n2x; i++) {
-//System.err.printf("%d (%d, %d)\n", i, bp2 / buf2[0].length, bp2 % buf2[0].length);
+//logger.log(Level.DEBUG, String.format("%d (%d, %d)", i, bp2 / buf2[0].length, bp2 % buf2[0].length));
                                 tmp += stage2[s2o][i] * buf2[bp2 / buf2[0].length][bp2 % buf2[0].length]; // *bp2++
                                 bp2++;
                             }
 
                             outbuf[op + p * nch + ch] = tmp;
-//System.err.printf("O: %06d: %f\n", op + p * nch + ch, tmp);
+//logger.log(Level.DEBUG, String.format("O: %06d: %f", op + p * nch + ch, tmp));
                         }
 
                         nsmplwrt2 = p;
@@ -1437,12 +1439,12 @@ int resample(ReadableByteChannel fpi, WritableByteChannel fpo) throws IOExceptio
                         for (i = 0; i < nsmplwrt2 * nch; i++) {
                             double f = outbuf[i] > 0 ? outbuf[i] : -outbuf[i];
                             peak[0] = Math.max(peak[0], f);
-//System.err.println("p: " + rawoutbuf.position() + ", l: " + rawoutbuf.limit());
+//logger.log(Level.DEBUG, "p: " + rawoutbuf.position() + ", l: " + rawoutbuf.limit());
                             rawoutbuf.asDoubleBuffer().put(i, outbuf[i]);
 //if (i < 100) {
-// System.err.printf("1: %06d: %f\n", i, outbuf[i]);
+// logger.log(Level.DEBUG, String.format("1: %06d: %f", i, outbuf[i]));
 //}
-//System.err.print(StringUtil.getDump(rawoutbuf, i, 8));
+//logger.log(Level.DEBUG, "\n" + StringUtil.getDump(rawoutbuf, i, 8));
                         }
                     } else {
                         switch (dbps) {
@@ -1806,93 +1808,86 @@ public void exec(String[] argv) throws IOException {
                 break;
             }
 
-            if (argv[i].equals("--rate")) {
-                dfrq = Integer.parseInt(argv[++i]);
-//System.err.printf("dfrq: %d\n", dfrq);
-                continue;
-            }
-
-            if (argv[i].equals("--att")) {
-                att = Float.parseFloat(argv[++i]);
-                continue;
-            }
-
-            if (argv[i].equals("--bits")) {
-                dbps = Integer.parseInt(argv[++i]);
-                if (dbps != 8 && dbps != 16 && dbps != 24) {
-                    throw new IllegalArgumentException("Error: Only 8bit, 16bit and 24bit PCM are supported.");
+            switch (argv[i]) {
+                case "--rate" -> {
+                    dfrq = Integer.parseInt(argv[++i]);
+//logger.log(Level.DEBUG, String.format("dfrq: %d", dfrq));
+                    continue;
                 }
-                dbps /= 8;
-                continue;
-            }
-
-            if (argv[i].equals("--twopass")) {
-                twopass = true;
-                continue;
-            }
-
-            if (argv[i].equals("--normalize")) {
-                twopass = true;
-                normalize = true;
-                continue;
-            }
-
-            if (argv[i].equals("--dither")) {
-                try {
-                    dither = Integer.parseInt(argv[i + 1]);
-                    if (dither < 0 || dither > 4) {
-                        throw new IllegalArgumentException("unrecognized dither type : " + argv[i + 1]);
+                case "--att" -> {
+                    att = Float.parseFloat(argv[++i]);
+                    continue;
+                }
+                case "--bits" -> {
+                    dbps = Integer.parseInt(argv[++i]);
+                    if (dbps != 8 && dbps != 16 && dbps != 24) {
+                        throw new IllegalArgumentException("Error: Only 8bit, 16bit and 24bit PCM are supported.");
                     }
-                    i++;
-                } catch (NumberFormatException e) {
-                    dither = -1;
+                    dbps /= 8;
+                    continue;
+                }
+                case "--twopass" -> {
+                    twopass = true;
+                    continue;
+                }
+                case "--normalize" -> {
+                    twopass = true;
+                    normalize = true;
+                    continue;
+                }
+                case "--dither" -> {
+                    try {
+                        dither = Integer.parseInt(argv[i + 1]);
+                        if (dither < 0 || dither > 4) {
+                            throw new IllegalArgumentException("unrecognized dither type : " + argv[i + 1]);
+                        }
+                        i++;
+                    } catch (NumberFormatException e) {
+                        dither = -1;
+                    }
+                    continue;
                 }
-                continue;
-            }
-
-            if (argv[i].equals("--pdf")) {
-                try {
-                    pdf = Integer.parseInt(argv[i + 1]);
-                    if (pdf < 0 || pdf > 2) {
+                case "--pdf" -> {
+                    try {
+                        pdf = Integer.parseInt(argv[i + 1]);
+                        if (pdf < 0 || pdf > 2) {
+                            throw new IllegalArgumentException("unrecognized p.d.f. type : " + argv[i + 1]);
+                        }
+                        i++;
+                    } catch (NumberFormatException e) {
                         throw new IllegalArgumentException("unrecognized p.d.f. type : " + argv[i + 1]);
                     }
-                    i++;
-                } catch (NumberFormatException e) {
-                    throw new IllegalArgumentException("unrecognized p.d.f. type : " + argv[i + 1]);
-                }
-
-                try {
-                    noiseamp = Double.parseDouble(argv[i + 1]);
-                    i++;
-                } catch (NumberFormatException e) {
-                    noiseamp = presets[pdf];
-                }
-
-                continue;
-            }
-
-            if (argv[i].equals("--quiet")) {
-                quiet = true;
-                continue;
-            }
 
-            if (argv[i].equals("--tmpfile")) {
-                tmpfn = argv[++i];
-                continue;
-            }
+                    try {
+                        noiseamp = Double.parseDouble(argv[i + 1]);
+                        i++;
+                    } catch (NumberFormatException e) {
+                        noiseamp = presets[pdf];
+                    }
 
-            if (argv[i].equals("--profile")) {
-                if (argv[i + 1].equals("fast")) {
-                    AA = 96;
-                    DF = 8000;
-                    FFTFIRLEN = 1024;
-                } else if (argv[i + 1].equals("standard")) {
-                    /* nothing to do */
-                } else {
-                    throw new IllegalArgumentException("unrecognized profile : " + argv[i + 1]);
+                    continue;
+                }
+                case "--quiet" -> {
+                    quiet = true;
+                    continue;
+                }
+                case "--tmpfile" -> {
+                    tmpfn = argv[++i];
+                    continue;
+                }
+                case "--profile" -> {
+                    if (argv[i + 1].equals("fast")) {
+                        AA = 96;
+                        DF = 8000;
+                        FFTFIRLEN = 1024;
+                    } else if (argv[i + 1].equals("standard")) {
+                        /* nothing to do */
+                    } else {
+                        throw new IllegalArgumentException("unrecognized profile : " + argv[i + 1]);
+                    }
+                    i++;
+                    continue;
                 }
-                i++;
-                continue;
             }
 
             throw new IllegalArgumentException("unrecognized option : " + argv[i]);
@@ -1926,7 +1921,7 @@ public void exec(String[] argv) throws IOException {
             bb.limit(36);
             fpi.read(bb);
             bb.flip();
-System.err.println("p: " + bb.position() + ", l: " + bb.limit());
+logger.log(Level.DEBUG, "p: " + bb.position() + ", l: " + bb.limit());
             if (bb.get() != 'R') error(1);
             if (bb.get() != 'I') error(1);
             if (bb.get() != 'F') error(1);
@@ -2118,7 +2113,7 @@ public void exec(String[] argv) throws IOException {
                 try (FileOutputStream tfos= new FileOutputStream(ft)) {
                     fpto = tfos.getChannel();
 
-//System.err.printf("nch: %d, bps: %d, size: %d, sfrq: %d, dfrq: %d, ???: %d, ???: %d, twopass: %b, dither: %d\n", nch, bps, 8, sfrq, dfrq, 1, length / bps / nch, twopass, dither);
+//logger.log(Level.DEBUG, String.format("nch: %d, bps: %d, size: %d, sfrq: %d, dfrq: %d, ???: %d, ???: %d, twopass: %b, dither: %d", nch, bps, 8, sfrq, dfrq, 1, length / bps / nch, twopass, dither));
                     Resampler resampler;
                     if (sfrq < dfrq) {
                         resampler = new Upsampler();
@@ -2157,36 +2152,29 @@ public void exec(String[] argv) throws IOException {
                 }
 
                 if (dither != 0) {
-                    switch (dbps) {
-                    case 1:
-                        gain = (normalize || peak[0] >= (0x7f - samp) / (double) 0x7f) ? 1 / peak[0] * (0x7f - samp) : 1 / peak[0] * 0x7f;
-                        break;
-                    case 2:
-                        gain = (normalize || peak[0] >= (0x7fff - samp) / (double) 0x7fff) ? 1 / peak[0] * (0x7fff - samp) : 1 / peak[0] * 0x7fff;
-                        break;
-                    case 3:
-                        gain = (normalize || peak[0] >= (0x7fffff - samp) / (double) 0x7fffff) ? 1 / peak[0] * (0x7fffff - samp) : 1 / peak[0] * 0x7fffff;
-                        break;
-                    }
+                    gain = switch (dbps) {
+                        case 1 ->
+                                (normalize || peak[0] >= (0x7f - samp) / (double) 0x7f) ? 1 / peak[0] * (0x7f - samp) : 1 / peak[0] * 0x7f;
+                        case 2 ->
+                                (normalize || peak[0] >= (0x7fff - samp) / (double) 0x7fff) ? 1 / peak[0] * (0x7fff - samp) : 1 / peak[0] * 0x7fff;
+                        case 3 ->
+                                (normalize || peak[0] >= (0x7fffff - samp) / (double) 0x7fffff) ? 1 / peak[0] * (0x7fffff - samp) : 1 / peak[0] * 0x7fffff;
+                        default -> gain;
+                    };
                 } else {
-                    switch (dbps) {
-                    case 1:
-                        gain = 1 / peak[0] * 0x7f;
-                        break;
-                    case 2:
-                        gain = 1 / peak[0] * 0x7fff;
-                        break;
-                    case 3:
-                        gain = 1 / peak[0] * 0x7fffff;
-                        break;
-                    }
+                    gain = switch (dbps) {
+                        case 1 -> 1 / peak[0] * 0x7f;
+                        case 2 -> 1 / peak[0] * 0x7fff;
+                        case 3 -> 1 / peak[0] * 0x7fffff;
+                        default -> gain;
+                    };
                 }
                 shaper.randPtr = 0;
 
                 setStartTime();
 
                 fptlen = (int) (ft.length() / 8);
-//System.err.println("tmp: " + fpt.getFilePointer());
+//logger.log(Level.DEBUG, "tmp: " + fpt.getFilePointer());
 
                 try (FileInputStream fisf = new FileInputStream(ft)) {
                     FileChannel fpti = fisf.getChannel();
@@ -2200,7 +2188,7 @@ public void exec(String[] argv) throws IOException {
                         bb.flip();
                         f = bb.getDouble();
 //if (sumread < 100) {
-// System.err.printf("2: %06d: %f\n", sumread, f);
+// logger.log(Level.DEBUG, String.format("2: %06d: %f", sumread, f));
 //}
                         f *= gain;
                         sumread++;
@@ -2257,7 +2245,7 @@ public void exec(String[] argv) throws IOException {
                     }
                     fpti.close();
                 }
-                //System.err.println("ft: " + ft);
+                //logger.log(Level.DEBUG, "ft: " + ft);
                 if (!ft.delete()) {
                     System.err.printf("Failed to remove %s\n", ft);
                 }
@@ -2358,7 +2346,7 @@ void io(ReadableByteChannel fpi, WritableByteChannel fpo, int length, int nch, i
             break;
         }
 
-logger.fine(String.format("nch: %d, sfrq: %d, bps: %d, sfrq: %d, bps: %d\n", nch, sfrq, bps, dfrq, dbps));
+logger.log(Level.DEBUG, String.format("nch: %d, sfrq: %d, bps: %d, sfrq: %d, bps: %d", nch, sfrq, bps, dfrq, dbps));
 
         if (bps != 1 && bps != 2 && bps != 3 && bps != 4) {
             throw new IllegalArgumentException("Only 8bit, 16bit, 24bit and 32bit PCM are supported.");
@@ -2432,7 +2420,7 @@ void io(ReadableByteChannel fpi, WritableByteChannel fpo, int length, int nch, i
                     System.err.print("Pass 1\n");
                 }
 
-logger.fine(String.format("nch: %d, bps: %d, size: %d, sfrq: %d, dfrq: %d, ???: %d, ???: %d, twopass: %b, dither: %d\n", nch, bps, 8, sfrq, dfrq, 1, length / bps / nch, twopass, dither));
+logger.log(Level.DEBUG, String.format("nch: %d, bps: %d, size: %d, sfrq: %d, dfrq: %d, ???: %d, ???: %d, twopass: %b, dither: %d", nch, bps, 8, sfrq, dfrq, 1, length / bps / nch, twopass, dither));
                 Resampler resampler;
                 if (sfrq < dfrq) {
                     resampler = new Upsampler();
@@ -2470,29 +2458,22 @@ void io(ReadableByteChannel fpi, WritableByteChannel fpo, int length, int nch, i
                 }
 
                 if (dither != 0) {
-                    switch (dbps) {
-                    case 1:
-                        gain = (normalize || peak[0] >= (0x7f - samp) / (double) 0x7f) ? 1 / peak[0] * (0x7f - samp) : 1 / peak[0] * 0x7f;
-                        break;
-                    case 2:
-                        gain = (normalize || peak[0] >= (0x7fff - samp) / (double) 0x7fff) ? 1 / peak[0] * (0x7fff - samp) : 1 / peak[0] * 0x7fff;
-                        break;
-                    case 3:
-                        gain = (normalize || peak[0] >= (0x7fffff - samp) / (double) 0x7fffff) ? 1 / peak[0] * (0x7fffff - samp) : 1 / peak[0] * 0x7fffff;
-                        break;
-                    }
+                    gain = switch (dbps) {
+                        case 1 ->
+                                (normalize || peak[0] >= (0x7f - samp) / (double) 0x7f) ? 1 / peak[0] * (0x7f - samp) : 1 / peak[0] * 0x7f;
+                        case 2 ->
+                                (normalize || peak[0] >= (0x7fff - samp) / (double) 0x7fff) ? 1 / peak[0] * (0x7fff - samp) : 1 / peak[0] * 0x7fff;
+                        case 3 ->
+                                (normalize || peak[0] >= (0x7fffff - samp) / (double) 0x7fffff) ? 1 / peak[0] * (0x7fffff - samp) : 1 / peak[0] * 0x7fffff;
+                        default -> gain;
+                    };
                 } else {
-                    switch (dbps) {
-                    case 1:
-                        gain = 1 / peak[0] * 0x7f;
-                        break;
-                    case 2:
-                        gain = 1 / peak[0] * 0x7fff;
-                        break;
-                    case 3:
-                        gain = 1 / peak[0] * 0x7fffff;
-                        break;
-                    }
+                    gain = switch (dbps) {
+                        case 1 -> 1 / peak[0] * 0x7f;
+                        case 2 -> 1 / peak[0] * 0x7fff;
+                        case 3 -> 1 / peak[0] * 0x7fffff;
+                        default -> gain;
+                    };
                 }
                 shaper.randPtr = 0;
 
@@ -2510,7 +2491,7 @@ void io(ReadableByteChannel fpi, WritableByteChannel fpo, int length, int nch, i
                     bb.flip();
                     f = bb.getDouble();
 //if (sumread < 100) {
-// System.err.printf("2: %06d: %f\n", sumread, f);
+// logger.log(Level.DEBUG, String.format("2: %06d: %f", sumread, f));
 //}
                     f *= gain;
                     sumread++;
diff --git a/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRCInputStream.java b/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRCInputStream.java
index 81ca167..50bdf24 100644
--- a/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRCInputStream.java
+++ b/src/main/java/vavi/sound/pcm/resampling/ssrc/SSRCInputStream.java
@@ -9,6 +9,8 @@
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.nio.channels.Channels;
 import java.nio.channels.Pipe;
 import java.util.Map;
@@ -16,6 +18,8 @@
 import java.util.concurrent.Executors;
 import javax.sound.sampled.AudioFormat;
 
+import static java.lang.System.getLogger;
+
 
 /**
  * SSRC InputStream
@@ -32,6 +36,8 @@
  */
 public class SSRCInputStream extends FilterInputStream {
 
+    private static final Logger logger = getLogger(SSRCInputStream.class.getName());
+
     /** use in properties */
     public SSRCInputStream(AudioFormat in, AudioFormat out, InputStream is) throws IOException {
 
@@ -44,7 +50,7 @@ public SSRCInputStream(AudioFormat in, AudioFormat out, InputStream is) throws I
                    in.properties()));
     }
 
-    private static ExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+    private static final ExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
 
     /**
      * @param in source stream
@@ -65,7 +71,7 @@ private static InputStream init(InputStream in, int ch, int iFrq, int iBps, int
                 ssrc.io(Channels.newChannel(in), pipe.sink(), in.available(), ch, iFrq, iBps, oFrq, oBps, props);
                 pipe.sink().close();
             } catch (IOException e) {
-                e.printStackTrace();
+                logger.log(Level.ERROR, e.getMessage(), e);
             }
         });
         return Channels.newInputStream(pipe.source());
diff --git a/src/main/java/vavi/sound/sampled/MonauralInputFilter.java b/src/main/java/vavi/sound/sampled/MonauralInputFilter.java
index d7ece05..1c7ac01 100644
--- a/src/main/java/vavi/sound/sampled/MonauralInputFilter.java
+++ b/src/main/java/vavi/sound/sampled/MonauralInputFilter.java
@@ -7,14 +7,14 @@
 package vavi.sound.sampled;
 
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
 
 
 /**
@@ -27,6 +27,8 @@
  */
 public class MonauralInputFilter implements InputFilter {
 
+    private static final Logger logger = getLogger(MonauralInputFilter.class.getName());
+
     @Override
     public AudioInputStream doFilter(AudioInputStream sourceAis) throws IOException, UnsupportedAudioFileException {
         AudioFormat inAudioFormat = sourceAis.getFormat();
@@ -42,8 +44,8 @@ public AudioInputStream doFilter(AudioInputStream sourceAis) throws IOException,
             inAudioFormat.getFrameSize(),
             inAudioFormat.getFrameRate(),
             inAudioFormat.isBigEndian());
-Debug.println(Level.FINE, "OUT: " + outAudioFormat);
-Debug.println(Level.FINE, "OK: " + AudioSystem.isConversionSupported(outAudioFormat, inAudioFormat));
+logger.log(Level.DEBUG, "OUT: " + outAudioFormat);
+logger.log(Level.DEBUG, "OK: " + AudioSystem.isConversionSupported(outAudioFormat, inAudioFormat));
 
         return AudioSystem.getAudioInputStream(outAudioFormat, sourceAis);
     }
diff --git a/src/main/java/vavi/sound/sampled/Pcm16BitMonauralWaveDivider.java b/src/main/java/vavi/sound/sampled/Pcm16BitMonauralWaveDivider.java
index 35c8797..aeed46d 100644
--- a/src/main/java/vavi/sound/sampled/Pcm16BitMonauralWaveDivider.java
+++ b/src/main/java/vavi/sound/sampled/Pcm16BitMonauralWaveDivider.java
@@ -8,12 +8,9 @@
 
 import java.io.EOFException;
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioInputStream;
 
-import vavi.util.Debug;
-
 
 /**
  * Pcm16BitMonauralWaveDivider.
@@ -48,25 +45,25 @@ class Pcm16BitMonauralWaveDivider implements WaveDivider {
     public void divide(float seconds, Event event) throws IOException {
 
         int numberChannels = targetAis.getFormat().getChannels();
-Debug.println(Level.FINE, "numberChannels: " + numberChannels);
+logger.log(Level.DEBUG, "numberChannels: " + numberChannels);
 
         int samplingRate = (int) targetAis.getFormat().getSampleRate();
-Debug.println(Level.FINE, "samplingRate: " + samplingRate);
+logger.log(Level.DEBUG, "samplingRate: " + samplingRate);
         int samplingBytes = targetAis.getFormat().getSampleSizeInBits() / 8;
-Debug.println(Level.FINE, "samplingBytes: " + samplingBytes);
+logger.log(Level.DEBUG, "samplingBytes: " + samplingBytes);
         int bytesPerSecond = samplingRate * samplingBytes;
-Debug.println(Level.FINE, "bytesPerSecond: " + bytesPerSecond);
-Debug.println(Level.FINE, "header.bytesPerSecond: " + targetAis.getFormat().getFrameSize() * targetAis.getFormat().getFrameRate());
+logger.log(Level.DEBUG, "bytesPerSecond: " + bytesPerSecond);
+logger.log(Level.DEBUG, "header.bytesPerSecond: " + targetAis.getFormat().getFrameSize() * targetAis.getFormat().getFrameRate());
         long totalTime = (long) (targetAis.available() / (targetAis.getFormat().getFrameSize() * targetAis.getFormat().getFrameRate()) * 1000);
-Debug.println(Level.FINE, "totalTime= " + (totalTime / (60 * 1000)) + ":" + ((totalTime % (60 * 1000)) / 1000) + "." + ((totalTime % (60 * 1000)) % 1000));
+logger.log(Level.DEBUG, "totalTime= " + (totalTime / (60 * 1000)) + ":" + ((totalTime % (60 * 1000)) / 1000) + "." + ((totalTime % (60 * 1000)) % 1000));
 
         // all channel, per second
         int blockSize = samplingRate * numberChannels * samplingBytes;
-Debug.println(Level.FINE, "blockSize: " + blockSize);
+logger.log(Level.DEBUG, "blockSize: " + blockSize);
 
         int numberOfChunks = targetAis.available() / (int) (blockSize * seconds);
         int moduloOfChunks = targetAis.available() % (int) (blockSize * seconds);
-Debug.println(Level.FINE, "numberOfChunks: " + numberOfChunks + ", moduloOfChunks: " + moduloOfChunks);
+logger.log(Level.DEBUG, "numberOfChunks: " + numberOfChunks + ", moduloOfChunks: " + moduloOfChunks);
 
         for (int i = 0; i < numberOfChunks; i++) {
             byte[] buffer = new byte[(int) (blockSize * seconds)];
@@ -78,7 +75,7 @@ public void divide(float seconds, Event event) throws IOException {
                 }
                 l += r;
             }
-Debug.println(Level.FINE, "CHUNK[" + i + "] " + buffer.length + " bytes");
+logger.log(Level.DEBUG, "CHUNK[" + i + "] " + buffer.length + " bytes");
             event.exec(new Chunk(i, buffer, samplingRate, samplingBytes * 8, numberChannels));
         }
         if (moduloOfChunks >= 0) {
@@ -92,7 +89,7 @@ public void divide(float seconds, Event event) throws IOException {
                 l += r;
             }
             event.exec(new Chunk(numberOfChunks, buffer, samplingRate, samplingBytes * 8, numberChannels));
-Debug.println(Level.FINE, "modulo bytes: " + buffer.length + ", " + (((totalTime / 1000) % seconds) + 1) + " [s]");
+logger.log(Level.DEBUG, "modulo bytes: " + buffer.length + ", " + (((totalTime / 1000) % seconds) + 1) + " [s]");
         }
     }
 }
diff --git a/src/main/java/vavi/sound/sampled/SimpleResamplingInputFilter.java b/src/main/java/vavi/sound/sampled/SimpleResamplingInputFilter.java
index 7c72627..0aba2fd 100644
--- a/src/main/java/vavi/sound/sampled/SimpleResamplingInputFilter.java
+++ b/src/main/java/vavi/sound/sampled/SimpleResamplingInputFilter.java
@@ -7,14 +7,14 @@
 package vavi.sound.sampled;
 
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
 
 
 /**
@@ -27,8 +27,10 @@
  */
 public class SimpleResamplingInputFilter implements InputFilter {
 
+    private static final Logger logger = getLogger(SimpleResamplingInputFilter.class.getName());
+
     /** */
-    protected int outSamplingRate;
+    protected final int outSamplingRate;
 
     /** */
     public SimpleResamplingInputFilter(int outSamplingRate) {
@@ -38,7 +40,7 @@ public SimpleResamplingInputFilter(int outSamplingRate) {
     @Override
     public AudioInputStream doFilter(AudioInputStream sourceAis) throws IOException, UnsupportedAudioFileException {
         AudioFormat inAudioFormat = sourceAis.getFormat();
-Debug.println(Level.FINE, "IN: " + inAudioFormat);
+logger.log(Level.DEBUG, "IN: " + inAudioFormat);
         // 1: PCM_SIGNED ? Hz, 16 bit, stereo, 2 bytes/frame, little-endian
         AudioFormat outAudioFormat = new AudioFormat(
             inAudioFormat.getEncoding(),
@@ -48,8 +50,8 @@ public AudioInputStream doFilter(AudioInputStream sourceAis) throws IOException,
             inAudioFormat.getFrameSize(),
             inAudioFormat.getFrameRate(),
             inAudioFormat.isBigEndian());
-Debug.println(Level.FINE, "OUT: " + outAudioFormat);
-Debug.println(Level.FINE, "OK: " + AudioSystem.isConversionSupported(outAudioFormat, inAudioFormat));
+logger.log(Level.DEBUG, "OUT: " + outAudioFormat);
+logger.log(Level.DEBUG, "OK: " + AudioSystem.isConversionSupported(outAudioFormat, inAudioFormat));
 
         return AudioSystem.getAudioInputStream(outAudioFormat, sourceAis);
     }
diff --git a/src/main/java/vavi/sound/sampled/TemporaryFiledInputFilter.java b/src/main/java/vavi/sound/sampled/TemporaryFiledInputFilter.java
index 1642b4b..f34e6f1 100644
--- a/src/main/java/vavi/sound/sampled/TemporaryFiledInputFilter.java
+++ b/src/main/java/vavi/sound/sampled/TemporaryFiledInputFilter.java
@@ -8,14 +8,14 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioFileFormat;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
 
 
 /**
@@ -26,12 +26,14 @@
  */
 public class TemporaryFiledInputFilter implements InputFilter {
 
+    private static final Logger logger = getLogger(TemporaryFiledInputFilter.class.getName());
+
     @Override
     public AudioInputStream doFilter(AudioInputStream sourceAis) throws IOException, UnsupportedAudioFileException {
         // once write into temp
         File tmpFile = File.createTempFile("temp", ".wav");
         int r = AudioSystem.write(sourceAis, AudioFileFormat.Type.WAVE, tmpFile);
-Debug.println(Level.FINE, "RESULT: " + r);
+logger.log(Level.DEBUG, "RESULT: " + r);
 
         return AudioSystem.getAudioInputStream(tmpFile);
     }
diff --git a/src/main/java/vavi/sound/sampled/WaveDivider.java b/src/main/java/vavi/sound/sampled/WaveDivider.java
index 2f6bb1b..a20f504 100644
--- a/src/main/java/vavi/sound/sampled/WaveDivider.java
+++ b/src/main/java/vavi/sound/sampled/WaveDivider.java
@@ -7,13 +7,13 @@
 package vavi.sound.sampled;
 
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import javax.sound.sampled.AudioFormat.Encoding;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.UnsupportedAudioFileException;
-import javax.sound.sampled.AudioFormat.Encoding;
 
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
 
 
 /**
@@ -24,18 +24,20 @@
  */
 public interface WaveDivider {
 
+    Logger logger = getLogger(WaveDivider.class.getName());
+
     /** Represents divided PCM data */
     class Chunk {
         /** Sequence number */
-        public int sequence;
+        public final int sequence;
         /** sampling rate */
-        public int samplingRate;
+        public final int samplingRate;
         /** sampling bits */
-        public int bits;
+        public final int bits;
         /** channel number */
-        public int channels;
+        public final int channels;
         /** PCM dara */
-        public byte[] buffer;
+        public final byte[] buffer;
         /** */
         Chunk(int sequence, byte[] buffer, int samplingRate, int bits, int channels) {
             this.sequence = sequence;
@@ -57,7 +59,7 @@ public static WaveDivider getWaveDivider(AudioInputStream audioInputStream) thro
                     return new Pcm16BitMonauralWaveDivider(new MonauralInputFilter().doFilter(audioInputStream));
                 }
             } else {
-Debug.println(Level.INFO, "unsupported type: " + audioInputStream.getFormat());
+logger.log(Level.INFO, "unsupported type: " + audioInputStream.getFormat());
                 throw new IllegalArgumentException("only pcm mono is supported.");
             }
         }
diff --git a/src/main/java/vavi/sound/sampled/adpcm/AdpcmWaveAudioFileReader.java b/src/main/java/vavi/sound/sampled/adpcm/AdpcmWaveAudioFileReader.java
index 068e1ca..a7efe78 100644
--- a/src/main/java/vavi/sound/sampled/adpcm/AdpcmWaveAudioFileReader.java
+++ b/src/main/java/vavi/sound/sampled/adpcm/AdpcmWaveAudioFileReader.java
@@ -10,11 +10,12 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.net.URL;
 import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.logging.Level;
 import javax.sound.sampled.AudioFileFormat;
 import javax.sound.sampled.AudioFileFormat.Type;
 import javax.sound.sampled.AudioFormat;
@@ -28,6 +29,8 @@
 import vavi.util.win32.Chunk;
 import vavi.util.win32.WAVE;
 
+import static java.lang.System.getLogger;
+
 
 /**
  * Provider for some ADPCM audio files reading services. This implementation can parse
@@ -39,6 +42,8 @@
  */
 public abstract class AdpcmWaveAudioFileReader extends AudioFileReader {
 
+    private static final Logger logger = getLogger(AdpcmWaveAudioFileReader.class.getName());
+
     @Override
     public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
         try (InputStream inputStream = Files.newInputStream(file.toPath())) {
@@ -86,7 +91,7 @@ protected int getBufferSize() {
      * @throws IOException                   if an I/O exception occurs.
      */
     protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLength) throws UnsupportedAudioFileException, IOException {
-Debug.println(Level.FINER, "enter available: " + bitStream.available() + ", " + getClass().getSimpleName());
+logger.log(Level.TRACE, "enter available: " + bitStream.available() + ", " + getClass().getSimpleName());
         float sampleRate;
         int channels;
         AudioFormat.Encoding encoding;
@@ -102,37 +107,37 @@ protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLen
             WAVE wave = Chunk.readFrom(is, WAVE.class, context);
             WAVE.fmt fmt = wave.findChildOf(WAVE.fmt.class);
             int formatCode = fmt.getFormatId();
- Debug.println(Level.FINER, "formatCode: " + formatCode);
+ logger.log(Level.TRACE, "formatCode: " + formatCode);
             if (formatCode != getFormatCode()) {
- Debug.println(Level.FINER, "unsupported wave format code: " + formatCode);
+ logger.log(Level.TRACE, "unsupported wave format code: " + formatCode);
                 throw new UnsupportedAudioFileException("unsupported wave format code: " + formatCode);
             }
             sampleRate = fmt.getSamplingRate();
             channels = fmt.getNumberChannels();
             properties = toProperties(fmt);
- Debug.println(Level.FINER, "properties: " + properties);
+ logger.log(Level.TRACE, "properties: " + properties);
         } catch (IOException e) {
             if (e.getMessage().equals(LimitedInputStream.ERROR_MESSAGE_REACHED_TO_LIMIT)) {
-Debug.println(Level.FINER, e);
-Debug.printStackTrace(Level.FINEST, e);
+logger.log(Level.DEBUG, e);
+logger.log(Level.TRACE, e.getMessage(), e);
                 throw (UnsupportedAudioFileException) new UnsupportedAudioFileException(e.getMessage()).initCause(e);
             } else {
                 throw e;
             }
         } catch (Exception e) {
-Debug.println(Level.FINER, e);
-Debug.printStackTrace(Level.FINEST, e);
+logger.log(Level.DEBUG, e);
+logger.log(Level.TRACE, e.getMessage(), e);
             throw (UnsupportedAudioFileException) new UnsupportedAudioFileException(e.getMessage()).initCause(e);
         } finally {
             try {
                 bitStream.reset();
             } catch (IOException e) {
-                if (Debug.isLoggable(Level.FINEST))
-Debug.printStackTrace(e);
+                if (Debug.isLoggable(java.util.logging.Level.FINEST))
+logger.log(Level.ERROR, e.getMessage(), e);
                 else
-Debug.println(Level.FINE, e);
+logger.log(Level.DEBUG, e);
             }
-Debug.println(Level.FINER, "finally available: " + bitStream.available());
+logger.log(Level.TRACE, "finally available: " + bitStream.available());
         }
         AudioFormat format;
         if (properties == null) {
diff --git a/src/main/java/vavi/sound/sampled/mfi/DividedMfiWithVoiceMaker.java b/src/main/java/vavi/sound/sampled/mfi/DividedMfiWithVoiceMaker.java
index 1501242..1fb972a 100644
--- a/src/main/java/vavi/sound/sampled/mfi/DividedMfiWithVoiceMaker.java
+++ b/src/main/java/vavi/sound/sampled/mfi/DividedMfiWithVoiceMaker.java
@@ -8,8 +8,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
@@ -18,11 +18,11 @@
 import org.klab.commons.cli.HelpOption;
 import org.klab.commons.cli.Option;
 import org.klab.commons.cli.Options;
-
 import vavi.sound.mfi.InvalidMfiDataException;
 import vavi.sound.sampled.FilterChain;
 import vavi.sound.sampled.WaveDivider;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -33,13 +33,15 @@
  */
 class DividedMfiWithVoiceMaker extends MfiWithVoiceMaker {
 
+    private static final Logger logger = getLogger(DividedMfiWithVoiceMaker.class.getName());
+
     /** source PCM */
-    private AudioInputStream sourceAis;
+    private final AudioInputStream sourceAis;
 
     /** output base directory */
-    private String directory;
+    private final String directory;
     /** output file template (use {@link String#format(String, Object...)}) */
-    private String base;
+    private final String base;
 
     /** */
     private static int toReal(int base, int percent) {
@@ -78,7 +80,7 @@ public void exec(WaveDivider.Chunk chunk) throws IOException {
                 File file = new File(directory, String.format(base, chunk.sequence + 1));
                 r += createMFi(chunk.buffer, file);
             } catch (InvalidMfiDataException e) {
-                throw (IOException) new IOException(e);
+                throw new IOException(e);
             }
         }
     }
@@ -96,10 +98,10 @@ public int create() throws IOException, UnsupportedAudioFileException, InvalidMf
         // divide
         Event event = new Event();
         WaveDivider waveDivider = WaveDivider.Factory.getWaveDivider(sourceAis);
-Debug.println(Level.FINE, "1: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "1: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         waveDivider.divide(time, event);
-Debug.println(Level.FINE, "2: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "2: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         return event.r;
     }
diff --git a/src/main/java/vavi/sound/sampled/mfi/MFi.java b/src/main/java/vavi/sound/sampled/mfi/MFi.java
index 9b605b9..2f5a30c 100644
--- a/src/main/java/vavi/sound/sampled/mfi/MFi.java
+++ b/src/main/java/vavi/sound/sampled/mfi/MFi.java
@@ -39,7 +39,7 @@ public MFi(Map properties) {
     }
 
     /** */
-    private Map properties;
+    private final Map properties;
 
     /** */
     public Map properties() {
diff --git a/src/main/java/vavi/sound/sampled/mfi/MfiAudioFileWriter.java b/src/main/java/vavi/sound/sampled/mfi/MfiAudioFileWriter.java
index caf1446..327a228 100644
--- a/src/main/java/vavi/sound/sampled/mfi/MfiAudioFileWriter.java
+++ b/src/main/java/vavi/sound/sampled/mfi/MfiAudioFileWriter.java
@@ -9,15 +9,17 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.nio.file.Files;
-
 import javax.sound.sampled.AudioFileFormat.Type;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.UnsupportedAudioFileException;
 import javax.sound.sampled.spi.AudioFileWriter;
 
 import vavi.sound.mfi.InvalidMfiDataException;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -28,6 +30,8 @@
  */
 public class MfiAudioFileWriter extends AudioFileWriter {
 
+    private static final Logger logger = getLogger(MfiAudioFileWriter.class.getName());
+
     /** */
     private static final Type[] outputTypes = new Type[] {
         new MFi(null) // TODO null
@@ -90,9 +94,9 @@ public int write(AudioInputStream stream, Type fileType, OutputStream out) throw
                 return r;
             }
         } catch (UnsupportedAudioFileException | InvalidMfiDataException e) {
-            throw (IOException) new IOException(e);
+            throw new IOException(e);
         } catch (IllegalArgumentException e) {
-Debug.printStackTrace(e);
+logger.log(Level.ERROR, e.getMessage(), e);
             throw e;
         }
     }
diff --git a/src/main/java/vavi/sound/sampled/mfi/MfiWithVoiceMaker.java b/src/main/java/vavi/sound/sampled/mfi/MfiWithVoiceMaker.java
index 85dd7ed..1dd6d23 100644
--- a/src/main/java/vavi/sound/sampled/mfi/MfiWithVoiceMaker.java
+++ b/src/main/java/vavi/sound/sampled/mfi/MfiWithVoiceMaker.java
@@ -8,9 +8,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.util.Properties;
-import java.util.logging.Level;
-
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
@@ -19,7 +19,6 @@
 import org.klab.commons.cli.HelpOption;
 import org.klab.commons.cli.Option;
 import org.klab.commons.cli.Options;
-
 import vavi.sound.mfi.InvalidMfiDataException;
 import vavi.sound.mfi.MfiEvent;
 import vavi.sound.mfi.MfiMessage;
@@ -33,7 +32,8 @@
 import vavi.sound.mfi.vavi.header.VersMessage;
 import vavi.sound.mfi.vavi.track.EndOfTrackMessage;
 import vavi.sound.sampled.FilterChain;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -44,6 +44,8 @@
  */
 class MfiWithVoiceMaker {
 
+    private static final Logger logger = getLogger(MfiWithVoiceMaker.class.getName());
+
     /** source PCM */
     private AudioInputStream sourceAis;
 
@@ -116,7 +118,7 @@ protected MfiWithVoiceMaker(String model, float time, int samplingRate, int bits
     public int create() throws IOException, UnsupportedAudioFileException, InvalidMfiDataException {
 long t = System.currentTimeMillis();
         // divide
-Debug.println(Level.FINE, "1: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "1: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         byte[] buffer = new byte[sourceAis.available()];
         int l = 0;
@@ -125,7 +127,7 @@ public int create() throws IOException, UnsupportedAudioFileException, InvalidMf
             l += r;
         }
         int result = createMFi(buffer, new File(filename));
-Debug.println(Level.FINE, "2: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "2: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         return result;
     }
@@ -174,7 +176,7 @@ protected int createMFi(byte[] data, File file) throws InvalidMfiDataException,
         }
 
         int r = MfiSystem.write(sequence, VaviMfiFileFormat.FILE_TYPE, file);
-Debug.println(Level.FINE, "write: " + r);
+logger.log(Level.DEBUG, "write: " + r);
         return r;
     }
 
@@ -201,7 +203,7 @@ protected int createMFi(byte[] data, File file) throws InvalidMfiDataException,
             sorc = Integer.parseInt(props.getProperty("sorc"));
             defaultModel = props.getProperty("defaultModel");
         } catch (Exception e) {
-            Debug.printStackTrace(e);
+            logger.log(Level.ERROR, e.getMessage(), e);
         }
     }
 
diff --git a/src/main/java/vavi/sound/sampled/smaf/DividedSmafWithVoiceMaker.java b/src/main/java/vavi/sound/sampled/smaf/DividedSmafWithVoiceMaker.java
index bc7bed6..2354aa1 100644
--- a/src/main/java/vavi/sound/sampled/smaf/DividedSmafWithVoiceMaker.java
+++ b/src/main/java/vavi/sound/sampled/smaf/DividedSmafWithVoiceMaker.java
@@ -8,8 +8,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
@@ -18,11 +18,11 @@
 import org.klab.commons.cli.HelpOption;
 import org.klab.commons.cli.Option;
 import org.klab.commons.cli.Options;
-
 import vavi.sound.sampled.FilterChain;
 import vavi.sound.sampled.WaveDivider;
 import vavi.sound.smaf.InvalidSmafDataException;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -33,13 +33,15 @@
  */
 class DividedSmafWithVoiceMaker extends SmafWithVoiceMaker {
 
+    private static final Logger logger = getLogger(DividedSmafWithVoiceMaker.class.getName());
+
     /** source PCM */
-    private AudioInputStream sourceAis;
+    private final AudioInputStream sourceAis;
 
     /** output base directory */
-    private String directory;
+    private final String directory;
     /** output file template (use {@link String#format(String, Object...)}) */
-    private String base;
+    private final String base;
 
     /**
      *
@@ -70,10 +72,10 @@ private class Event implements WaveDivider.Event {
         public void exec(WaveDivider.Chunk chunk) throws IOException {
             try {
                 File file = new File(directory, String.format(base, chunk.sequence + 1));
-Debug.println(Level.FINE, "file: " + file + ", " + directory + ", " + base + ", " + (chunk.sequence + 1));
+logger.log(Level.DEBUG, "file: " + file + ", " + directory + ", " + base + ", " + (chunk.sequence + 1));
                 r += createSMAF(chunk.buffer, file);
             } catch (InvalidSmafDataException e) {
-                throw (IOException) new IOException(e);
+                throw new IOException(e);
             }
         }
     }
@@ -91,10 +93,10 @@ public int create() throws IOException, UnsupportedAudioFileException, InvalidSm
         // divide
         Event event = new Event();
         WaveDivider waveDivider = WaveDivider.Factory.getWaveDivider(sourceAis);
-Debug.println(Level.FINE, "1: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "1: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         waveDivider.divide(time, event);
-Debug.println(Level.FINE, "2: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "2: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         return event.r;
     }
diff --git a/src/main/java/vavi/sound/sampled/smaf/SMAF.java b/src/main/java/vavi/sound/sampled/smaf/SMAF.java
index c24a113..bd24da2 100644
--- a/src/main/java/vavi/sound/sampled/smaf/SMAF.java
+++ b/src/main/java/vavi/sound/sampled/smaf/SMAF.java
@@ -38,7 +38,7 @@ public SMAF(Map properties) {
     }
 
     /** */
-    private Map properties;
+    private final Map properties;
 
     /** */
     public Map properties() {
diff --git a/src/main/java/vavi/sound/sampled/smaf/SmafWithVoiceMaker.java b/src/main/java/vavi/sound/sampled/smaf/SmafWithVoiceMaker.java
index ade8619..c7cd73f 100644
--- a/src/main/java/vavi/sound/sampled/smaf/SmafWithVoiceMaker.java
+++ b/src/main/java/vavi/sound/sampled/smaf/SmafWithVoiceMaker.java
@@ -8,12 +8,12 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Properties;
-import java.util.logging.Level;
-
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.UnsupportedAudioFileException;
@@ -22,7 +22,6 @@
 import org.klab.commons.cli.HelpOption;
 import org.klab.commons.cli.Option;
 import org.klab.commons.cli.Options;
-
 import vavi.sound.mobile.AudioEngine;
 import vavi.sound.sampled.FilterChain;
 import vavi.sound.smaf.InvalidSmafDataException;
@@ -32,16 +31,17 @@
 import vavi.sound.smaf.chunk.FileChunk;
 import vavi.sound.smaf.chunk.PcmAudioTrackChunk;
 import vavi.sound.smaf.chunk.SeekAndPhraseInfoChunk;
-import vavi.sound.smaf.chunk.WaveDataChunk;
-import vavi.sound.smaf.chunk.WaveType;
 import vavi.sound.smaf.chunk.TrackChunk.FormatType;
 import vavi.sound.smaf.chunk.TrackChunk.SequenceType;
+import vavi.sound.smaf.chunk.WaveDataChunk;
+import vavi.sound.smaf.chunk.WaveType;
 import vavi.sound.smaf.message.EndOfSequenceMessage;
 import vavi.sound.smaf.message.NopMessage;
 import vavi.sound.smaf.message.VolumeMessage;
 import vavi.sound.smaf.message.WaveMessage;
 import vavi.sound.smaf.sequencer.WaveSequencer;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -52,6 +52,8 @@
  */
 class SmafWithVoiceMaker {
 
+    private static final Logger logger = getLogger(SmafWithVoiceMaker.class.getName());
+
     /** source PCM */
     private AudioInputStream sourceAis;
 
@@ -115,7 +117,7 @@ protected SmafWithVoiceMaker(float time, int samplingRate, int bits, int channel
     public int create() throws IOException, UnsupportedAudioFileException, InvalidSmafDataException {
 long t = System.currentTimeMillis();
         // divide
-Debug.println(Level.FINE, "1: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "1: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         byte[] buffer = new byte[sourceAis.available()];
         int l = 0;
@@ -124,7 +126,7 @@ public int create() throws IOException, UnsupportedAudioFileException, InvalidSm
             l += r;
         }
         int result = createSMAF(buffer, new File(filename));
-Debug.println(Level.FINE, "2: " + (System.currentTimeMillis() - t));
+logger.log(Level.DEBUG, "2: " + (System.currentTimeMillis() - t));
 t = System.currentTimeMillis();
         return result;
     }
@@ -160,11 +162,11 @@ protected int createSMAF(byte[] data, File file) throws InvalidSmafDataException
 
         int timeBase = 4; // [ms]
 
-Debug.println(Level.FINE, "time: " + time + ", " + data.length);
+logger.log(Level.DEBUG, "time: " + time + ", " + data.length);
         int numberOfChunks = (int) ((time * 1000) / (NopMessage.maxSteps * timeBase));
-Debug.println(Level.FINE, "numberOfChunks: " + numberOfChunks);
+logger.log(Level.DEBUG, "numberOfChunks: " + numberOfChunks);
         int moduloOfChunks = (int) ((time * 1000) % (NopMessage.maxSteps * timeBase) / timeBase);
-Debug.println(Level.FINE, "moduloOfChunks: " + moduloOfChunks);
+logger.log(Level.DEBUG, "moduloOfChunks: " + moduloOfChunks);
 
         int messageBytes = 0;
         int streamNumber = 1;
@@ -173,41 +175,41 @@ protected int createSMAF(byte[] data, File file) throws InvalidSmafDataException
         SmafMessage message = new VolumeMessage(0, 0, 127);
         audioSequenceDataChunk.addSmafMessage(message);
         messageBytes += message.getLength();
-//Debug.println("messageBytes: volume: " + messageBytes);
+//logger.log(Level.DEBUG, "messageBytes: volume: " + messageBytes);
         for (int i = 0; i < numberOfChunks; i++) {
             message = new WaveMessage(0, 0, streamNumber++, NopMessage.maxSteps);
             audioSequenceDataChunk.addSmafMessage(message);
             messageBytes += message.getLength();
-//Debug.println("messageBytes: wave: " + messageBytes);
+//logger.log(Level.DEBUG, "messageBytes: wave: " + messageBytes);
 
             message = new NopMessage(NopMessage.maxSteps);
             audioSequenceDataChunk.addSmafMessage(message);
             messageBytes += message.getLength();
-//Debug.println("messageBytes: nop: " + messageBytes);
+//logger.log(Level.DEBUG, "messageBytes: nop: " + messageBytes);
         }
         if (moduloOfChunks != 0) {
             message = new WaveMessage(0, 0, streamNumber++, moduloOfChunks);
             audioSequenceDataChunk.addSmafMessage(message);
             messageBytes += message.getLength();
-//Debug.println("messageBytes: wave: " + messageBytes);
+//logger.log(Level.DEBUG, "messageBytes: wave: " + messageBytes);
 
             message = new NopMessage(moduloOfChunks);
             audioSequenceDataChunk.addSmafMessage(message);
             messageBytes += message.getLength();
-//Debug.println("messageBytes: nop: " + messageBytes);
+//logger.log(Level.DEBUG, "messageBytes: nop: " + messageBytes);
         }
         audioSequenceDataChunk.addSmafMessage(new EndOfSequenceMessage(0));
 
         SeekAndPhraseInfoChunk seekAndPhraseInfoChunk = new SeekAndPhraseInfoChunk();
         seekAndPhraseInfoChunk.setStartPoint(0);
         seekAndPhraseInfoChunk.setStopPoint(messageBytes);
-Debug.println(Level.FINE, "sp: " + messageBytes);
+logger.log(Level.DEBUG, "sp: " + messageBytes);
 
         AudioEngine audioEngine = WaveSequencer.Factory.getAudioEngine(ADPCM);
         int chunkSize = numberOfChunks == 0 ? 0 : data.length / numberOfChunks;
-Debug.println(Level.FINE, "chunkSize: " + chunkSize);
+logger.log(Level.DEBUG, "chunkSize: " + chunkSize);
         int moduloChunkSize = numberOfChunks == 0 ? data.length : data.length % chunkSize;
-Debug.println(Level.FINE, "moduloChunkSize: " + moduloChunkSize);
+logger.log(Level.DEBUG, "moduloChunkSize: " + moduloChunkSize);
         streamNumber = 1;
 
         PcmAudioTrackChunk pcmAudioTrackChunk = new PcmAudioTrackChunk();
@@ -246,18 +248,18 @@ protected int createSMAF(byte[] data, File file) throws InvalidSmafDataException
         }
         fileChunk.writeTo(Files.newOutputStream(file.toPath()));
         int r = fileChunk.getSize();
-Debug.println(Level.FINE, "write: " + r);
+logger.log(Level.DEBUG, "write: " + r);
         return r;
     }
 
     /** vendor */
-    protected static String vn;
+    protected static final String vn;
 
     /** copyright */
-    protected static String cr;
+    protected static final String cr;
 
     /** */
-    protected static String defaultModel;
+    protected static final String defaultModel;
 
     /* */
     static {
@@ -281,18 +283,24 @@ public static class Arguments {
         @Argument(index = 0)
         File file;
         @Option(argName = "filename", option = "f", args = 1, required = false, description = "output mmf filename")
+        final
         String outFilename = "out.mmf";
         @Option(argName = "model", option = "m", required = false, args = 1, description = "terminal model")
         String model = defaultModel;
         @Option(argName = "rate", option = "r", required = false, args = 1, description = "adpcm sampling rate [Hz]")
+        final
         int samplingRate = 16000;
         @Option(argName = "bits", option = "b", required = false, args = 1, description = "adpcm sampling bits")
+        final
         int bits = 4;
         @Option(argName = "channels", option = "c", required = false, args = 1, description = "adpcm channels")
+        final
         int channels = 1;
         @Option(argName = "masterVolume", option = "v", required = false, args = 1, description = "master volume in [%]")
+        final
         int masterVolume = 100;
         @Option(argName = "adpcmVolume", option = "a", required = false, args = 1, description = "adpcm volume in [%]")
+        final
         int adpcmVolume = 100;
     }
 
diff --git a/src/main/java/vavi/sound/smaf/MetaEventAdapter.java b/src/main/java/vavi/sound/smaf/MetaEventAdapter.java
index 7e18614..8a8c4f0 100644
--- a/src/main/java/vavi/sound/smaf/MetaEventAdapter.java
+++ b/src/main/java/vavi/sound/smaf/MetaEventAdapter.java
@@ -6,8 +6,8 @@
 
 package vavi.sound.smaf;
 
-import java.util.logging.Level;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
 import javax.sound.midi.MetaEventListener;
 
 import vavi.sound.midi.MidiConstants.MetaEvent;
@@ -18,7 +18,8 @@
 import vavi.sound.smaf.sequencer.MachineDependentSequencer;
 import vavi.sound.smaf.sequencer.SmafMessageStore;
 import vavi.sound.smaf.sequencer.WaveSequencer;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
 
 
 /**
@@ -29,6 +30,8 @@
  */
 class MetaEventAdapter implements MetaEventListener, SmafDevice {
 
+    private static final Logger logger = getLogger(MetaEventAdapter.class.getName());
+
     /** the device information */
     private static final SmafDevice.Info info =
         new SmafDevice.Info("Java SMAF WAVE Sequencer",
@@ -64,32 +67,32 @@ public void open() {
      */
     @Override
     public void meta(javax.sound.midi.MetaMessage message) {
-//Debug.println("type: " + message.getType());
+//logger.log(Level.DEBUG, "type: " + message.getType());
         switch (MetaEvent.valueOf(message.getType())) {
         case META_MACHINE_DEPEND: // sequencer specific meta event
             try {
                 processSpecial(message);
             } catch (InvalidSmafDataException e) {
-                Debug.printStackTrace(e.getCause());
+                logger.log(Level.ERROR, e.getCause().getMessage(), e.getCause());
             }
 catch (RuntimeException e) {
-Debug.printStackTrace(e);
+logger.log(Level.ERROR, e.getMessage(), e);
 } catch (Error e) {
-Debug.printStackTrace(e);
+logger.log(Level.ERROR, e.getMessage(), e);
 throw e;
 }
             break;
         case META_TEXT_EVENT:     // text event
         case META_COPYRIGHT:      // show copyright
         case META_NAME:           // sequence name or track name
-Debug.println(Level.FINE, "meta " + message.getType() + ": " + MidiUtil.getDecodedMessage(message.getData()));
+logger.log(Level.DEBUG, "meta " + message.getType() + ": " + MidiUtil.getDecodedMessage(message.getData()));
             break;
         case META_END_OF_TRACK:   // end of track
         case META_TEMPO:          // tempo was set
-Debug.println(Level.FINE, "this handler ignore meta: " + message.getType());
+logger.log(Level.DEBUG, "this handler ignore meta: " + message.getType());
             break;
         default:
-Debug.println(Level.FINE, "no meta sub handler: " + message.getType());
+logger.log(Level.DEBUG, "no meta sub handler: " + message.getType());
             break;
         }
     }
@@ -107,13 +110,13 @@ private void processSpecial(javax.sound.midi.MetaMessage message)
         int manufacturerId = data[0];
         switch (manufacturerId) {
         case 0:     // 3 byte manufacturer id
-Debug.printf(Level.WARNING, "unhandled manufacturer: %02x %02x %02x\n", data[0], data[1], data[2]);
+logger.log(Level.WARNING, String.format("unhandled manufacturer: %02x %02x %02x", data[0], data[1], data[2]));
             break;
         case VaviMidiDeviceProvider.MANUFACTURER_ID: // 0x5f vavi
             processSpecial_Vavi(message);
             break;
         default:
-Debug.printf(Level.WARNING, "unhandled manufacturer: %02x\n", manufacturerId);
+logger.log(Level.WARNING, String.format("unhandled manufacturer: %02x", manufacturerId));
             break;
         }
     }
@@ -124,7 +127,7 @@ private void processSpecial(javax.sound.midi.MetaMessage message)
      * 0x5f functionId
      * 
*/ - private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi(javax.sound.midi.MetaMessage message) throws InvalidSmafDataException { byte[] data = message.getData(); @@ -137,7 +140,7 @@ private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) processSpecial_Vavi_Wave(message); break; default: -Debug.printf(Level.WARNING, "unhandled function: %02x\n", functionId); +logger.log(Level.WARNING, String.format("unhandled function: %02x", functionId)); break; } } @@ -147,12 +150,12 @@ private void processSpecial_Vavi(javax.sound.midi.MetaMessage message) * 0x5f 0x01 *
*/ - private void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage message) throws InvalidSmafDataException { byte[] data = message.getData(); int id = (data[2] & 0xff) * 0xff + (data[3] & 0xff); -//Debug.println("message id: " + id); +//logger.log(Level.DEBUG, "message id: " + id); MachineDependentSequencer sequencer = (MachineDependentSequencer) SmafMessageStore.get(id); sequencer.sequence(); } @@ -163,12 +166,12 @@ private void processSpecial_Vavi_MachineDependent(javax.sound.midi.MetaMessage m * 0x5f 0x03 id(H) id(L) * */ - private void processSpecial_Vavi_Wave(javax.sound.midi.MetaMessage message) + private static void processSpecial_Vavi_Wave(javax.sound.midi.MetaMessage message) throws InvalidSmafDataException { byte[] data = message.getData(); int id = (data[2] & 0xff) * 0x100 + (data[3] & 0xff); -//Debug.println("message id: " + id); +//logger.log(Level.DEBUG, "message id: " + id); WaveSequencer sequencer = (WaveSequencer) SmafMessageStore.get(id); sequencer.sequence(); } diff --git a/src/main/java/vavi/sound/smaf/MetaSupport.java b/src/main/java/vavi/sound/smaf/MetaSupport.java index 8956587..aa24107 100644 --- a/src/main/java/vavi/sound/smaf/MetaSupport.java +++ b/src/main/java/vavi/sound/smaf/MetaSupport.java @@ -21,7 +21,7 @@ class MetaSupport implements Serializable { /** The metaEvent listeners */ - private List listenerList = new ArrayList<>(); + private final List listenerList = new ArrayList<>(); /** Adds {@link MetaEventListener}. */ public void addMetaEventListener(MetaEventListener l) { diff --git a/src/main/java/vavi/sound/smaf/Sequence.java b/src/main/java/vavi/sound/smaf/Sequence.java index 49f6be3..46a3ae8 100644 --- a/src/main/java/vavi/sound/smaf/Sequence.java +++ b/src/main/java/vavi/sound/smaf/Sequence.java @@ -22,7 +22,7 @@ public class Sequence { /** */ - protected List tracks; + protected final List tracks; /** Creates a sequence. */ public Sequence() { diff --git a/src/main/java/vavi/sound/smaf/SmafDevice.java b/src/main/java/vavi/sound/smaf/SmafDevice.java index 515fcc9..fa483d3 100644 --- a/src/main/java/vavi/sound/smaf/SmafDevice.java +++ b/src/main/java/vavi/sound/smaf/SmafDevice.java @@ -19,13 +19,13 @@ public interface SmafDevice { class Info { /** */ - String name; + final String name; /** */ - String vendor; + final String vendor; /** */ - String description; + final String description; /** */ - String version; + final String version; /** */ protected Info(String name, diff --git a/src/main/java/vavi/sound/smaf/SmafDeviceProvider.java b/src/main/java/vavi/sound/smaf/SmafDeviceProvider.java index 9d96556..c5ec568 100644 --- a/src/main/java/vavi/sound/smaf/SmafDeviceProvider.java +++ b/src/main/java/vavi/sound/smaf/SmafDeviceProvider.java @@ -6,13 +6,15 @@ package vavi.sound.smaf; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -23,11 +25,13 @@ */ public class SmafDeviceProvider { + private static final Logger logger = getLogger(SmafDeviceProvider.class.getName()); + /** */ public static final String version = "1.0.10"; /** */ - private SmafDevice.Info[] smafDeviceInfos; + private final SmafDevice.Info[] smafDeviceInfos; /** */ public SmafDeviceProvider() { @@ -73,7 +77,7 @@ public static SmafDevice getSmafDevice(SmafDevice.Info smafDeviceInfo) { try { return deviceMap.get(smafDeviceInfo).getDeclaredConstructor().newInstance(); } catch (Exception e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); } } @@ -81,7 +85,7 @@ public static SmafDevice getSmafDevice(SmafDevice.Info smafDeviceInfo) { } /** */ - private static Map> deviceMap = new HashMap<>(); + private static final Map> deviceMap = new HashMap<>(); /* */ static { @@ -97,14 +101,14 @@ public static SmafDevice getSmafDevice(SmafDevice.Info smafDeviceInfo) { if (key.startsWith("smaf.device.")) { @SuppressWarnings("unchecked") Class deviceClass = (Class) Class.forName(props.getProperty(key)); -//Debug.println("smaf device class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "smaf device class: " + StringUtil.getClassName(clazz)); SmafDevice.Info smafDeviceInfo = deviceClass.getDeclaredConstructor().newInstance().getDeviceInfo(); deviceMap.put(smafDeviceInfo, deviceClass); } } } catch (Exception e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/smaf/SmafEvent.java b/src/main/java/vavi/sound/smaf/SmafEvent.java index a3241b8..14f0167 100644 --- a/src/main/java/vavi/sound/smaf/SmafEvent.java +++ b/src/main/java/vavi/sound/smaf/SmafEvent.java @@ -16,10 +16,10 @@ public class SmafEvent { /** */ - private long tick; + private final long tick; /** */ - private SmafMessage smafMessage; + private final SmafMessage smafMessage; /** * @param smafMessage diff --git a/src/main/java/vavi/sound/smaf/SmafFileWriter.java b/src/main/java/vavi/sound/smaf/SmafFileWriter.java index c472a5a..9f448bb 100644 --- a/src/main/java/vavi/sound/smaf/SmafFileWriter.java +++ b/src/main/java/vavi/sound/smaf/SmafFileWriter.java @@ -10,10 +10,11 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.file.Files; -import java.util.logging.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -24,8 +25,10 @@ */ class SmafFileWriter { + private static final Logger logger = getLogger(SmafFileWriter.class.getName()); + /** smaf file types */ - private static int[] types = { SmafFileFormat.FILE_TYPE }; + private static final int[] types = { SmafFileFormat.FILE_TYPE }; /** */ public int[] getSmafFileTypes() { @@ -64,7 +67,7 @@ public int write(Sequence in, int fileType, OutputStream out) throws IOException { if (!isFileTypeSupported(fileType)) { -Debug.println(Level.WARNING, "unsupported fileType: " + fileType); +logger.log(Level.WARNING, "unsupported fileType: " + fileType); return 0; } @@ -81,7 +84,7 @@ public int write(Sequence in, int fileType, OutputStream out) try { ff.writeTo(out); } catch (InvalidSmafDataException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); return 0; } diff --git a/src/main/java/vavi/sound/smaf/SmafMidiConverter.java b/src/main/java/vavi/sound/smaf/SmafMidiConverter.java index de462ae..5aba5bf 100644 --- a/src/main/java/vavi/sound/smaf/SmafMidiConverter.java +++ b/src/main/java/vavi/sound/smaf/SmafMidiConverter.java @@ -7,11 +7,11 @@ package vavi.sound.smaf; import java.io.IOException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiEvent; import javax.sound.midi.Sequence; @@ -21,7 +21,8 @@ import vavi.sound.midi.smaf.SmafVaviSequence; import vavi.sound.smaf.message.MidiContext; import vavi.sound.smaf.message.MidiConvertible; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -32,6 +33,8 @@ */ class SmafMidiConverter implements SmafDevice { + private static final Logger logger = getLogger(SmafMidiConverter.class.getName()); + /** the device information */ private static final SmafDevice.Info info = new SmafDevice.Info("Java MIDI, SMAF Sequence Converter", @@ -62,7 +65,7 @@ public void open() { } /** debug */ -private Set> uc = new HashSet<>(); +private final Set> uc = new HashSet<>(); /** Converts smaf sequence to midi sequence */ Sequence convert(vavi.sound.smaf.Sequence smafSequence) @@ -75,7 +78,7 @@ Sequence convert(vavi.sound.smaf.Sequence smafSequence) MidiContext midiContext = new MidiContext(); int resolution = midiContext.getResolution(smafTracks); -Debug.println(Level.FINE, "resolution: " + resolution); +logger.log(Level.DEBUG, "resolution: " + resolution); Sequence midiSequence = new SmafVaviSequence(Sequence.PPQ, resolution, 1); javax.sound.midi.Track midiTrack = midiSequence.getTracks()[0]; @@ -96,7 +99,7 @@ Sequence convert(vavi.sound.smaf.Sequence smafSequence) SmafMessage smafMessage = smafEvent.getMessage(); midiContext.addCurrentTick(midiContext.getTicksOf(smafMessage.getDuration())); -//Debug.println("■■■■■(" + i + ":" + j + ") ticks: " + midiContext.getCurrentTick() + "(" + midiContext.getTicksOf(smafMessage.getDuration()) + "," + smafMessage.getDuration() + "), " + smafMessage.getClass().getSimpleName()); +//logger.log(Level.DEBUG, "■■■■■(" + i + ":" + j + ") ticks: " + midiContext.getCurrentTick() + "(" + midiContext.getTicksOf(smafMessage.getDuration()) + "," + smafMessage.getDuration() + "), " + smafMessage.getClass().getSimpleName()); if (smafMessage instanceof MidiConvertible) { if (!(smafMessage instanceof vavi.sound.smaf.message.NoteMessage) && @@ -104,12 +107,12 @@ Sequence convert(vavi.sound.smaf.Sequence smafSequence) !(smafMessage instanceof vavi.sound.smaf.message.PitchBendMessage) && !(smafMessage instanceof vavi.sound.smaf.message.PanMessage) && !(smafMessage instanceof vavi.sound.smaf.message.ExpressionMessage)) { - Debug.println(Level.FINE, "midi convertible(" + i + ":" + j + "): " + smafMessage); + logger.log(Level.DEBUG, "midi convertible(" + i + ":" + j + "): " + smafMessage); } //if (smafMessage instanceof vavi.sound.smaf.message.NoteMessage) { // int gateTime = ((vavi.sound.smaf.message.NoteMessage) smafMessage).getGateTime(); // if (gateTime == 0) { -// Debug.println(Level.WARNING, "★★★★★(" + i + ":" + j + ") gateTime == 0: " + smafMessage); +// logger.log(Level.WARNING, "★★★★★(" + i + ":" + j + ") gateTime == 0: " + smafMessage); // } //} MidiEvent[] midiEvents = ((MidiConvertible) smafMessage).getMidiEvents(midiContext); @@ -120,13 +123,13 @@ Sequence convert(vavi.sound.smaf.Sequence smafSequence) } } } else if (smafMessage instanceof MetaMessage) { -Debug.println(Level.FINE, "meta: " + ((MetaMessage) smafMessage).getType()); +logger.log(Level.DEBUG, "meta: " + ((MetaMessage) smafMessage).getType()); for (Map.Entry entry : ((MetaMessage) smafMessage).data.entrySet()) { -Debug.println(Level.FINE, entry.getKey() + "=" + entry.getValue()); +logger.log(Level.DEBUG, entry.getKey() + "=" + entry.getValue()); } } else { if (!uc.contains(smafMessage.getClass())) { - Debug.println(Level.WARNING, "unhandled message: " + smafMessage); + logger.log(Level.WARNING, "unhandled message: " + smafMessage); uc.add(smafMessage.getClass()); } } @@ -138,9 +141,9 @@ Sequence convert(vavi.sound.smaf.Sequence smafSequence) /** Note may be entered before Control/Program */ @SuppressWarnings("unused") - private void addSmafMessage(javax.sound.midi.Track midiTrack, MidiEvent midiEvent) { -//Debug.println("★: " + midiEvent.getMessage()); -//Debug.println("★: " + (midiTrack.size() > 1 ? midiTrack.get(midiTrack.size() - 2).getMessage() : null)); + private static void addSmafMessage(javax.sound.midi.Track midiTrack, MidiEvent midiEvent) { +//logger.log(Level.DEBUG, "★: " + midiEvent.getMessage()); +//logger.log(Level.DEBUG, "★: " + (midiTrack.size() > 1 ? midiTrack.get(midiTrack.size() - 2).getMessage() : null)); if (midiEvent.getTick() == 0 && midiEvent.getMessage() instanceof ShortMessage && ((ShortMessage) midiEvent.getMessage()).getCommand() == ShortMessage.PROGRAM_CHANGE && @@ -152,7 +155,7 @@ private void addSmafMessage(javax.sound.midi.Track midiTrack, MidiEvent midiEven midiTrack.remove(removedMidiEvent); midiTrack.add(midiEvent); midiTrack.add(removedMidiEvent); -Debug.println(Level.INFO, "★★★★★ : " + MidiUtil.paramString(midiEvent.getMessage()) + ", " + MidiUtil.paramString(removedMidiEvent.getMessage())); +logger.log(Level.INFO, "★★★★★ : " + MidiUtil.paramString(midiEvent.getMessage()) + ", " + MidiUtil.paramString(removedMidiEvent.getMessage())); } else { midiTrack.add(midiEvent); } diff --git a/src/main/java/vavi/sound/smaf/SmafSequence.java b/src/main/java/vavi/sound/smaf/SmafSequence.java index 238e096..12ca569 100644 --- a/src/main/java/vavi/sound/smaf/SmafSequence.java +++ b/src/main/java/vavi/sound/smaf/SmafSequence.java @@ -6,15 +6,17 @@ package vavi.sound.smaf; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.chunk.Chunk; import vavi.sound.smaf.chunk.FileChunk; import vavi.sound.smaf.chunk.TrackChunk; import vavi.sound.smaf.message.STMessage; import vavi.sound.smaf.message.VNMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -25,6 +27,8 @@ */ class SmafSequence extends Sequence { + private static final Logger logger = getLogger(SmafSequence.class.getName()); + /** TODO content should be moved to SmafFileFormat/FileChunk */ SmafSequence(FileChunk fileChunk) { try { @@ -52,7 +56,7 @@ class SmafSequence extends Sequence { String prot = "vavi"; if (fileChunk.getOptionalDataChunk() != null) { for (Chunk dataChunk : fileChunk.getOptionalDataChunk().getDataChunks()) { -Debug.println(Level.FINE, dataChunk); +logger.log(Level.DEBUG, dataChunk); // TODO } } else if (fileChunk.getContentsInfoChunk() != null) { // TODO no need for if as it is required @@ -80,11 +84,11 @@ private void createTrack(List events) { /** * hack of Track */ - private void insert(Track track, SmafEvent event, int index) { + private static void insert(Track track, SmafEvent event, int index) { try { Class clazz = track.getClass(); //for (Field field : clazz.getDeclaredFields()) { -// System.err.println("field: " + field); +// logger.log(Level.DEBUG, "field: " + field); //} @SuppressWarnings("unchecked") List events = (List) clazz.getDeclaredField("events").get(track); diff --git a/src/main/java/vavi/sound/smaf/SmafSequencer.java b/src/main/java/vavi/sound/smaf/SmafSequencer.java index c9c9f6b..8a23fc2 100644 --- a/src/main/java/vavi/sound/smaf/SmafSequencer.java +++ b/src/main/java/vavi/sound/smaf/SmafSequencer.java @@ -8,7 +8,8 @@ import java.io.IOException; import java.io.InputStream; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.Instrument; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiChannel; @@ -18,7 +19,8 @@ import javax.sound.midi.Soundbank; import vavi.sound.midi.MidiUtil; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -33,6 +35,8 @@ */ class SmafSequencer implements Sequencer, Synthesizer { + private static final Logger logger = getLogger(SmafSequencer.class.getName()); + /** the device information */ private static final SmafDevice.Info info = new SmafDevice.Info("Java SMAF Sound Sequencer", @@ -73,7 +77,7 @@ public boolean isOpen() { } /** ADPCM sequencer, TODO should be {@link javax.sound.midi.Transmitter} */ - private javax.sound.midi.MetaEventListener mea = new MetaEventAdapter(); + private final javax.sound.midi.MetaEventListener mea = new MetaEventAdapter(); @Override public void open() throws SmafUnavailableException { @@ -86,7 +90,7 @@ public void open() throws SmafUnavailableException { midiSequencer.open(); midiSynthesizer.open(); } catch (MidiUnavailableException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new SmafUnavailableException(e); } } @@ -100,10 +104,10 @@ public void setSequence(Sequence sequence) try { midiSequencer.setSequence(SmafSystem.toMidiSequence(sequence)); } catch (InvalidMidiDataException e) { -Debug.println(e); +logger.log(Level.DEBUG, e); throw new InvalidSmafDataException(e); } catch (SmafUnavailableException e) { -Debug.println(e); +logger.log(Level.DEBUG, e); throw new IllegalStateException(e); } } @@ -160,7 +164,7 @@ private void off() { //------------------------------------------------------------------------- /** {@link MetaMessage MetaEvent} utility */ - private MetaSupport metaSupport = new MetaSupport(); + private final MetaSupport metaSupport = new MetaSupport(); /* Adds a {@link MetaEventListener}. */ @Override @@ -180,26 +184,23 @@ protected void fireMeta(MetaMessage meta) { } /** meta 0x2f listener */ - private javax.sound.midi.MetaEventListener mel = new javax.sound.midi.MetaEventListener() { - @Override - public void meta(javax.sound.midi.MetaMessage message) { -//Debug.println("type: " + message.getType()); - switch (message.getType()) { - case 0x2f: // added automatically at the end of the sequence - try { - MetaMessage metaMessage = new MetaMessage(); - metaMessage.setMessage(0x2f, null); - fireMeta(metaMessage); - off(); - } catch (InvalidSmafDataException e) { -Debug.println(e); - } + private final javax.sound.midi.MetaEventListener mel = message -> { +//logger.log(Level.DEBUG, "type: " + message.getType()); + switch (message.getType()) { + case 0x2f: // added automatically at the end of the sequence + try { + MetaMessage metaMessage = new MetaMessage(); + metaMessage.setMessage(0x2f, null); + fireMeta(metaMessage); + off(); + } catch (InvalidSmafDataException e) { +logger.log(Level.DEBUG, e); + } catch (RuntimeException | Error e) { -Debug.printStackTrace(e); - throw e; +logger.log(Level.ERROR, e.getMessage(), e); +throw e; } - break; - } + break; } }; diff --git a/src/main/java/vavi/sound/smaf/SmafSystem.java b/src/main/java/vavi/sound/smaf/SmafSystem.java index 7c0ec63..1b776e7 100644 --- a/src/main/java/vavi/sound/smaf/SmafSystem.java +++ b/src/main/java/vavi/sound/smaf/SmafSystem.java @@ -11,13 +11,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.file.Files; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaEventListener; import javax.sound.midi.Sequence; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -28,16 +29,18 @@ */ public final class SmafSystem { + private static final Logger logger = getLogger(SmafSystem.class.getName()); + /** TODO SmafDeviceProvider */ - private static Sequencer sequencer; + private static final Sequencer sequencer; /** TODO SmafDeviceProvider */ - private static SmafMidiConverter converter; + private static final SmafMidiConverter converter; /** TODO SmafDeviceProvider */ - private static MetaEventListener waveSequencer; + private static final MetaEventListener waveSequencer; /** */ - private static SmafFileReader reader; + private static final SmafFileReader reader; /** */ - private static SmafFileWriter writer; + private static final SmafFileWriter writer; /* */ static { @@ -107,7 +110,7 @@ public static Sequence toMidiSequence(vavi.sound.smaf.Sequence sequence) try { return converter.convert(sequence); } catch (IOException | InvalidMidiDataException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw new InvalidSmafDataException(e); } } @@ -123,7 +126,7 @@ public static vavi.sound.smaf.Sequence toSmafSequence(Sequence in, int fileType) try { return converter.convert(in, fileType); } catch (IOException | InvalidSmafDataException e) { -Debug.printStackTrace(e); +logger.log(Level.ERROR, e.getMessage(), e); throw (InvalidMidiDataException) new InvalidMidiDataException().initCause(e); } } diff --git a/src/main/java/vavi/sound/smaf/SysexMessage.java b/src/main/java/vavi/sound/smaf/SysexMessage.java index 8b73f6c..39624f4 100644 --- a/src/main/java/vavi/sound/smaf/SysexMessage.java +++ b/src/main/java/vavi/sound/smaf/SysexMessage.java @@ -81,20 +81,15 @@ public static class Factory { * @param data 0: maker id ... */ public static SysexMessage getSysexMessage(int duration, byte[] data) throws InvalidSmafDataException { - SysexMessage sysexMessage; - switch (data[0]) { - case 0x43: // YAMAHA - sysexMessage = new vavi.sound.smaf.message.yamaha.YamahaMessage(); - break; - case 0x7e: // non realtime - sysexMessage = new vavi.sound.smaf.message.NonRealtimeUniversalSysexMessage(); - break; - case 0x7f: // realtime - sysexMessage = new vavi.sound.smaf.message.RealtimeUniversalSysexMessage(); - break; - default: - throw new IllegalArgumentException("unknown vendor: " + data[0]); - } + SysexMessage sysexMessage = switch (data[0]) { + case 0x43 -> // YAMAHA + new vavi.sound.smaf.message.yamaha.YamahaMessage(); + case 0x7e -> // non realtime + new vavi.sound.smaf.message.NonRealtimeUniversalSysexMessage(); + case 0x7f -> // realtime + new vavi.sound.smaf.message.RealtimeUniversalSysexMessage(); + default -> throw new IllegalArgumentException("unknown vendor: " + data[0]); + }; sysexMessage.setDuration(duration); sysexMessage.setMessage(0xf0, data, data.length); return sysexMessage; diff --git a/src/main/java/vavi/sound/smaf/Track.java b/src/main/java/vavi/sound/smaf/Track.java index 40d0b7a..e43c183 100644 --- a/src/main/java/vavi/sound/smaf/Track.java +++ b/src/main/java/vavi/sound/smaf/Track.java @@ -19,7 +19,7 @@ public class Track { /** */ - protected List events; + protected final List events; /** * diff --git a/src/main/java/vavi/sound/smaf/chunk/AudioSequenceDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/AudioSequenceDataChunk.java index 95ff266..6da42d4 100644 --- a/src/main/java/vavi/sound/smaf/chunk/AudioSequenceDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/AudioSequenceDataChunk.java @@ -7,13 +7,15 @@ package vavi.sound.smaf.chunk; import java.io.IOException; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.chunk.TrackChunk.FormatType; import vavi.sound.smaf.message.WaveMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,10 +28,12 @@ */ public class AudioSequenceDataChunk extends SequenceDataChunk { + private static final Logger logger = getLogger(AudioSequenceDataChunk.class.getName()); + /** */ public AudioSequenceDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "AudioSequenceData: " + size + " bytes"); +logger.log(Level.DEBUG, "AudioSequenceData: " + size + " bytes"); } /** */ @@ -42,7 +46,7 @@ public AudioSequenceDataChunk() { @Override protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { -//Debug.println("available: " + is.available() + ", " + available()); +//logger.log(Level.DEBUG, "available: " + is.available() + ", " + available()); //skip(is, size); // TODO FormatType formatType = ((TrackChunk) parent).getFormatType(); switch (formatType) { @@ -52,7 +56,7 @@ protected void init(MyDataInputStream dis, Chunk parent) default: throw new InvalidSmafDataException("FormatType: " + formatType); } -Debug.println(Level.FINE, "messages: " + messages.size()); +logger.log(Level.DEBUG, "messages: " + messages.size()); } /** diff --git a/src/main/java/vavi/sound/smaf/chunk/BitmapChunk.java b/src/main/java/vavi/sound/smaf/chunk/BitmapChunk.java index 3515e38..25507e0 100644 --- a/src/main/java/vavi/sound/smaf/chunk/BitmapChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/BitmapChunk.java @@ -8,10 +8,12 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -24,10 +26,12 @@ */ public class BitmapChunk extends Chunk { + private static final Logger logger = getLogger(BitmapChunk.class.getName()); + /** */ public BitmapChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "Bitmap: " + size + " bytes"); +logger.log(Level.DEBUG, "Bitmap: " + size + " bytes"); } /** */ @@ -36,7 +40,7 @@ public BitmapChunk() { this.size = 0; } - /** */ + /** */ @Override protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { diff --git a/src/main/java/vavi/sound/smaf/chunk/ChannelStatus.java b/src/main/java/vavi/sound/smaf/chunk/ChannelStatus.java index 756ed12..994db11 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ChannelStatus.java +++ b/src/main/java/vavi/sound/smaf/chunk/ChannelStatus.java @@ -28,18 +28,18 @@ public enum Type { } /** smaf channel */ - private int channel; + private final int channel; /** */ private ChannelStatus.Status keyControlStatus; /** */ private ChannelStatus.Status led; /** */ - private ChannelStatus.Status vibration; + private final ChannelStatus.Status vibration; /** */ private ChannelStatus.Type type; /** internal use */ - private FormatType formatType; + private final FormatType formatType; /** * For HandyPhoneStandard. diff --git a/src/main/java/vavi/sound/smaf/chunk/Chunk.java b/src/main/java/vavi/sound/smaf/chunk/Chunk.java index 62a30d5..5ae8c3c 100644 --- a/src/main/java/vavi/sound/smaf/chunk/Chunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/Chunk.java @@ -11,15 +11,17 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.util.ByteUtil; -import vavi.util.Debug; import vavi.util.properties.PrefixedPropertiesFactory; +import static java.lang.System.getLogger; + /** * Chunk. @@ -30,6 +32,8 @@ */ public abstract class Chunk { + private static final Logger logger = getLogger(Chunk.class.getName()); + /** Chunk ID */ protected byte[] id = new byte[4]; @@ -87,8 +91,7 @@ public static Chunk readFrom(InputStream is, Chunk parent) throws InvalidSmafDataException, IOException { DataInputStream dis; - if (is instanceof MyDataInputStream) { - MyDataInputStream mdis = (MyDataInputStream) is; + if (is instanceof MyDataInputStream mdis) { dis = new DataInputStream(mdis.is); } else { dis = new DataInputStream(is); @@ -98,13 +101,13 @@ public static Chunk readFrom(InputStream is, Chunk parent) dis.readFully(id); // not want to count down int size = dis.readInt(); -Debug.printf(Level.FINE, "size: 0x%1$08x (%1$d)", size); +logger.log(Level.DEBUG, String.format("size: 0x%1$08x (%1$d)", size)); Chunk chunk = newInstance(id, size); -//Debug.println(chunk.getClass().getName() + "\n" + StringUtil.getDump(is, 0, 128)); -//Debug.printf(Level.FINE, "is: " + is + " / " + chunk.getClass().getName()); +//logger.log(Level.DEBUG, chunk.getClass().getName() + "\n" + StringUtil.getDump(is, 0, 128)); +//logger.log(Level.DEBUG, String.format("is: " + is + " / " + chunk.getClass().getName())); MyDataInputStream mdis = new MyDataInputStream(is, id, size); -//Debug.printf(Level.FINE, "mdis: " + mdis + " / " + chunk.getClass().getName()); +//logger.log(Level.DEBUG, String.format("mdis: " + mdis + " / " + chunk.getClass().getName())); chunk.init(mdis, parent); if (parent != null) { @@ -116,10 +119,10 @@ public static Chunk readFrom(InputStream is, Chunk parent) assert false : "is: " + is.getClass().getName(); } } else { -//Debug.printf(Level.FINE, "crc (calc): %04x, avail: %d, %s, %s", mdis.crc(), mdis.available(), mdis, chunk.getClass().getName()); +//logger.log(Level.DEBUG, String.format("crc (calc): %04x, avail: %d, %s, %s", mdis.crc(), mdis.available(), mdis, chunk.getClass().getName())); if (chunk instanceof FileChunk fc) { if (fc.getCrc() != mdis.crc()) { -Debug.printf(Level.WARNING, "crc not match expected: %04x, actural: %04x", fc.getCrc(), mdis.crc()); +logger.log(Level.WARNING, String.format("crc not match expected: %04x, actual: %04x", fc.getCrc(), mdis.crc())); } } } @@ -134,10 +137,10 @@ public static Chunk readFrom(InputStream is, Chunk parent) /** input stream with count down, crc */ protected static class MyDataInputStream extends InputStream implements DataInput { - InputStream is; - DataInputStream dis; + final InputStream is; + final DataInputStream dis; int readSize; - static ThreadLocal crc = new ThreadLocal<>(); + static final ThreadLocal crc = new ThreadLocal<>(); protected MyDataInputStream(InputStream is, byte[] id, int size) { if (is instanceof MyDataInputStream mdis) { @@ -145,7 +148,7 @@ protected MyDataInputStream(InputStream is, byte[] id, int size) { } else { this.is = is; } -//Debug.printf(Level.FINE, "is: " + this.is); +//logger.log(Level.DEBUG, String.format("is: " + this.is)); this.dis = new DataInputStream(this.is); this.readSize = size; @@ -156,7 +159,7 @@ protected MyDataInputStream(InputStream is, byte[] id, int size) { crc.get().update(ByteUtil.getBeBytes(size)); } public int crc() { -//Debug.println("crc len: " + crc.get().getCount()); +//logger.log(Level.DEBUG, "crc len: " + crc.get().getCount()); return crc.get().getValue(); } @Override @@ -255,7 +258,7 @@ static class CRC16 { static final int BYTE_BIT = 8; /** maximum unsigned char value */ static final int UCHAR_MAX = 0xff; - static int[] crcTable = new int[UCHAR_MAX + 1]; + static final int[] crcTable = new int[UCHAR_MAX + 1]; static final int CRCPOLY1 = 0x1021; static { @@ -321,14 +324,14 @@ private static Chunk newInstance(byte[] id, int size) try { return chunkFactory.get(id).newInstance(id, size); } catch (IllegalArgumentException e) { -Debug.println(Level.FINE, e); +logger.log(Level.DEBUG, e); return new UndefinedChunk(id, size); // TODO out source // throw new InvalidSmafDataException("unsupported chunk id: " + StringUtil.getDump(id)); } catch (Exception e) { if (e instanceof InvocationTargetException) { -Debug.printStackTrace(Level.SEVERE, e.getCause()); +logger.log(Level.ERROR, e.getCause().getMessage(), e.getCause()); } else { -Debug.printStackTrace(Level.SEVERE, e); +logger.log(Level.ERROR, e.getMessage(), e); } throw new IllegalStateException(e); } @@ -344,7 +347,7 @@ private static Chunk newInstance(byte[] id, int size) @Override public Constructor get(byte[] id) { String type = new String(id); - Debug.printf(Level.FINE, "Chunk ID(read): %s+0x%02x", (Character.isLetterOrDigit(type.charAt(3)) ? type : new String(id, 0, 3)), (int) type.charAt(3)); +logger.log(Level.DEBUG, String.format("Chunk ID(read): %s+0x%02x", (Character.isLetterOrDigit(type.charAt(3)) ? type : new String(id, 0, 3)), (int) type.charAt(3))); for (String key : instances.keySet()) { if (key.charAt(3) == '*' && key.substring(0, 3).equals(type.substring(0, 3))) { @@ -362,10 +365,10 @@ protected Constructor getStoreValue(String value) { try { @SuppressWarnings("unchecked") Class clazz = (Class) Class.forName(value); -//Debug.println("chunk class: " + StringUtil.getClassName(clazz)); +//logger.log(Level.DEBUG, "chunk class: " + StringUtil.getClassName(clazz)); return clazz.getConstructor(byte[].class, Integer.TYPE); } catch (Exception e) { - Debug.printStackTrace(e); + logger.log(Level.ERROR, e.getMessage(), e); throw new IllegalStateException(e); } } diff --git a/src/main/java/vavi/sound/smaf/chunk/ColorPaletteDefinitionChunk.java b/src/main/java/vavi/sound/smaf/chunk/ColorPaletteDefinitionChunk.java index 75e2acc..ff95cdb 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ColorPaletteDefinitionChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/ColorPaletteDefinitionChunk.java @@ -26,7 +26,7 @@ public class ColorPaletteDefinitionChunk extends Chunk { /** */ public ColorPaletteDefinitionChunk(byte[] id, int size) { super(id, size); -//Debug.println("ColorPaletteDefinition: " + size); +//logger.log(Level.DEBUG, "ColorPaletteDefinition: " + size); } /** */ diff --git a/src/main/java/vavi/sound/smaf/chunk/ContentsInfoChunk.java b/src/main/java/vavi/sound/smaf/chunk/ContentsInfoChunk.java index 003cd4e..f96bebc 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ContentsInfoChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/ContentsInfoChunk.java @@ -10,14 +10,16 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Map; import java.util.TreeMap; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * ContentsInfo Chunk. @@ -37,6 +39,8 @@ */ public class ContentsInfoChunk extends Chunk { + private static final Logger logger = getLogger(ContentsInfoChunk.class.getName()); + /** */ public ContentsInfoChunk(byte[] id, int size) { super(id, size); @@ -53,26 +57,26 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { this.contentsClass = dis.readUnsignedByte(); -Debug.println(Level.FINE, "contentsClass: " + (contentsClass == 0 ? "YAMAHA" : "Vender ID(" + contentsClass + ")")); +logger.log(Level.DEBUG, "contentsClass: " + (contentsClass == 0 ? "YAMAHA" : "Vender ID(" + contentsClass + ")")); this.contentsType = dis.readUnsignedByte(); -Debug.printf(Level.FINE, "contentsType: 0x%02x\n", contentsType); +logger.log(Level.DEBUG, String.format("contentsType: 0x%02x", contentsType)); this.contentsCodeType = dis.readUnsignedByte(); -Debug.printf(Level.FINE, "contentsCodeType: 0x%02x\n", contentsCodeType); +logger.log(Level.DEBUG, String.format("contentsCodeType: 0x%02x", contentsCodeType)); this.copyStatus = dis.readUnsignedByte(); -Debug.println(Level.FINE, "copyStatus: " + StringUtil.toBits(copyStatus, 8)); +logger.log(Level.DEBUG, "copyStatus: " + StringUtil.toBits(copyStatus, 8)); this.copyCounts = dis.readUnsignedByte(); -Debug.println(Level.FINE, "copyCounts: " + copyCounts); +logger.log(Level.DEBUG, "copyCounts: " + copyCounts); byte[] option = new byte[size - 5]; dis.readFully(option); -Debug.println(Level.FINE, "option: " + option.length + " bytes (subData)"); +logger.log(Level.DEBUG, "option: " + option.length + " bytes (subData)"); int i = 0; while (i < option.length) { -Debug.println(Level.FINER, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); +logger.log(Level.TRACE, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); SubData subDatum = new SubData(option, i, contentsCodeType); subData.put(subDatum.getTag(), subDatum); -Debug.println(Level.FINE, "ContentsInfo: subDatum: " + subDatum); +logger.log(Level.DEBUG, "ContentsInfo: subDatum: " + subDatum); i += 2 + 1 + subDatum.getData().length + 1; // tag ':' data ',' -Debug.println(Level.FINER, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); +logger.log(Level.TRACE, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); } } @@ -193,7 +197,7 @@ public void setCopyStatus(int copyStatus) { } /** */ - private Map subData = new TreeMap<>(); + private final Map subData = new TreeMap<>(); /** * @return null when specified sub chunk is not found diff --git a/src/main/java/vavi/sound/smaf/chunk/DataChunk.java b/src/main/java/vavi/sound/smaf/chunk/DataChunk.java index 94a534b..8cc2961 100644 --- a/src/main/java/vavi/sound/smaf/chunk/DataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/DataChunk.java @@ -11,14 +11,16 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Map; import java.util.TreeMap; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * Data Chunk. @@ -30,12 +32,14 @@ */ public class DataChunk extends Chunk { + private static final Logger logger = getLogger(DataChunk.class.getName()); + /** */ public DataChunk(byte[] id, int size) { super(id, size); this.languageCode = id[3] & 0xff; -Debug.println(Level.FINE, "Data: lang: " + languageCode + ", size: " + size); +logger.log(Level.DEBUG, "Data: lang: " + languageCode + ", size: " + size); } /** */ @@ -48,12 +52,12 @@ public DataChunk() { protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { -Debug.println(Level.FINER, "available: " + dis.available()); +logger.log(Level.TRACE, "available: " + dis.available()); while (dis.available() > 4) { // TODO normal files should be 0. SubData subDatum = new SubData(dis); -Debug.println(Level.FINE, subDatum); +logger.log(Level.DEBUG, subDatum); subData.put(subDatum.tag, subDatum); -Debug.println(Level.FINER, "SubData: " + subDatum.tag + ", " + subDatum.data.length + ", " + dis.available()); +logger.log(Level.TRACE, "SubData: " + subDatum.tag + ", " + subDatum.data.length + ", " + dis.available()); } dis.skipBytes(dis.available()); // TODO not necessary if the file is normal } @@ -74,7 +78,7 @@ public void writeTo(OutputStream os) throws IOException { private static final String defaultEncoding = "Windows-31J"; /** */ - private Map subData = new TreeMap<>(); + private final Map subData = new TreeMap<>(); /** */ String getSubDataByTag(String tag) { @@ -160,10 +164,10 @@ public int getSize() { } /** tag */ - private String tag; + private final String tag; /** Data */ - private byte[] data; + private final byte[] data; /** */ public String toString() { diff --git a/src/main/java/vavi/sound/smaf/chunk/DisplayParameterDefinitionChunk.java b/src/main/java/vavi/sound/smaf/chunk/DisplayParameterDefinitionChunk.java index d4b2ecb..578a385 100644 --- a/src/main/java/vavi/sound/smaf/chunk/DisplayParameterDefinitionChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/DisplayParameterDefinitionChunk.java @@ -9,13 +9,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.midi.MidiUtil; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,10 +30,12 @@ */ public class DisplayParameterDefinitionChunk extends Chunk { + private static final Logger logger = getLogger(DisplayParameterDefinitionChunk.class.getName()); + /** */ public DisplayParameterDefinitionChunk(byte[] id, int size) { super(id, size); -//Debug.println("DisplayParameterDefinition: " + size); +//logger.log(Level.DEBUG, "DisplayParameterDefinition: " + size); } /** */ @@ -50,7 +54,7 @@ protected void init(MyDataInputStream dis, Chunk parent) int eventType = dis.readUnsignedByte(); Event event = new Event(); event.eventType = eventType; -Debug.println(Level.FINE, "event: " + eventType); +logger.log(Level.DEBUG, "event: " + eventType); for (int j = 0; j < ((eventSize - 1) / 2); j++) { int parameterId = dis.readUnsignedByte(); int parameterValue = dis.readUnsignedByte(); @@ -58,7 +62,7 @@ protected void init(MyDataInputStream dis, Chunk parent) parameter.parameterID = ParameterID.valueOf(parameterId); parameter.value = parameterValue; event.parameters.add(parameter); -Debug.println(Level.FINE, "parameters: " + parameter); +logger.log(Level.DEBUG, "parameters: " + parameter); } i += (eventSize > 127 ? 2 : 1) + eventSize; } @@ -77,7 +81,7 @@ public void writeTo(OutputStream os) throws IOException { } /** */ - private List events = new ArrayList<>(); + private final List events = new ArrayList<>(); /** */ static class Event { @@ -87,7 +91,7 @@ static class Event { */ int eventType; /** */ - List parameters = new ArrayList<>(); + final List parameters = new ArrayList<>(); /** */ static class Parameter { ParameterID parameterID; diff --git a/src/main/java/vavi/sound/smaf/chunk/FileChunk.java b/src/main/java/vavi/sound/smaf/chunk/FileChunk.java index c40bff4..cba3726 100644 --- a/src/main/java/vavi/sound/smaf/chunk/FileChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/FileChunk.java @@ -10,12 +10,14 @@ import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,6 +30,8 @@ */ public class FileChunk extends Chunk { + private static final Logger logger = getLogger(FileChunk.class.getName()); + /** */ public FileChunk(byte[] id, int size) { super(id, size); @@ -50,7 +54,7 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof OptionalDataChunk) { optionalDataChunk = chunk; } else if (chunk instanceof ScoreTrackChunk) { -Debug.println(Level.FINE, "TRACK: " + scoreTrackChunks.size()); +logger.log(Level.DEBUG, "TRACK: " + scoreTrackChunks.size()); scoreTrackChunks.add((TrackChunk) chunk); } else if (chunk instanceof PcmAudioTrackChunk) { pcmAudioTrackChunks.add((TrackChunk) chunk); @@ -59,16 +63,16 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof MasterTrackChunk) { masterTrackChunk = (TrackChunk) chunk; } else { -Debug.println(Level.WARNING, "unsupported chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unsupported chunk: " + chunk.getClass()); } } -//Debug.println("available: " + is.available()); +//logger.log(Level.DEBUG, "available: " + is.available()); this.crc = dis.readUnsignedShort(); -Debug.printf(Level.FINE, "crc (orig): %04x\n", crc); +logger.log(Level.DEBUG, String.format("crc (orig): %04x", crc)); if (dis.available() > 4) { int kddiCrc = dis.readUnsignedShort(); int kddiMark = dis.readUnsignedShort(); -Debug.printf(Level.FINE, "has kddi crc: %04x, %04x\n", kddiCrc, kddiMark); +logger.log(Level.DEBUG, String.format("has kddi crc: %04x, %04x", kddiCrc, kddiMark)); } } @@ -104,7 +108,7 @@ public void writeTo(OutputStream os) throws IOException { /** */ private static class Crc16OutputStream extends FilterOutputStream { /** */ - private CRC16 crc16 = new CRC16(); + private final CRC16 crc16 = new CRC16(); /** */ public Crc16OutputStream(OutputStream out) { super(out); @@ -155,7 +159,7 @@ public void setOptionalDataChunk(OptionalDataChunk optionalDataChunk) { } /** "MTR*" */ - private List scoreTrackChunks = new ArrayList<>(); + private final List scoreTrackChunks = new ArrayList<>(); /** */ public List getScoreTrackChunks() { @@ -169,7 +173,7 @@ public void addScoreTrackChunk(ScoreTrackChunk scoreTrackChunk) { } /** "ATR*" */ - private List pcmAudioTrackChunks = new ArrayList<>(); + private final List pcmAudioTrackChunks = new ArrayList<>(); /** */ public List getPcmAudioTrackChunks() { @@ -183,7 +187,7 @@ public void addPcmAudioTrackChunk(PcmAudioTrackChunk pcmAudioTrackChunk) { } /** "GTR*" */ - private List graphicsTrackChunks = new ArrayList<>(); + private final List graphicsTrackChunks = new ArrayList<>(); /** */ public List getGraphicsTrackChunks() { diff --git a/src/main/java/vavi/sound/smaf/chunk/GraphicsSetupDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/GraphicsSetupDataChunk.java index 21e8a6c..3568028 100644 --- a/src/main/java/vavi/sound/smaf/chunk/GraphicsSetupDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/GraphicsSetupDataChunk.java @@ -9,10 +9,12 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -25,10 +27,12 @@ */ public class GraphicsSetupDataChunk extends Chunk { + private static final Logger logger = getLogger(GraphicsSetupDataChunk.class.getName()); + /** */ public GraphicsSetupDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "GraphicsSetupData: " + size + " bytes"); +logger.log(Level.DEBUG, "GraphicsSetupData: " + size + " bytes"); } /** */ @@ -46,7 +50,7 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataE } else if (chunk instanceof ColorPaletteDefinitionChunk) { colorPaletteDefinitionChunk = chunk; } else { -Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } diff --git a/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackChunk.java b/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackChunk.java index 83f4cd2..3129b4c 100644 --- a/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackChunk.java @@ -9,17 +9,19 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.MetaMessage; import vavi.sound.smaf.SmafEvent; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -41,10 +43,12 @@ */ public class GraphicsTrackChunk extends TrackChunk { + private static final Logger logger = getLogger(GraphicsTrackChunk.class.getName()); + /** */ public GraphicsTrackChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "Graphics[" + trackNumber + "]: " + size); +logger.log(Level.DEBUG, "Graphics[" + trackNumber + "]: " + size); } /** */ @@ -80,7 +84,7 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof ImageDataChunk) { imageDataChunk = chunk; } else { -Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } } @@ -138,7 +142,7 @@ public void setSetupDataChunk(SetupDataChunk setupDataChunk) { } /** > 1 */ - private List sequenceDataChunks = new ArrayList<>(); + private final List sequenceDataChunks = new ArrayList<>(); /** (option) */ private Chunk fontDataChunk; diff --git a/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackSequenceDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackSequenceDataChunk.java index 9f4d7aa..7438039 100644 --- a/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackSequenceDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/GraphicsTrackSequenceDataChunk.java @@ -8,7 +8,8 @@ import java.io.DataInputStream; import java.io.IOException; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.midi.MidiUtil; import vavi.sound.smaf.InvalidSmafDataException; @@ -21,7 +22,8 @@ import vavi.sound.smaf.message.graphics.OffsetOriginMessage; import vavi.sound.smaf.message.graphics.ResetOrigneMessage; import vavi.sound.smaf.message.graphics.UserMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -34,6 +36,8 @@ */ public class GraphicsTrackSequenceDataChunk extends SequenceDataChunk { + private static final Logger logger = getLogger(GraphicsTrackSequenceDataChunk.class.getName()); + /** */ private int sequenceNumber; @@ -42,7 +46,7 @@ public GraphicsTrackSequenceDataChunk(byte[] id, int size) { super(id, size); this.sequenceNumber = id[3]; -Debug.println(Level.FINE, "GraphicsTrackSequenceData[" + sequenceNumber + "]: " + size + " bytes"); +logger.log(Level.DEBUG, "GraphicsTrackSequenceData[" + sequenceNumber + "]: " + size + " bytes"); } /** */ @@ -63,7 +67,7 @@ protected void init(MyDataInputStream dis, Chunk parent) default: throw new InvalidSmafDataException("FormatType: " + formatType); } -Debug.println(Level.FINE, "messages: " + messages.size()); +logger.log(Level.DEBUG, "messages: " + messages.size()); } /** formatType 0 */ @@ -75,7 +79,7 @@ protected void readHandyPhoneStandard(DataInputStream dis) while (dis.available() > 0) { // -------- duration -------- int duration = MidiUtil.readVariableLength(dis); -//Debug.println("duration: " + duration + ", 0x" + StringUtil.toHex4(duration)); +//logger.log(Level.DEBUG, "duration: " + duration + ", 0x" + StringUtil.toHex4(duration)); // -------- event -------- int e1 = dis.readUnsignedByte(); switch (e1) { @@ -114,12 +118,12 @@ protected void readHandyPhoneStandard(DataInputStream dis) byte[] data = new byte[size]; dis.readFully(data); smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.FINE, "reserved: %02x\n", e1); +logger.log(Level.DEBUG, String.format("reserved: %02x", e1)); } break; } -//Debug.println(available() + ", " + smafMessage); -Debug.println(Level.FINE, "message: " + smafMessage); +//logger.log(Level.DEBUG, available() + ", " + smafMessage); +logger.log(Level.DEBUG, "message: " + smafMessage); messages.add(smafMessage); } } diff --git a/src/main/java/vavi/sound/smaf/chunk/HuffmanDecodingInputStream.java b/src/main/java/vavi/sound/smaf/chunk/HuffmanDecodingInputStream.java index 603e393..8f2ff47 100644 --- a/src/main/java/vavi/sound/smaf/chunk/HuffmanDecodingInputStream.java +++ b/src/main/java/vavi/sound/smaf/chunk/HuffmanDecodingInputStream.java @@ -9,9 +9,10 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -25,6 +26,8 @@ */ public class HuffmanDecodingInputStream extends FilterInputStream { + private static final Logger logger = getLogger(HuffmanDecodingInputStream.class.getName()); + /** */ private int currentByte; @@ -32,7 +35,7 @@ public class HuffmanDecodingInputStream extends FilterInputStream { private int bitOffset = 8; /** */ - private int root; + private final int root; /** */ public HuffmanDecodingInputStream(InputStream is) throws IOException { @@ -42,7 +45,7 @@ public HuffmanDecodingInputStream(InputStream is) throws IOException { if ((root = readTree(true)) == -1) { throw new IllegalStateException("can not initialize reading tree"); } -Debug.println(Level.FINE, "root: " + root); +logger.log(Level.DEBUG, "root: " + root); } /** @@ -56,11 +59,11 @@ private int readBit() throws IOException { } bitOffset = 0; currentByte = in.read(); -Debug.println(Level.FINE, "currentByte: " + currentByte); +logger.log(Level.DEBUG, "currentByte: " + currentByte); } int bit = (currentByte >> (7 - bitOffset)) & 0x01; -Debug.println(Level.FINE, "bit: " + bit + " (" + bitOffset + ")"); +logger.log(Level.DEBUG, "bit: " + bit + " (" + bitOffset + ")"); bitOffset++; return bit; @@ -88,9 +91,9 @@ private int readBits(int n) throws IOException { private static final int N = 256; /** */ - private int[] left = new int[2 * N - 1]; + private final int[] left = new int[2 * N - 1]; /** */ - private int[] right = new int[2 * N - 1]; + private final int[] right = new int[2 * N - 1]; /** */ private int available; // TODO thread safe? @@ -106,7 +109,7 @@ private int readTree(boolean init) throws IOException { } int bit = readBit(); -Debug.println(Level.FINE, "bit: " + bit); +logger.log(Level.DEBUG, "bit: " + bit); if (bit == -1) { return -1; } @@ -135,7 +138,7 @@ public int read() throws IOException { if (r < 0) { return -1; } else { - return buf[0]; + return buf[0] & 0xff; } } @@ -144,7 +147,7 @@ public int read(byte[] b, int offset, int length) throws IOException { int position = 0; while (position < length) { int node = root; -Debug.println(Level.FINE, "node: " + node); +logger.log(Level.DEBUG, "node: " + node); while (node >= N) { int bit = readBit(); if (bit == -1) { diff --git a/src/main/java/vavi/sound/smaf/chunk/ImageChunk.java b/src/main/java/vavi/sound/smaf/chunk/ImageChunk.java index 6d7b6af..a00b766 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ImageChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/ImageChunk.java @@ -10,12 +10,13 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.imageio.ImageIO; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,6 +29,8 @@ */ public class ImageChunk extends Chunk { + private static final Logger logger = getLogger(ImageChunk.class.getName()); + /** */ private int imageNumer; @@ -36,7 +39,7 @@ public ImageChunk(byte[] id, int size) { super(id, size); this.imageNumer = id[3]; -Debug.println(Level.FINE, "Image[" + imageNumer + "]: " + size + " bytes"); +logger.log(Level.DEBUG, "Image[" + imageNumer + "]: " + size + " bytes"); } /** */ @@ -52,7 +55,7 @@ protected void init(MyDataInputStream dis, Chunk parent) this.imageData = new byte[size]; dis.readFully(imageData); -Debug.println(Level.FINE, "image: " + getImage()); +logger.log(Level.DEBUG, "image: " + getImage()); } /** */ diff --git a/src/main/java/vavi/sound/smaf/chunk/ImageDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/ImageDataChunk.java index 5fa8242..509d8ff 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ImageDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/ImageDataChunk.java @@ -8,12 +8,14 @@ import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,10 +28,12 @@ */ public class ImageDataChunk extends Chunk { + private static final Logger logger = getLogger(ImageDataChunk.class.getName()); + /** */ public ImageDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "ImageData: " + size + " bytes"); +logger.log(Level.DEBUG, "ImageData: " + size + " bytes"); } /** */ @@ -38,7 +42,7 @@ public ImageDataChunk() { this.size = 0; } - /** */ + /** */ @Override protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { @@ -52,14 +56,14 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof LinkChunk) { // "" imageDataChunks.add(chunk); } else { - Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); + logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } -Debug.println(Level.FINE, "messages: " + imageDataChunks.size()); +logger.log(Level.DEBUG, "messages: " + imageDataChunks.size()); } /** */ - private List imageDataChunks = new ArrayList<>(); + private final List imageDataChunks = new ArrayList<>(); /** TODO */ @Override diff --git a/src/main/java/vavi/sound/smaf/chunk/LinkChunk.java b/src/main/java/vavi/sound/smaf/chunk/LinkChunk.java index d1b8526..d3b1b08 100644 --- a/src/main/java/vavi/sound/smaf/chunk/LinkChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/LinkChunk.java @@ -8,10 +8,12 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -24,10 +26,12 @@ */ public class LinkChunk extends Chunk { + private static final Logger logger = getLogger(LinkChunk.class.getName()); + /** */ public LinkChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "Link: " + size + " bytes"); +logger.log(Level.DEBUG, "Link: " + size + " bytes"); } /** */ @@ -36,7 +40,7 @@ public LinkChunk() { this.size = 0; } - /** */ + /** */ @Override protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { diff --git a/src/main/java/vavi/sound/smaf/chunk/MasterTrackChunk.java b/src/main/java/vavi/sound/smaf/chunk/MasterTrackChunk.java index 2fff0d5..486738f 100644 --- a/src/main/java/vavi/sound/smaf/chunk/MasterTrackChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/MasterTrackChunk.java @@ -8,12 +8,14 @@ import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafEvent; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,10 +28,12 @@ */ public class MasterTrackChunk extends TrackChunk { + private static final Logger logger = getLogger(MasterTrackChunk.class.getName()); + /** */ public MasterTrackChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "MasterTrack: " + size); +logger.log(Level.DEBUG, "MasterTrack: " + size); } @Override @@ -38,20 +42,20 @@ protected void init(MyDataInputStream dis, Chunk parent) this.formatType = FormatType.values()[dis.readUnsignedByte()]; this.sequenceType = SequenceType.values()[dis.readUnsignedByte()]; -Debug.println(Level.FINE, "sequenceType: " + sequenceType); +logger.log(Level.DEBUG, "sequenceType: " + sequenceType); this.durationTimeBase = dis.readUnsignedByte(); -//Debug.println("durationTimeBase: " + StringUtil.toHex2(durationTimeBase)); +//logger.log(Level.DEBUG, "durationTimeBase: " + StringUtil.toHex2(durationTimeBase)); int optionSize = dis.readUnsignedByte(); this.optionData = new byte[optionSize]; dis.readFully(optionData); while (dis.available() > 0) { -//Debug.println("available: " + is.available() + ", " + available()); +//logger.log(Level.DEBUG, "available: " + is.available() + ", " + available()); Chunk chunk = readFrom(dis); if (chunk instanceof MasterTrackSequenceDataChunk) { // "Mssq" sequenceDataChunk = chunk; } else { -Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } } diff --git a/src/main/java/vavi/sound/smaf/chunk/MasterTrackSequenceDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/MasterTrackSequenceDataChunk.java index 7f69f2d..853cc1e 100644 --- a/src/main/java/vavi/sound/smaf/chunk/MasterTrackSequenceDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/MasterTrackSequenceDataChunk.java @@ -7,10 +7,12 @@ package vavi.sound.smaf.chunk; import java.io.IOException; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -23,10 +25,12 @@ */ public class MasterTrackSequenceDataChunk extends SequenceDataChunk { + private static final Logger logger = getLogger(MasterTrackSequenceDataChunk.class.getName()); + /** */ public MasterTrackSequenceDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "MasterTrackSequenceData: " + size + " bytes"); +logger.log(Level.DEBUG, "MasterTrackSequenceData: " + size + " bytes"); } /** TODO how to get formatType from parent chunk ??? */ diff --git a/src/main/java/vavi/sound/smaf/chunk/OptionalDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/OptionalDataChunk.java index 1a03281..dbe31c4 100644 --- a/src/main/java/vavi/sound/smaf/chunk/OptionalDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/OptionalDataChunk.java @@ -9,12 +9,14 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,10 +29,12 @@ */ public class OptionalDataChunk extends Chunk { + private static final Logger logger = getLogger(OptionalDataChunk.class.getName()); + /** */ public OptionalDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "OptionalData: " + size + " bytes"); +logger.log(Level.DEBUG, "OptionalData: " + size + " bytes"); } /** */ @@ -63,7 +67,7 @@ public void writeTo(OutputStream os) throws IOException { } /** DataChunk "Dch*", ... */ - private List dataChunks = new ArrayList<>(); + private final List dataChunks = new ArrayList<>(); /** * @return Returns the subChunks. diff --git a/src/main/java/vavi/sound/smaf/chunk/PcmAudioTrackChunk.java b/src/main/java/vavi/sound/smaf/chunk/PcmAudioTrackChunk.java index ba78cd1..f65ca3a 100644 --- a/src/main/java/vavi/sound/smaf/chunk/PcmAudioTrackChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/PcmAudioTrackChunk.java @@ -9,18 +9,20 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.MetaMessage; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -35,10 +37,12 @@ */ public class PcmAudioTrackChunk extends TrackChunk { + private static final Logger logger = getLogger(PcmAudioTrackChunk.class.getName()); + /** */ public PcmAudioTrackChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "PcmAudioTrack[" + trackNumber + "]: " + size + " bytes"); +logger.log(Level.DEBUG, "PcmAudioTrack[" + trackNumber + "]: " + size + " bytes"); } /** */ @@ -53,17 +57,17 @@ protected void init(MyDataInputStream dis, Chunk parent) //skip(is, size); this.formatType = FormatType.values()[dis.readUnsignedByte()]; -Debug.println(Level.FINE, "formatType: " + formatType); +logger.log(Level.DEBUG, "formatType: " + formatType); this.sequenceType = SequenceType.values()[dis.readUnsignedByte()]; -Debug.println(Level.FINE, "sequenceType: " + sequenceType); +logger.log(Level.DEBUG, "sequenceType: " + sequenceType); this.waveType = new WaveType(dis.readUnsignedShort()); -Debug.println(Level.FINE, "waveType: " + waveType); +logger.log(Level.DEBUG, "waveType: " + waveType); this.durationTimeBase = dis.readUnsignedByte(); -Debug.println(Level.FINE, "durationTimeBase: " + durationTimeBase + ", " + getDurationTimeBase() + " ms"); +logger.log(Level.DEBUG, "durationTimeBase: " + durationTimeBase + ", " + getDurationTimeBase() + " ms"); this.gateTimeTimeBase = dis.readUnsignedByte(); -Debug.println(Level.FINE, "gateTimeTimeBase: " + gateTimeTimeBase + ", " + getGateTimeTimeBase() + " ms"); +logger.log(Level.DEBUG, "gateTimeTimeBase: " + gateTimeTimeBase + ", " + getGateTimeTimeBase() + " ms"); while (dis.available() > 0) { Chunk chunk = readFrom(dis); @@ -76,7 +80,7 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof WaveDataChunk) { waveDataChunks.add(chunk); } else { -Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } } @@ -141,7 +145,7 @@ public void setSetupDataChunk(SetupDataChunk setupDataChunk) { } /** */ - private List waveDataChunks = new ArrayList<>(); + private final List waveDataChunks = new ArrayList<>(); /** "Awa*" TODO is there really more than one? */ public void addWaveDataChunk(Chunk waveDataChunk) { diff --git a/src/main/java/vavi/sound/smaf/chunk/ScoreTrackChunk.java b/src/main/java/vavi/sound/smaf/chunk/ScoreTrackChunk.java index 32ab130..53a6574 100644 --- a/src/main/java/vavi/sound/smaf/chunk/ScoreTrackChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/ScoreTrackChunk.java @@ -9,18 +9,20 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.MetaMessage; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -43,10 +45,12 @@ */ public class ScoreTrackChunk extends TrackChunk { + private static final Logger logger = getLogger(ScoreTrackChunk.class.getName()); + /** */ public ScoreTrackChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "ScoreTrack[" + trackNumber + "]: " + size + " bytes"); +logger.log(Level.DEBUG, "ScoreTrack[" + trackNumber + "]: " + size + " bytes"); } /** */ @@ -61,21 +65,21 @@ protected void init(MyDataInputStream dis, Chunk parent) this.formatType = FormatType.values()[dis.readUnsignedByte()]; this.sequenceType = SequenceType.values()[dis.readUnsignedByte()]; -Debug.println(Level.FINE, "sequenceType: " + sequenceType); +logger.log(Level.DEBUG, "sequenceType: " + sequenceType); this.durationTimeBase = dis.readUnsignedByte(); -Debug.println(Level.FINE, "durationTimeBase: " + durationTimeBase + ", " + getDurationTimeBase() + " ms"); +logger.log(Level.DEBUG, "durationTimeBase: " + durationTimeBase + ", " + getDurationTimeBase() + " ms"); this.gateTimeTimeBase = dis.readUnsignedByte(); -Debug.println(Level.FINE, "gateTimeTimeBase: " + gateTimeTimeBase + ", " + getGateTimeTimeBase() + " ms"); +logger.log(Level.DEBUG, "gateTimeTimeBase: " + gateTimeTimeBase + ", " + getGateTimeTimeBase() + " ms"); switch (formatType) { case HandyPhoneStandard: { byte[] buffer = new byte[2]; dis.readFully(buffer); -//Debug.println(StringUtil.getDump(channelStatus)); +//logger.log(Level.DEBUG, StringUtil.getDump(channelStatus)); this.channelStatuses = new ChannelStatus[4]; for (int i = 0; i < 4; i++) { channelStatuses[i] = new ChannelStatus(i, (byte) ((buffer[i / 2] & (0xf0 >> (4 * (i % 2)))) >> (4 * ((i + 1) % 2)))); -//Debug.println(channelStatuses[i]); +//logger.log(Level.DEBUG, channelStatuses[i]); } } break; case MobileStandard_Compress: @@ -85,7 +89,7 @@ protected void init(MyDataInputStream dis, Chunk parent) this.channelStatuses = new ChannelStatus[16]; for (int i = 0; i < 16; i++) { channelStatuses[i] = new ChannelStatus(i, (int) buffer[i]); -//Debug.println(channelStatuses[i]); +//logger.log(Level.DEBUG, channelStatuses[i]); } } break; case Unknown3: { @@ -94,10 +98,10 @@ protected void init(MyDataInputStream dis, Chunk parent) // TODO implement } break; } -Debug.println(Level.FINE, "formatType: " + formatType); +logger.log(Level.DEBUG, "formatType: " + formatType); while (dis.available() > 0) { -//Debug.println("available: " + is.available() + ", " + available()); +//logger.log(Level.DEBUG, "available: " + is.available() + ", " + available()); Chunk chunk = readFrom(dis); if (chunk instanceof SeekAndPhraseInfoChunk) { seekAndPhraseInfoChunk = chunk; @@ -108,7 +112,7 @@ protected void init(MyDataInputStream dis, Chunk parent) } else if (chunk instanceof StreamPcmDataChunk) { streamPcmDataChunk = chunk; } else { -Debug.println(Level.WARNING, "unsupported chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unsupported chunk: " + chunk.getClass()); } } } @@ -202,7 +206,7 @@ public List getSmafEvents() throws InvalidSmafDataException { List messages = ((SetupDataChunk) setupDataChunk).getSmafMessages(); for (SmafMessage message : messages) { events.add(new SmafEvent(message, 0L)); -//Debug.println("SetupDataChunk: " + message); +//logger.log(Level.DEBUG, "SetupDataChunk: " + message); } } @@ -211,7 +215,7 @@ public List getSmafEvents() throws InvalidSmafDataException { List messages = ((StreamPcmDataChunk) streamPcmDataChunk).getSmafMessages(); for (SmafMessage message : messages) { events.add(new SmafEvent(message, 0L)); // TODO 0l -//Debug.println("StreamPcmDataChunk: " + message); +//logger.log(Level.DEBUG, "StreamPcmDataChunk: " + message); } } @@ -219,7 +223,7 @@ public List getSmafEvents() throws InvalidSmafDataException { List messages = ((SequenceDataChunk) sequenceDataChunk).getSmafMessages(); for (SmafMessage message : messages) { events.add(new SmafEvent(message, 0L)); // TODO 0l -//Debug.println("SequenceDataChunk: " + message); +//logger.log(Level.DEBUG, "SequenceDataChunk: " + message); } return events; diff --git a/src/main/java/vavi/sound/smaf/chunk/SeekAndPhraseInfoChunk.java b/src/main/java/vavi/sound/smaf/chunk/SeekAndPhraseInfoChunk.java index 869cc36..ba4fc4f 100644 --- a/src/main/java/vavi/sound/smaf/chunk/SeekAndPhraseInfoChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/SeekAndPhraseInfoChunk.java @@ -9,14 +9,16 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteBuffer; import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,10 +31,12 @@ */ public class SeekAndPhraseInfoChunk extends Chunk { + private static final Logger logger = getLogger(SeekAndPhraseInfoChunk.class.getName()); + /** */ public SeekAndPhraseInfoChunk(byte[] id, int size) { super(id, size); -//Debug.println("SeekAndPhraseInfo: " + size); +//logger.log(Level.DEBUG, "SeekAndPhraseInfo: " + size); } /** */ @@ -46,17 +50,17 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { byte[] data = new byte[size]; -Debug.println(Level.FINE, "SeekAndPhraseInfo: " + size + " bytes (subData)"); +logger.log(Level.DEBUG, "SeekAndPhraseInfo: " + size + " bytes (subData)"); dis.readFully(data); int i = 0; while (i < size) { -//Debug.println(i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); +//logger.log(Level.DEBUG, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); SubData subDatum = new SubData(data, i); subData.put(subDatum.getTag(), subDatum); -Debug.println(Level.FINE, "SeekAndPhraseInfo: subData: " + subDatum); +logger.log(Level.DEBUG, "SeekAndPhraseInfo: subData: " + subDatum); i += 2 + 1 + subDatum.getData().length + 1; // tag ':' data ',' -//Debug.println(i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); +//logger.log(Level.DEBUG, i + " / " + option.length + "\n" + StringUtil.getDump(option, i, option.length - i)); } } @@ -73,7 +77,7 @@ public void writeTo(OutputStream os) throws IOException { } /** */ - private Map subData = new TreeMap<>(); + private final Map subData = new TreeMap<>(); /** */ private static final String TAG_StartPoint = "st"; diff --git a/src/main/java/vavi/sound/smaf/chunk/SequenceDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/SequenceDataChunk.java index dd362d3..f01ab71 100644 --- a/src/main/java/vavi/sound/smaf/chunk/SequenceDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/SequenceDataChunk.java @@ -11,11 +11,12 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.logging.Level; import vavi.sound.midi.MidiUtil; import vavi.sound.smaf.InvalidSmafDataException; @@ -34,10 +35,10 @@ import vavi.sound.smaf.message.ProgramChangeMessage; import vavi.sound.smaf.message.UndefinedMessage; import vavi.sound.smaf.message.VolumeMessage; -import vavi.util.Debug; - import vavix.io.huffman.Huffman; +import static java.lang.System.getLogger; + /** * SequenceData Chunk. @@ -49,10 +50,12 @@ */ public class SequenceDataChunk extends Chunk { + private static final Logger logger = getLogger(SequenceDataChunk.class.getName()); + /** */ public SequenceDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "SequenceData: " + size + " bytes"); +logger.log(Level.DEBUG, "SequenceData: " + size + " bytes"); } /** */ @@ -65,7 +68,7 @@ public SequenceDataChunk() { @Override protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { -//Debug.println("available: " + is.available() + ", " + available()); +//logger.log(Level.DEBUG, "available: " + is.available() + ", " + available()); //skip(is, size); ScoreTrackChunk.FormatType formatType = ((TrackChunk) parent).getFormatType(); switch (formatType) { @@ -81,14 +84,14 @@ protected void init(MyDataInputStream dis, Chunk parent) //os1.write(baos.toByteArray()); //os1.flush(); //os1.close(); -//Debug.println("data.enc created"); +//logger.log(Level.DEBUG, "data.enc created"); byte[] decoded = new Huffman().decode(baos.toByteArray()); //OutputStream os2 = new FileOutputStream("/tmp/data.dec"); //os2.write(decoded); //os2.flush(); //os2.close(); -//Debug.println("data.dec created"); -Debug.println(Level.FINE, "decode: " + size + " -> " + decoded.length); +//logger.log(Level.DEBUG, "data.dec created"); +logger.log(Level.DEBUG, "decode: " + size + " -> " + decoded.length); size = decoded.length; readMobileStandard(new MyDataInputStream(new ByteArrayInputStream(decoded), id, decoded.length)); break; @@ -97,7 +100,7 @@ protected void init(MyDataInputStream dis, Chunk parent) readMobileStandard(dis); break; } -Debug.println(Level.FINE, "messages: " + messages.size()); +logger.log(Level.DEBUG, "messages: " + messages.size()); } /** @@ -118,7 +121,7 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) while (dis.available() > 0) { // -------- duration -------- int duration = MidiUtil.readVariableLength(dis); -//Debug.println("duration: " + duration + ", 0x" + StringUtil.toHex4(duration)); +//logger.log(Level.DEBUG, "duration: " + duration + ", 0x" + StringUtil.toHex4(duration)); // -------- event -------- int e1 = dis.readUnsignedByte(); if (e1 == 0xff) { // exclusive, nop @@ -136,12 +139,12 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) break; default: smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "unknown 0xff, 0x02x\n", e2); +logger.log(Level.WARNING, String.format("unknown 0xff, 0x%02x", e2)); break; } } else if (e1 != 0x00) { // note int gateTime = MidiUtil.readVariableLength(dis); -//Debug.println("gateTime: " + gateTime + ", 0x" + StringUtil.toHex4(gateTime)); +//logger.log(Level.DEBUG, String.format("gateTime: %d, 0x%04x", gateTime, gateTime)); smafMessage = getHandyPhoneStandardMessage(duration, e1, gateTime); } else { // e1 == 0x00 other event int e2 = dis.readUnsignedByte(); @@ -151,7 +154,7 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) smafMessage = new EndOfSequenceMessage(duration); } else { smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "unknown 0x00, 0x00, 0x02x\n", e3); +logger.log(Level.WARNING, String.format("unknown 0x00, 0x00, 0x%02x", e3)); } } else { int channel = (e2 & 0xc0) >> 6; @@ -187,7 +190,7 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) break; default: smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "unknown 0x00, 0x02x, 3, %02x\n", e2, data); +logger.log(Level.WARNING, String.format("unknown 0x00, 0x%02x, 3, %02x", e2, data)); break; } break; @@ -203,9 +206,9 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) } } } -//Debug.println(available() + ", " + smafMessage); +//logger.log(Level.DEBUG, available() + ", " + smafMessage); if (smafMessage != null) { -//Debug.println("message: " + smafMessage); +//logger.log(Level.DEBUG, "message: " + smafMessage); messages.add(smafMessage); } else { assert false : "smafMessage is null"; @@ -220,7 +223,7 @@ protected void readHandyPhoneStandard(MyDataInputStream dis) }; /** debug */ -private Set uc = new HashSet<>(); +private final Set uc = new HashSet<>(); /** debug */ private int cc = 0; @@ -233,7 +236,7 @@ private void readMobileStandard(MyDataInputStream dis) while (dis.available() > 0) { // duration int duration = MidiUtil.readVariableLength(dis); -//Debug.println("duration: " + duration); +//logger.log(Level.DEBUG, "duration: " + duration); // event int status = dis.readUnsignedByte(); if (status >= 0x80 && status <= 0x8f) { // note w/o velocity @@ -251,7 +254,7 @@ private void readMobileStandard(MyDataInputStream dis) int d1 = dis.readUnsignedByte(); int d2 = dis.readUnsignedByte(); smafMessage = null; -Debug.printf(Level.WARNING, "reserved: 0xa_: %02x%02x\n", d1, d2); +logger.log(Level.WARNING, String.format("reserved: 0xa_: %02x%02x", d1, d2)); } else if (status >= 0xb0 && status <= 0xbf) { // control change int channel = status & 0x0f; int control = dis.readUnsignedByte(); @@ -293,7 +296,7 @@ private void readMobileStandard(MyDataInputStream dis) break; default: smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "undefined control: %02x, %02x\n", control, value); +logger.log(Level.WARNING, String.format("undefined control: %02x, %02x", control, value)); break; } } else if (status >= 0xc0 && status <= 0xcf) { // program change @@ -303,7 +306,7 @@ private void readMobileStandard(MyDataInputStream dis) } else if (status >= 0xd0 && status <= 0xdf) { // reserved int d1 = dis.readUnsignedByte(); smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "reserved: 0xd_: %02x\n", d1); +logger.log(Level.WARNING, String.format("reserved: 0xd_: %02x", d1)); } else if (status >= 0xe0 && status <= 0xef) { // pitch vend message int channel = status & 0x0f; int lsb = dis.readUnsignedByte(); @@ -318,13 +321,13 @@ private void readMobileStandard(MyDataInputStream dis) case 0x2f: int d2 = dis.readUnsignedByte(); // must be 0 if (d2 != 0) { -Debug.printf(Level.WARNING, "illegal state: %02x\n", d2); +logger.log(Level.WARNING, String.format("illegal state: %02x", d2)); } smafMessage = new EndOfSequenceMessage(duration); break; default: smafMessage = new UndefinedMessage(duration); -Debug.printf(Level.WARNING, "unknown: 0xff: %02x\n", d1); +logger.log(Level.WARNING, String.format("unknown: 0xff: %02x", d1)); break; } } else if (status == 0xf0) { // exclusive @@ -336,18 +339,18 @@ private void readMobileStandard(MyDataInputStream dis) } else if (status < 0x80) { // data smafMessage = null; if (cc < 10) { - Debug.printf(Level.WARNING, "data found, ignore: %02x\n", status); + logger.log(Level.WARNING, String.format("data found, ignore: %02x", status)); } cc++; } else /* 0xf1 ~ 0xfe */ { // reserved smafMessage = new UndefinedMessage(duration); if (!uc.contains(String.format("reserved: %02x", status))) { - Debug.printf(Level.WARNING, "reserved: %02x\n", status); + logger.log(Level.WARNING, String.format("reserved: %02x", status)); uc.add(String.format("reserved: %02x", status)); } } -//Debug.println(available() + ", " + smafMessage); +//logger.log(Level.DEBUG, available() + ", " + smafMessage); if (smafMessage != null) { messages.add(smafMessage); } else { @@ -369,7 +372,7 @@ public void writeTo(OutputStream os) throws IOException { } /** */ - protected List messages = new ArrayList<>(); + protected final List messages = new ArrayList<>(); /** * @return Returns the messages. diff --git a/src/main/java/vavi/sound/smaf/chunk/SetupDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/SetupDataChunk.java index 0b22601..7c087a4 100644 --- a/src/main/java/vavi/sound/smaf/chunk/SetupDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/SetupDataChunk.java @@ -9,16 +9,18 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.midi.MidiUtil; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.SysexMessage; import vavi.sound.smaf.message.UndefinedMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,10 +33,12 @@ */ public class SetupDataChunk extends Chunk { + private static final Logger logger = getLogger(SetupDataChunk.class.getName()); + /** */ public SetupDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "SetupData: " + size + " bytes"); +logger.log(Level.DEBUG, "SetupData: " + size + " bytes"); } /** */ @@ -59,7 +63,7 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataE readMobileStandard(dis); break; } -Debug.println(Level.FINE, "messages: " + messages.size()); +logger.log(Level.DEBUG, "messages: " + messages.size()); } /** @@ -92,12 +96,12 @@ private void readHandyPhoneStandard(MyDataInputStream dis) throws InvalidSmafDat break; default: smafMessage = new UndefinedMessage(0); -Debug.printf(Level.WARNING, "unknown 0xff, 0x%02x\n", e2); +logger.log(Level.WARNING, String.format("unknown 0xff, 0x%02x", e2)); break; } } else { smafMessage = new UndefinedMessage(0); -Debug.printf(Level.WARNING, "unhandled: %02x\n", e1); +logger.log(Level.WARNING, String.format("unhandled: %02x", e1)); } if (smafMessage != null) { @@ -124,7 +128,7 @@ private void readMobileStandard(MyDataInputStream dis) throws InvalidSmafDataExc smafMessage = SysexMessage.Factory.getSysexMessage(0, data); } else { smafMessage = new UndefinedMessage(0); -Debug.printf(Level.WARNING, "unhandled: %02x\n", status); +logger.log(Level.WARNING, String.format("unhandled: %02x", status)); } if (smafMessage != null) { @@ -149,7 +153,7 @@ public void writeTo(OutputStream os) throws IOException { } /** SysEx messages */ - private List messages = new ArrayList<>(); + private final List messages = new ArrayList<>(); /** * @return Returns the messages. diff --git a/src/main/java/vavi/sound/smaf/chunk/StreamPcmDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/StreamPcmDataChunk.java index 935a8d5..00ad30b 100644 --- a/src/main/java/vavi/sound/smaf/chunk/StreamPcmDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/StreamPcmDataChunk.java @@ -9,13 +9,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -29,10 +31,12 @@ */ public class StreamPcmDataChunk extends Chunk { + private static final Logger logger = getLogger(StreamPcmDataChunk.class.getName()); + /** */ public StreamPcmDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "StreamPcmData: " + size); +logger.log(Level.DEBUG, "StreamPcmData: " + size); } /** */ @@ -48,7 +52,7 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataE if (chunk instanceof StreamWaveDataChunk) { streamWaveDataChunks.add(chunk); } else { -Debug.println(Level.WARNING, "unknown chunk: " + chunk.getClass()); +logger.log(Level.WARNING, "unknown chunk: " + chunk.getClass()); } } } @@ -66,7 +70,7 @@ public void writeTo(OutputStream os) throws IOException { } /** */ - private List streamWaveDataChunks = new ArrayList<>(); + private final List streamWaveDataChunks = new ArrayList<>(); /** "Mwa*" */ public void addWaveDataChunk(Chunk streamWaveDataChunk) { diff --git a/src/main/java/vavi/sound/smaf/chunk/StreamWaveDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/StreamWaveDataChunk.java index 3019209..ad21770 100644 --- a/src/main/java/vavi/sound/smaf/chunk/StreamWaveDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/StreamWaveDataChunk.java @@ -7,12 +7,14 @@ package vavi.sound.smaf.chunk; import java.io.IOException; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.message.WaveDataMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -25,10 +27,12 @@ */ public class StreamWaveDataChunk extends WaveDataChunk { + private static final Logger logger = getLogger(StreamWaveDataChunk.class.getName()); + /** */ public StreamWaveDataChunk(byte[] id, int size) { super(id, size); -Debug.println(Level.FINE, "StreamWaveData: " + size); +logger.log(Level.DEBUG, "StreamWaveData: " + size); } /** */ diff --git a/src/main/java/vavi/sound/smaf/chunk/SubData.java b/src/main/java/vavi/sound/smaf/chunk/SubData.java index ebf2592..bfe7553 100644 --- a/src/main/java/vavi/sound/smaf/chunk/SubData.java +++ b/src/main/java/vavi/sound/smaf/chunk/SubData.java @@ -89,7 +89,7 @@ public int getSize() { } /** */ - private String tag; + private final String tag; /** tag */ public String getTag() { @@ -97,7 +97,7 @@ public String getTag() { } /** */ - private byte[] data; + private final byte[] data; /** Data */ public byte[] getData() { diff --git a/src/main/java/vavi/sound/smaf/chunk/TrackChunk.java b/src/main/java/vavi/sound/smaf/chunk/TrackChunk.java index 4251c75..a583627 100644 --- a/src/main/java/vavi/sound/smaf/chunk/TrackChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/TrackChunk.java @@ -139,7 +139,7 @@ public void setSequenceType(SequenceType sequenceType) { * @param timeBase real timeBase [msec] * @return index of timeBase */ - private int findTimeBase(int timeBase) { + private static int findTimeBase(int timeBase) { for (int i = 0; i < timeBaseTable.length; i++) { if (timeBase == timeBaseTable[i]) { return i; diff --git a/src/main/java/vavi/sound/smaf/chunk/UndefinedChunk.java b/src/main/java/vavi/sound/smaf/chunk/UndefinedChunk.java index 4e802e4..f783a72 100644 --- a/src/main/java/vavi/sound/smaf/chunk/UndefinedChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/UndefinedChunk.java @@ -8,12 +8,14 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * Undefined Chunk. @@ -23,6 +25,8 @@ */ public class UndefinedChunk extends Chunk { + private static final Logger logger = getLogger(UndefinedChunk.class.getName()); + /** */ public UndefinedChunk(byte[] id, int size) { super(id, size); @@ -34,18 +38,18 @@ protected void init(MyDataInputStream dis, Chunk parent) throws InvalidSmafDataException, IOException { if (size > dis.available()) { -Debug.println(Level.WARNING, "read size is larger than available stream"); +logger.log(Level.WARNING, "read size is larger than available stream"); //new Exception("*** DUMMY ***").printStackTrace(System.err); throw new InvalidSmafDataException("read size is larger than available stream"); } byte[] data = new byte[size]; dis.readFully(data); -Debug.println(Level.WARNING, "Undefined: size: " + size + "\n" + StringUtil.getDump(data, 64)); +logger.log(Level.WARNING, "Undefined: size: " + size + "\n" + StringUtil.getDump(data, 64)); } @Override public void writeTo(OutputStream os) throws IOException { // TODO -Debug.println(Level.WARNING, "not implemented skip"); +logger.log(Level.WARNING, "not implemented skip"); } } diff --git a/src/main/java/vavi/sound/smaf/chunk/WaveDataChunk.java b/src/main/java/vavi/sound/smaf/chunk/WaveDataChunk.java index c7aabe6..94c5e8a 100644 --- a/src/main/java/vavi/sound/smaf/chunk/WaveDataChunk.java +++ b/src/main/java/vavi/sound/smaf/chunk/WaveDataChunk.java @@ -9,12 +9,14 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.message.WaveDataMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,12 +29,14 @@ */ public class WaveDataChunk extends Chunk { + private static final Logger logger = getLogger(WaveDataChunk.class.getName()); + /** */ public WaveDataChunk(byte[] id, int size) { super(id, size); waveNumber = id[3] & 0xff; -Debug.println(Level.FINE, "WaveData[" + waveNumber + "]: " + size + " bytes"); +logger.log(Level.DEBUG, "WaveData[" + waveNumber + "]: " + size + " bytes"); } /** */ diff --git a/src/main/java/vavi/sound/smaf/chunk/WaveType.java b/src/main/java/vavi/sound/smaf/chunk/WaveType.java index b7fb891..c8068e2 100644 --- a/src/main/java/vavi/sound/smaf/chunk/WaveType.java +++ b/src/main/java/vavi/sound/smaf/chunk/WaveType.java @@ -7,9 +7,10 @@ package vavi.sound.smaf.chunk; import java.io.IOException; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; -import vavi.util.Debug; +import static java.lang.System.getLogger; /** @@ -33,8 +34,10 @@ */ public class WaveType { + private static final Logger logger = getLogger(WaveType.class.getName()); + /** 1, 2 */ - private int waveChannels; + private final int waveChannels; /** * TODO different numbers in chunks, can it be solved with enum? @@ -61,16 +64,16 @@ public class WaveType { * 5 Offset Binary PCM (unsigned PCM?) * */ - private int waveFormat; + private final int waveFormat; /** */ private static final int[] samplingFreqs = { 4000, 8000, 11000, 22050, 44100 }; /** 4000, 8000, 11000, 22050, 44100 */ - private int waveSamplingFreq; + private final int waveSamplingFreq; /** 4, 8, 12, 16 */ - private int waveBaseBit; + private final int waveBaseBit; /** */ private static final int[] tableForMwq = { 4, 5, 1 }; @@ -88,12 +91,12 @@ public class WaveType { * */ WaveType(int waveType) throws IOException { -//Debug.println("waveType: " + StringUtil.toHex4(waveType)); +//logger.log(Level.DEBUG, "waveType: " + StringUtil.toHex4(waveType)); this.waveChannels = (waveType & 0x8000) != 0 ? 2 : 1; this.waveFormat = (waveType & 0x7000) >> 12; this.waveSamplingFreq = samplingFreqs[(waveType & 0x0f00) >> 8]; this.waveBaseBit = 4 * (((waveType & 0x00f0) >> 4) + 1); -Debug.println(Level.FINE, "waveType: " + this); +logger.log(Level.DEBUG, "waveType: " + this); } /** @@ -108,12 +111,12 @@ public class WaveType { * */ WaveType(byte[] waveType) throws IOException { -Debug.printf(Level.FINE, "waveType: %02x %02x %02x\n", waveType[0], waveType[1], waveType[2]); +logger.log(Level.DEBUG, String.format("waveType: %02x %02x %02x", waveType[0], waveType[1], waveType[2])); this.waveChannels = (waveType[0] & 0x80) != 0 ? 2 : 1; this.waveFormat = tableForMwq[(waveType[0] & 0x70) >> 4]; this.waveBaseBit = 4 * ((waveType[0] & 0x0f) + 1); this.waveSamplingFreq = ((waveType[1] & 0xff) << 8) | waveType[2] & 0xff; -Debug.println(Level.FINE, "waveType: " + this); +logger.log(Level.DEBUG, "waveType: " + this); } /** @@ -135,25 +138,13 @@ int intValue() { int waveType = 0; waveType |= waveChannels == 2 ? 0x8000: 0; waveType |= waveFormat << 12; // TODO 5, 6 - int v; - switch (waveSamplingFreq) { - case 4000: - v = 0; - break; - case 8000: - default: - v = 1; - break; - case 11000: - v = 2; - break; - case 22050: - v = 3; - break; - case 44100: - v = 4; - break; - } + int v = switch (waveSamplingFreq) { + case 4000 -> 0; + default -> 1; + case 11000 -> 2; + case 22050 -> 3; + case 44100 -> 4; + }; waveType |= v << 8; waveType |= (waveBaseBit / 4 - 1) << 4; return waveType; diff --git a/src/main/java/vavi/sound/smaf/message/BankSelectMessage.java b/src/main/java/vavi/sound/smaf/message/BankSelectMessage.java index 270ef4b..4c47534 100644 --- a/src/main/java/vavi/sound/smaf/message/BankSelectMessage.java +++ b/src/main/java/vavi/sound/smaf/message/BankSelectMessage.java @@ -6,7 +6,8 @@ package vavi.sound.smaf.message; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiEvent; import javax.sound.midi.ShortMessage; @@ -14,7 +15,8 @@ import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.chunk.TrackChunk.FormatType; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,6 +28,8 @@ public class BankSelectMessage extends vavi.sound.smaf.ShortMessage implements MidiConvertible, SmafConvertible { + private static final Logger logger = getLogger(BankSelectMessage.class.getName()); + /** smaf channel */ private int channel; @@ -125,7 +129,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataException { if (significant == null) { // HandyPhoneStandard -Debug.printf(Level.FINE, "BankSelect: [%d] %dch, 0x%02x", duration, channel, bank); +logger.log(Level.DEBUG, String.format("BankSelect: [%d] %dch, 0x%02x", duration, channel, bank)); int data2; if ((bank & 0x80) != 0) { context.setDrum(channel, MidiContext.ChannelConfiguration.PERCUSSION); @@ -161,7 +165,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) } else { // MobileStandard int midiChannel = context.retrieveChannel(this.channel); -Debug.println(Level.FINE, "BankSelect(" + significant + "): [" + duration + "] " + midiChannel + "ch, " + bank); +logger.log(Level.DEBUG, "BankSelect(" + significant + "): [" + duration + "] " + midiChannel + "ch, " + bank); ShortMessage shortMessage = new ShortMessage(); shortMessage.setMessage(ShortMessage.CONTROL_CHANGE, midiChannel, @@ -190,7 +194,7 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) changeBankMessage.setBank(data1); context.setBeforeTick(track, midiEvent.getTick()); -//Debug.println(channel + ": " + StringUtil.toHex2(data1) + ", " + StringUtil.toHex2(changeVoiceMessage.getProgram()) + ", " + changeBankMessage.getBank()); +//logger.log(Level.DEBUG, channel + ": " + StringUtil.toHex2(data1) + ", " + StringUtil.toHex2(changeVoiceMessage.getProgram()) + ", " + changeBankMessage.getBank()); return new SmafEvent[] { new SmafEvent(changeBankMessage, midiEvent.getTick()), diff --git a/src/main/java/vavi/sound/smaf/message/EndOfSequenceMessage.java b/src/main/java/vavi/sound/smaf/message/EndOfSequenceMessage.java index dc8ffa9..0a9166a 100644 --- a/src/main/java/vavi/sound/smaf/message/EndOfSequenceMessage.java +++ b/src/main/java/vavi/sound/smaf/message/EndOfSequenceMessage.java @@ -9,14 +9,15 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.MidiEvent; import vavi.sound.midi.MidiUtil; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.chunk.TrackChunk.FormatType; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -34,6 +35,8 @@ public class EndOfSequenceMessage extends vavi.sound.smaf.ShortMessage implements MidiConvertible, SmafConvertible { + private static final Logger logger = getLogger(EndOfSequenceMessage.class.getName()); + /** for SmafConvertible */ public EndOfSequenceMessage() { } @@ -87,7 +90,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) { javax.sound.midi.Track midiTrack = context.getMidiTrack(); MidiEvent midiEvent = midiTrack.get(midiTrack.size() - 1); // should be EoT midiEvent.setTick(context.getCurrentTick()); -Debug.println(Level.FINE, "EOT: " + midiEvent.getMessage().getClass().getName()); +logger.log(Level.DEBUG, "EOT: " + midiEvent.getMessage().getClass().getName()); return null; } diff --git a/src/main/java/vavi/sound/smaf/message/ExpressionMessage.java b/src/main/java/vavi/sound/smaf/message/ExpressionMessage.java index 09f77ac..a7e06d2 100644 --- a/src/main/java/vavi/sound/smaf/message/ExpressionMessage.java +++ b/src/main/java/vavi/sound/smaf/message/ExpressionMessage.java @@ -95,7 +95,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) MidiEvent[] events = new MidiEvent[1]; ShortMessage shortMessage = new ShortMessage(); -//Debug.println("Expression: [" + duration + "] " + channel + "ch, " + volume); +//logger.log(Level.DEBUG, "Expression: [" + duration + "] " + channel + "ch, " + volume); shortMessage.setMessage(ShortMessage.CONTROL_CHANGE, midiChannel, 11, // expression MSB diff --git a/src/main/java/vavi/sound/smaf/message/MidiContext.java b/src/main/java/vavi/sound/smaf/message/MidiContext.java index 5d432a5..ae6712f 100644 --- a/src/main/java/vavi/sound/smaf/message/MidiContext.java +++ b/src/main/java/vavi/sound/smaf/message/MidiContext.java @@ -6,8 +6,9 @@ package vavi.sound.smaf.message; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; -import java.util.logging.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -20,7 +21,8 @@ import vavi.sound.smaf.chunk.ChannelStatus; import vavi.sound.smaf.chunk.ScoreTrackChunk; import vavi.sound.smaf.chunk.TrackChunk.FormatType; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -31,6 +33,8 @@ */ public class MidiContext { + private static final Logger logger = getLogger(MidiContext.class.getName()); + /** Max MIDI channels */ public static final int MAX_MIDI_CHANNELS = 16; @@ -73,7 +77,7 @@ public void setTrack(Track smafTrack) { if (metaMessage.getType() == MetaEvent.META_MACHINE_DEPEND.number()) { // this.formatType = (FormatType) metaMessage.getData().get("formatType"); // [ms] -Debug.println(Level.FINE, "formatType: " + formatType); +logger.log(Level.DEBUG, "formatType: " + formatType); for (int i = 0; i < MAX_MIDI_CHANNELS; i++) { if (formatType == FormatType.HandyPhoneStandard) { velocities[i] = 0x7f; @@ -83,7 +87,7 @@ public void setTrack(Track smafTrack) { } // ChannelStatus[] channelStatuses = (ChannelStatus[]) metaMessage.getData().get("channelStatuses"); -Debug.println(Level.FINE, "channelStatuses: " + (channelStatuses != null ? channelStatuses.length : null)); +logger.log(Level.DEBUG, "channelStatuses: " + (channelStatuses != null ? channelStatuses.length : null)); if (channelStatuses != null) { for (int i = 0; i < channelStatuses.length; i++) { setDrum(i, toChannelConfiguration(getMidiChannel(i), channelStatuses[i].getType())); @@ -113,18 +117,14 @@ public javax.sound.midi.Track getMidiTrack() { } /** convert types */ - private ChannelConfiguration toChannelConfiguration(int midiChannel, ChannelStatus.Type type) { - switch (type) { - case Melody: - return ChannelConfiguration.SOUND_SET; - case NoCare: - return midiChannel == CHANNEL_DRUM ? ChannelConfiguration.PERCUSSION : ChannelConfiguration.SOUND_SET; - case NoMelody: - default: - return ChannelConfiguration.UNUSED; - case Rhythm: - return ChannelConfiguration.PERCUSSION; - } + private static ChannelConfiguration toChannelConfiguration(int midiChannel, ChannelStatus.Type type) { + return switch (type) { + case Melody -> ChannelConfiguration.SOUND_SET; + case NoCare -> + midiChannel == CHANNEL_DRUM ? ChannelConfiguration.PERCUSSION : ChannelConfiguration.SOUND_SET; + default -> ChannelConfiguration.UNUSED; + case Rhythm -> ChannelConfiguration.PERCUSSION; + }; } /** current track no. */ @@ -141,7 +141,7 @@ public void setSmafTrackNumber(int smafTrackNumber) { } /** current ticks, index is smafTrackNumber */ - private long[] currentTicks = new long[4]; + private final long[] currentTicks = new long[4]; /** * smafTrackNumber must be set @@ -168,10 +168,10 @@ public void addCurrentTick(long ticks) { } /** whether channel is for rhythm, index is pseudo MIDI channel */ - private ChannelConfiguration[] drums = new ChannelConfiguration[MAX_MIDI_CHANNELS]; + private final ChannelConfiguration[] drums = new ChannelConfiguration[MAX_MIDI_CHANNELS]; /** index is pseudo MIDI channel */ - private int[] velocities = new int[MAX_MIDI_CHANNELS]; + private final int[] velocities = new int[MAX_MIDI_CHANNELS]; /* init */ { Arrays.fill(drums, ChannelConfiguration.UNUSED); @@ -199,10 +199,10 @@ public void setDrum(int smafChannel, ChannelConfiguration value) { int midiChannel = getMidiChannel(smafChannel); if (drumSwapChannel != CHANNEL_UNUSED && midiChannel == drumSwapChannel) { -Debug.println(Level.FINE, "already swapped: " + midiChannel + ", " + value); +logger.log(Level.DEBUG, "already swapped: " + midiChannel + ", " + value); } else { drums[midiChannel] = value; -//Debug.println("temporary: " + midiChannel + ", " + value); +//logger.log(Level.DEBUG, "temporary: " + midiChannel + ", " + value); } // if DRUM_CHANNEL is not a rhythm, replace it with an empty channel. @@ -210,14 +210,14 @@ public void setDrum(int smafChannel, ChannelConfiguration value) { for (int k = MAX_MIDI_CHANNELS - 1; k >= 0; k--) { if (k != CHANNEL_DRUM && drums[k] == ChannelConfiguration.UNUSED) { drumSwapChannel = k; -Debug.println(Level.FINE, "channel 9 -> " + k); +logger.log(Level.DEBUG, "channel 9 -> " + k); break; } } if (drumSwapChannel == CHANNEL_UNUSED) { - Debug.println(Level.FINE, "cannot swap: " + midiChannel + ", " + value); + logger.log(Level.DEBUG, "cannot swap: " + midiChannel + ", " + value); } -Debug.println(Level.FINE, "channel configuration: " + midiChannel + "ch, " + drums[midiChannel]); +logger.log(Level.DEBUG, "channel configuration: " + midiChannel + "ch, " + drums[midiChannel]); } if (value != ChannelConfiguration.UNUSED) { StringBuilder sb1 = new StringBuilder(16); @@ -228,12 +228,12 @@ public void setDrum(int smafChannel, ChannelConfiguration value) { sb2.append(midiChannel == i ? "*" : " "); sb3.append(drums[i].name().charAt(0)); } -Debug.println(Level.FINE, "drums: " + midiChannel + "ch, " + value + "\n" + sb1 + "\n" + sb2 + "\n" + sb3); +logger.log(Level.DEBUG, "drums: " + midiChannel + "ch, " + value + "\n" + sb1 + "\n" + sb2 + "\n" + sb3); } } /** program no, index is pseudo MIDI channel assigned to channel */ - private int[] programs = new int[MAX_MIDI_CHANNELS]; + private final int[] programs = new int[MAX_MIDI_CHANNELS]; /** * @param smafChannel SMAF channel @@ -244,7 +244,7 @@ private int getMidiChannel(int smafChannel) { return smafTrackNumber * 4 + smafChannel; } else { if (smafTrackNumber > 0) { - Debug.println(Level.FINE, "track > 0: " + smafTrackNumber); + logger.log(Level.DEBUG, "track > 0: " + smafTrackNumber); } return smafTrackNumber * 16 + smafChannel; } @@ -259,7 +259,7 @@ public int setProgram(int smafChannel, int program) { if (formatType != FormatType.HandyPhoneStandard) { if (midiChannel != drumSwapChannel && drums[midiChannel] == ChannelConfiguration.PERCUSSION) { -Debug.println(Level.FINE, "drum always zero:[" + midiChannel + "]: " + program); +logger.log(Level.DEBUG, "drum always zero:[" + midiChannel + "]: " + program); program = 0; } } @@ -290,7 +290,7 @@ public int retrieveChannel(int smafChannel) { int midiChannel = getMidiChannel(smafChannel); // if (midiChannel == drumSwapChannel) { -//Debug.println("used swapped channel: " + midiChannel); +//logger.log(Level.DEBUG, "used swapped channel: " + midiChannel); // } // drum channel is used as sound @@ -317,31 +317,21 @@ public int retrievePitch(int smafChannel, int pitch) { if (formatType == ScoreTrackChunk.FormatType.HandyPhoneStandard) { int midiChannel = getMidiChannel(smafChannel); if (drums[midiChannel] == ChannelConfiguration.PERCUSSION) { -//Debug.println("drum pitch: " + (programs[midiChannel] & 0x7f) + ", " + pitch); +//logger.log(Level.DEBUG, "drum pitch: " + (programs[midiChannel] & 0x7f) + ", " + pitch); return programs[midiChannel] & 0x7f; } else { pitch += 36; - switch (octaveShifts[midiChannel]) { - default: - case 0: - return pitch; - case 1: - return pitch + 12; - case 2: - return pitch + 24; - case 3: - return pitch + 36; - case 4: - return pitch + 48; - case 0x81: - return pitch - 12; - case 0x82: - return pitch - 24; - case 0x83: - return pitch - 36; - case 0x84: - return pitch - 48; - } + return switch (octaveShifts[midiChannel]) { + default -> pitch; + case 1 -> pitch + 12; + case 2 -> pitch + 24; + case 3 -> pitch + 36; + case 4 -> pitch + 48; + case 0x81 -> pitch - 12; + case 0x82 -> pitch - 24; + case 0x83 -> pitch - 36; + case 0x84 -> pitch - 48; + }; } } else { return pitch; @@ -368,7 +358,7 @@ public int retrievePitch(int smafChannel, int pitch) { * * @see OctaveShiftMessage */ - private int[] octaveShifts = new int[MAX_MIDI_CHANNELS]; + private final int[] octaveShifts = new int[MAX_MIDI_CHANNELS]; /** * @param smafChannel channel @@ -379,7 +369,7 @@ public int retrievePitch(int smafChannel, int pitch) { public void setOctaveShift(int smafChannel, int octaveShift) { int midiChannel = getMidiChannel(smafChannel); octaveShifts[midiChannel] = octaveShift; -//Debug.println("octaveShifts[" + midiChannel + "]: " + octaveShift); +//logger.log(Level.DEBUG, "octaveShifts[" + midiChannel + "]: " + octaveShift); } /** @@ -391,7 +381,7 @@ public void setOctaveShift(int smafChannel, int octaveShift) { public int setVelocity(int smafChannel, int velocity) { int midiChannel = getMidiChannel(smafChannel); velocities[midiChannel] = velocity; -//Debug.println("velocities[" + mididChannel + "]: " + octaveShift); +//logger.log(Level.DEBUG, "velocities[" + mididChannel + "]: " + octaveShift); return velocity; // TODO mhh... } @@ -481,7 +471,7 @@ public int getVelocity(int smafChannel) { /* */ static { -Debug.println(Level.FINE, "tempoTable: " + tempoTable.length); +logger.log(Level.DEBUG, "tempoTable: " + tempoTable.length); } /** if no tempo is specified, SSD will treat it as a quarter note = 120 */ @@ -537,7 +527,7 @@ public int getResolution(Track[] smafTracks) if (message instanceof vavi.sound.smaf.MetaMessage metaMessage) { if (metaMessage.getType() == MetaEvent.META_MACHINE_DEPEND.number()) { this.timeBase = (Integer) metaMessage.getData().get("durationTimeBase"); // [ms] -Debug.println(Level.FINE, "timebase: " + timeBase + ", (" + t + ":" + i + ")"); +logger.log(Level.DEBUG, "timebase: " + timeBase + ", (" + t + ":" + i + ")"); return tempo * timeBase; } } @@ -545,7 +535,7 @@ public int getResolution(Track[] smafTracks) t++; } -Debug.println(Level.FINE, "no tempo message in track 0"); +logger.log(Level.DEBUG, "no tempo message in track 0"); return 120; } } diff --git a/src/main/java/vavi/sound/smaf/message/MidiConvertibleMessage.java b/src/main/java/vavi/sound/smaf/message/MidiConvertibleMessage.java index 92559cb..71e8396 100644 --- a/src/main/java/vavi/sound/smaf/message/MidiConvertibleMessage.java +++ b/src/main/java/vavi/sound/smaf/message/MidiConvertibleMessage.java @@ -24,13 +24,13 @@ public class MidiConvertibleMessage extends vavi.sound.smaf.ShortMessage implements MidiConvertible { /** smaf channel */ - private int channel; + private final int channel; /** */ - private int command; + private final int command; /** */ - private int value; + private final int value; /** * @param duration duration @@ -93,7 +93,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce MidiEvent[] events = new MidiEvent[1]; ShortMessage shortMessage = new ShortMessage(); -//Debug.println("(" + StringUtil.toHex2(command) + "): " + channel + "ch, " + StringUtil.toHex2(value)); +//logger.log(Level.DEBUG, "(" + StringUtil.toHex2(command) + "): " + channel + "ch, " + StringUtil.toHex2(value)); shortMessage.setMessage(ShortMessage.CONTROL_CHANGE, midiChannel, command, diff --git a/src/main/java/vavi/sound/smaf/message/NoteMessage.java b/src/main/java/vavi/sound/smaf/message/NoteMessage.java index ebdeb61..5738c8c 100644 --- a/src/main/java/vavi/sound/smaf/message/NoteMessage.java +++ b/src/main/java/vavi/sound/smaf/message/NoteMessage.java @@ -6,9 +6,9 @@ package vavi.sound.smaf.message; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.NoSuchElementException; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiEvent; import javax.sound.midi.ShortMessage; @@ -16,7 +16,8 @@ import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -28,6 +29,8 @@ public class NoteMessage extends SmafMessage implements MidiConvertible { + private static final Logger logger = getLogger(NoteMessage.class.getName()); + /** note */ private int note; @@ -71,7 +74,7 @@ public NoteMessage(int duration, int status, int gateTime) { this.note = status & 0x0f; this.gateTime = gateTime; //if (gateTime == 0) { -// Debug.println(Level.WARNING, "★★★★★ gateTime == 0: " + channel + "ch, note: " + note); +// logger.log(Level.WARNING, "★★★★★ gateTime == 0: " + channel + "ch, note: " + note); //} this.velocity = -1; } @@ -105,18 +108,17 @@ protected NoteMessage() { * @return note */ public int getNote() { - switch (octave) { - case 0: // 00 - return note; - case 1: // 01 - return note + 12; - case 2: // 10 - return note + 24; - case 3: // 11 - return note + 36; - default: - return note; - } + return switch (octave) { + case 0 -> // 00 + note; + case 1 -> // 01 + note + 12; + case 2 -> // 10 + note + 24; + case 3 -> // 11 + note + 36; + default -> note; + }; } /** @@ -216,7 +218,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) if (gateTime == 0) { if (uc < 10) { - Debug.println(Level.WARNING, "★★★★★ gateTime == 0 ignored: " + this); + logger.log(Level.WARNING, "★★★★★ gateTime == 0 ignored: " + this); } uc++; return null; @@ -232,7 +234,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) midiChannel, pitch, velocity); -//Debug.println("note: " + channel + ": " + pitch); +//logger.log(Level.DEBUG, "note: " + channel + ": " + pitch); events[0] = new MidiEvent(shortMessage, context.getCurrentTick()); shortMessage = new ShortMessage(); @@ -258,14 +260,14 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) int command = shortMessage.getCommand(); int data1 = shortMessage.getData1(); int data2 = shortMessage.getData2(); -//Debug.println(midiEvent.getTick() + ", " + channel + ", " + command + ", " + (context.retrievePitch(channel, data1) + 45) + ", " + (data2 / 2)); +//logger.log(Level.DEBUG, midiEvent.getTick() + ", " + channel + ", " + command + ", " + (context.retrievePitch(channel, data1) + 45) + ", " + (data2 / 2)); if (command == ShortMessage.NOTE_OFF || // note on with velocity 0 (command == ShortMessage.NOTE_ON && data2 == 0)) { if (!context.isNoteOffEventUsed()) { -Debug.println(Level.FINE, "[" + context.getMidiEventIndex() + "] no pair of ON for: " + channel + "ch, " + data1); +logger.log(Level.DEBUG, "[" + context.getMidiEventIndex() + "] no pair of ON for: " + channel + "ch, " + data1); } return null; @@ -276,7 +278,7 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) try { noteOffEvent = context.getNoteOffMidiEvent(); } catch (NoSuchElementException e) { -Debug.println(Level.WARNING, "[" + context.getMidiEventIndex() + "] no pair of OFF for: " + channel + "ch, " + data1); +logger.log(Level.WARNING, "[" + context.getMidiEventIndex() + "] no pair of OFF for: " + channel + "ch, " + data1); return null; } @@ -301,12 +303,12 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) smafMessage.setNote(context.retrievePitch(channel, data1)); smafMessage.setGateTime(i == onLength - 1 ? length % 255 : 255); if (length >= 255) { - Debug.println(Level.FINE, channel + "ch, " + smafMessage.getNote() + ", " + smafMessage.getDuration() + ":[" + i + "]:" + (i == onLength - 1 ? length % 255 : 255) + "/" + length); + logger.log(Level.DEBUG, channel + "ch, " + smafMessage.getNote() + ", " + smafMessage.getDuration() + ":[" + i + "]:" + (i == onLength - 1 ? length % 255 : 255) + "/" + length); } -//Debug.println(channel + ", " + smafMessage.getVoice() + ", " + ((smafMessage.getMessage()[1] & 0xc0) >> 6)); +//logger.log(Level.DEBUG, channel + ", " + smafMessage.getVoice() + ", " + ((smafMessage.getMessage()[1] & 0xc0) >> 6)); smafEvents[i] = new SmafEvent(smafMessage, 0L); // TODO 0l if (smafEvents[i] == null) { - Debug.println(Level.FINE, "[" + i + "]: " + smafEvents[i]); + logger.log(Level.DEBUG, "[" + i + "]: " + smafEvents[i]); } if (i == 0) { context.setBeforeTick(track, midiEvent.getTick()); diff --git a/src/main/java/vavi/sound/smaf/message/OctaveShiftMessage.java b/src/main/java/vavi/sound/smaf/message/OctaveShiftMessage.java index 28fcac6..b6a0f68 100644 --- a/src/main/java/vavi/sound/smaf/message/OctaveShiftMessage.java +++ b/src/main/java/vavi/sound/smaf/message/OctaveShiftMessage.java @@ -39,7 +39,7 @@ public class OctaveShiftMessage extends vavi.sound.smaf.ShortMessage * 0x85 ~ 0xff Reserved * */ - private int octaveShift; + private final int octaveShift; /** * Creates OctaveShiftMessage. diff --git a/src/main/java/vavi/sound/smaf/message/PitchBendMessage.java b/src/main/java/vavi/sound/smaf/message/PitchBendMessage.java index ea322ea..3e7254d 100644 --- a/src/main/java/vavi/sound/smaf/message/PitchBendMessage.java +++ b/src/main/java/vavi/sound/smaf/message/PitchBendMessage.java @@ -39,7 +39,7 @@ public PitchBendMessage(int duration, int channel, int value) { this.duration = duration; this.channel = channel; this.pitchBend = value; -//Debug.println("pitchBend: " + value); +//logger.log(Level.DEBUG, "pitchBend: " + value); } /** for SmafConvertible */ diff --git a/src/main/java/vavi/sound/smaf/message/ProgramChangeMessage.java b/src/main/java/vavi/sound/smaf/message/ProgramChangeMessage.java index d3a2082..370df6d 100644 --- a/src/main/java/vavi/sound/smaf/message/ProgramChangeMessage.java +++ b/src/main/java/vavi/sound/smaf/message/ProgramChangeMessage.java @@ -96,7 +96,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) int midiChannel = context.setProgram(this.channel, this.program); int program = midiChannel == MidiContext.CHANNEL_DRUM ? 0 : context.getProgram(this.channel); -//Debug.println("ProgramChange: [" + duration + "] " + channel + "ch, " + context.getProgram(channel)); +//logger.log(Level.DEBUG, "ProgramChange: [" + duration + "] " + channel + "ch, " + context.getProgram(channel)); if (context.getFormatType() == FormatType.HandyPhoneStandard && context.getDrum(this.channel) == ChannelConfiguration.PERCUSSION && context.getSmafTrackNumber() * 4 + this.channel != MidiContext.CHANNEL_DRUM) { diff --git a/src/main/java/vavi/sound/smaf/message/STMessage.java b/src/main/java/vavi/sound/smaf/message/STMessage.java index 683761f..8c12b7b 100644 --- a/src/main/java/vavi/sound/smaf/message/STMessage.java +++ b/src/main/java/vavi/sound/smaf/message/STMessage.java @@ -7,14 +7,16 @@ package vavi.sound.smaf.message; import java.io.UnsupportedEncodingException; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,6 +29,8 @@ public class STMessage extends SmafMessage implements MidiConvertible { + private static final Logger logger = getLogger(STMessage.class.getName()); + /** */ private String songTitle; @@ -77,7 +81,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce try { data = songTitle.getBytes("Windows-31J"); } catch (UnsupportedEncodingException e) { -Debug.println(e); +logger.log(Level.DEBUG, e); data = songTitle.getBytes(); } MetaMessage metaMessage = new MetaMessage(); diff --git a/src/main/java/vavi/sound/smaf/message/SmafContext.java b/src/main/java/vavi/sound/smaf/message/SmafContext.java index bfec4c5..1758901 100644 --- a/src/main/java/vavi/sound/smaf/message/SmafContext.java +++ b/src/main/java/vavi/sound/smaf/message/SmafContext.java @@ -6,11 +6,11 @@ package vavi.sound.smaf.message; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.Arrays; import java.util.BitSet; import java.util.NoSuchElementException; -import java.util.logging.Level; - import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; import javax.sound.midi.MidiFileFormat; @@ -21,7 +21,8 @@ import vavi.sound.smaf.InvalidSmafDataException; import vavi.sound.smaf.SmafEvent; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -32,6 +33,8 @@ */ public class SmafContext implements SmafConvertible { + private static final Logger logger = getLogger(SmafContext.class.getName()); + /** max SMAF track number */ public static final int MAX_SMAF_TRACKS = 4; @@ -66,7 +69,7 @@ public void setTimeBase(int timeBase) { //---- /** index is SMAF Track No., true if used */ - private boolean[] trackUsed = new boolean[MAX_SMAF_TRACKS]; + private final boolean[] trackUsed = new boolean[MAX_SMAF_TRACKS]; /** * @param smafTrackNumber smaf track number @@ -96,14 +99,14 @@ public double getScale() { /** */ public void setScale(float scale) { -Debug.println(Level.FINE, "scale: " + scale); +logger.log(Level.DEBUG, "scale: " + scale); this.scale = scale; } //---- /** the previous tick, index is SMAF Track No. */ - private long[] beforeTicks = new long[MAX_SMAF_TRACKS]; + private final long[] beforeTicks = new long[MAX_SMAF_TRACKS]; /* init */ { Arrays.fill(beforeTicks, 0); @@ -144,7 +147,7 @@ private int retrieveDelta(int smafTrackNumber, long currentTick) { } /** error rounded with Math#round() */ - private double[] roundedSum = new double[MAX_SMAF_TRACKS]; + private final double[] roundedSum = new double[MAX_SMAF_TRACKS]; /** correction when the sum of rounding errors with Math#round() is larger than 1 */ private int getAdjustedDelta(int smafTrackNumber, double floatDelta) { @@ -152,11 +155,11 @@ private int getAdjustedDelta(int smafTrackNumber, double floatDelta) { double rounded = floatDelta - delta; roundedSum[smafTrackNumber] += rounded; if (roundedSum[smafTrackNumber] >= 1f) { -Debug.println(Level.FINE, "rounded over 1, plus 1: " + roundedSum[smafTrackNumber] + "[" + smafTrackNumber + "]"); +logger.log(Level.DEBUG, "rounded over 1, plus 1: " + roundedSum[smafTrackNumber] + "[" + smafTrackNumber + "]"); delta += 1; roundedSum[smafTrackNumber] -= 1; } else if (roundedSum[smafTrackNumber] <= -1f) { -Debug.println(Level.FINE, "rounded under -1, minus 1: " + roundedSum[smafTrackNumber] + "[" + smafTrackNumber + "]"); +logger.log(Level.DEBUG, "rounded under -1, minus 1: " + roundedSum[smafTrackNumber] + "[" + smafTrackNumber + "]"); delta -= 1; roundedSum[smafTrackNumber] += 1; } @@ -204,24 +207,24 @@ public SmafEvent[] getIntervalSmafEvents() { // tempo track = smafTrackNumber; interval = retrieveDelta(track, midiEvent.getTick()); -Debug.println(Level.FINE, "interval for tempo[" + smafTrackNumber + "]: " + interval); +logger.log(Level.DEBUG, "interval for tempo[" + smafTrackNumber + "]: " + interval); } else if (midiMessage instanceof MetaMessage && ((MetaMessage) midiMessage).getType() == 47) { // eot track = smafTrackNumber; interval = retrieveDelta(track, midiEvent.getTick()); -Debug.println(Level.FINE, "interval for EOT[" + smafTrackNumber + "]: " + interval); +logger.log(Level.DEBUG, "interval for EOT[" + smafTrackNumber + "]: " + interval); } else if (midiMessage instanceof SysexMessage) { return null; } else { -Debug.println(Level.WARNING, "not supported message: " + midiMessage); +logger.log(Level.WARNING, "not supported message: " + midiMessage); return null; } //if (interval > 255) { -// Debug.println("interval: " + interval + ", " + (interval - 256)); +// logger.log(Level.DEBUG, "interval: " + interval + ", " + (interval - 256)); //} if (interval < 0) { // it shouldn't be possible - Debug.println(Level.WARNING, "interval: " + interval); + logger.log(Level.WARNING, "interval: " + interval); interval = 0; } int nopLength = interval / 255; @@ -236,7 +239,7 @@ public SmafEvent[] getIntervalSmafEvents() { incrementBeforeTick(track, 255); } -//Debug.println(nopLength + " nops inserted"); +//logger.log(Level.DEBUG, nopLength + " nops inserted"); return smafEvents; } @@ -258,14 +261,14 @@ public int getDuration() { } else if (midiMessage instanceof MetaMessage && ((MetaMessage) midiMessage).getType() == 81) { // tempo delta = retrieveAdjustedDelta(smafTrackNumber, midiEvent.getTick()); // TODO is smafTrackNumber ok? -Debug.println(Level.FINE, "delta for tempo[" + smafTrackNumber + "]: " + delta); +logger.log(Level.DEBUG, "delta for tempo[" + smafTrackNumber + "]: " + delta); } else { -Debug.println(Level.FINE, "no delta defined for: " + midiMessage); +logger.log(Level.DEBUG, "no delta defined for: " + midiMessage); } if (delta > 255) { // this is impossible because it should be handled by getIntervalSmafEvents - Debug.println(Level.WARNING, "Δ: " + delta + ", " + (delta % 256)); + logger.log(Level.WARNING, "Δ: " + delta + ", " + (delta % 256)); } return delta % 256; } @@ -367,7 +370,7 @@ public MidiEvent getNextMidiEvent() throws NoSuchElementException { if (shortMessage.getChannel() == channel && shortMessage.getCommand() == ShortMessage.NOTE_ON && shortMessage.getData1() != data1) { -Debug.println(Level.FINE, "next: " + shortMessage.getChannel() + "ch, " + shortMessage.getData1()); +logger.log(Level.DEBUG, "next: " + shortMessage.getChannel() + "ch, " + shortMessage.getData1()); return midiEvent; } } @@ -485,7 +488,7 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) rpnMSB[channel] = data2; break; default: -//Debug.println("not implemented: " + data1); +//logger.log(Level.DEBUG, "not implemented: " + data1); break; } diff --git a/src/main/java/vavi/sound/smaf/message/TrackMessage.java b/src/main/java/vavi/sound/smaf/message/TrackMessage.java index c98bea4..88e2fa2 100644 --- a/src/main/java/vavi/sound/smaf/message/TrackMessage.java +++ b/src/main/java/vavi/sound/smaf/message/TrackMessage.java @@ -9,13 +9,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.SmafFileFormat; import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.Track; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -26,11 +28,13 @@ */ public class TrackMessage { + private static final Logger logger = getLogger(TrackMessage.class.getName()); + /** */ - private int trackNumber; + private final int trackNumber; /** */ - private Track track; + private final Track track; /** */ public TrackMessage(int trackNumber, Track track) { @@ -45,7 +49,7 @@ public void writeTo(OutputStream out) throws IOException { dos.writeBytes(getType()); dos.writeInt(getDataLength()); -Debug.println(Level.FINE, "track: " + trackNumber + ": " + getDataLength()); +logger.log(Level.DEBUG, "track: " + trackNumber + ": " + getDataLength()); for (int j = 0; j < track.size(); j++) { SmafEvent event = track.get(j); SmafMessage message = event.getMessage(); diff --git a/src/main/java/vavi/sound/smaf/message/UndefinedMessage.java b/src/main/java/vavi/sound/smaf/message/UndefinedMessage.java index a4a1400..028abe2 100644 --- a/src/main/java/vavi/sound/smaf/message/UndefinedMessage.java +++ b/src/main/java/vavi/sound/smaf/message/UndefinedMessage.java @@ -23,7 +23,7 @@ public class UndefinedMessage extends SmafMessage { */ public UndefinedMessage(int duration) { this.duration = duration; -//Debug.println("UndefinedMessage: ★★★★★★★★★★★★★★★★"); +//logger.log(Level.DEBUG, "UndefinedMessage: ★★★★★★★★★★★★★★★★"); } /** */ diff --git a/src/main/java/vavi/sound/smaf/message/VNMessage.java b/src/main/java/vavi/sound/smaf/message/VNMessage.java index 2a24253..b06f3c6 100644 --- a/src/main/java/vavi/sound/smaf/message/VNMessage.java +++ b/src/main/java/vavi/sound/smaf/message/VNMessage.java @@ -7,14 +7,16 @@ package vavi.sound.smaf.message; import java.io.UnsupportedEncodingException; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; import vavi.sound.midi.MidiConstants.MetaEvent; import vavi.sound.smaf.SmafMessage; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -27,6 +29,8 @@ public class VNMessage extends SmafMessage implements MidiConvertible { + private static final Logger logger = getLogger(VNMessage.class.getName()); + /** */ private String venderName; @@ -77,7 +81,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce try { data = venderName.getBytes("Windows-31J"); } catch (UnsupportedEncodingException e) { -Debug.println(e); +logger.log(Level.DEBUG, e); data = venderName.getBytes(); } MetaMessage metaMessage = new MetaMessage(); diff --git a/src/main/java/vavi/sound/smaf/message/VolumeMessage.java b/src/main/java/vavi/sound/smaf/message/VolumeMessage.java index 12ec329..f3f0c76 100644 --- a/src/main/java/vavi/sound/smaf/message/VolumeMessage.java +++ b/src/main/java/vavi/sound/smaf/message/VolumeMessage.java @@ -9,8 +9,8 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MidiEvent; import javax.sound.midi.ShortMessage; @@ -20,7 +20,8 @@ import vavi.sound.smaf.SmafEvent; import vavi.sound.smaf.chunk.TrackChunk.FormatType; import vavi.sound.smaf.message.MidiContext.ChannelConfiguration; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -38,6 +39,8 @@ public class VolumeMessage extends vavi.sound.smaf.ShortMessage implements MidiConvertible, SmafConvertible { + private static final Logger logger = getLogger(VolumeMessage.class.getName()); + /** smaf channel */ private int channel; @@ -129,7 +132,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) context.getSmafTrackNumber() * 4 + this.channel != MidiContext.CHANNEL_DRUM) { // TODO psm sets the last(maximum?)? volume -Debug.println(Level.FINE, "volume: " + volume); +logger.log(Level.DEBUG, "volume: " + volume); context.setVelocity(this.channel, volume); return null; @@ -162,7 +165,7 @@ public SmafEvent[] getSmafEvents(MidiEvent midiEvent, SmafContext context) smafMessage.setDuration(context.getDuration()); smafMessage.setChannel(voice); smafMessage.setVolume(data2); -Debug.println(Level.FINE, "voice: " + voice + ", volume: " + data2); +logger.log(Level.DEBUG, "voice: " + voice + ", volume: " + data2); context.setBeforeTick(track, midiEvent.getTick()); diff --git a/src/main/java/vavi/sound/smaf/message/WaveDataMessage.java b/src/main/java/vavi/sound/smaf/message/WaveDataMessage.java index 85391d2..9d1d147 100644 --- a/src/main/java/vavi/sound/smaf/message/WaveDataMessage.java +++ b/src/main/java/vavi/sound/smaf/message/WaveDataMessage.java @@ -7,9 +7,9 @@ package vavi.sound.smaf.message; import java.io.Serializable; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.nio.ByteBuffer; -import java.util.logging.Level; - import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -20,7 +20,8 @@ import vavi.sound.smaf.SmafMessage; import vavi.sound.smaf.sequencer.SmafMessageStore; import vavi.sound.smaf.sequencer.WaveSequencer; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -35,18 +36,20 @@ public class WaveDataMessage extends SmafMessage implements WaveSequencer, MidiConvertible, Serializable { + private static final Logger logger = getLogger(WaveDataMessage.class.getName()); + /** */ - private int number; + private final int number; /** */ - private int format; + private final int format; /** */ - private byte[] data; + private final byte[] data; /** */ - private int samplingRate; + private final int samplingRate; /** */ - private int samplingBits; + private final int samplingBits; /** */ - private int channels; + private final int channels; /** */ @@ -115,15 +118,15 @@ public MidiEvent[] getMidiEvents(MidiContext context) /* */ @Override public void sequence() throws InvalidSmafDataException { -Debug.println(Level.FINE, "WAVE DATA[" + number + "]: " + this); +logger.log(Level.DEBUG, "WAVE DATA[" + number + "]: " + this); //try { // java.io.OutputStream os = new java.io.FileOutputStream("out.pcm"); // os.write(data); // os.flush(); // os.close(); -// Debug.println("WAVE DATA saved to out.pcm"); +// logger.log(Level.DEBUG, "WAVE DATA saved to out.pcm"); //} catch (java.io.IOException e) { -// Debug.printStackTrace(e); +// logger.log(Level.ERROR, e.getMessage(), e); //} AudioEngine engine = Factory.getAudioEngine(format); engine.setData(number, -1, samplingRate, samplingBits, channels, data, false); diff --git a/src/main/java/vavi/sound/smaf/message/WaveMessage.java b/src/main/java/vavi/sound/smaf/message/WaveMessage.java index 471e683..83d7432 100644 --- a/src/main/java/vavi/sound/smaf/message/WaveMessage.java +++ b/src/main/java/vavi/sound/smaf/message/WaveMessage.java @@ -10,8 +10,8 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.Serializable; -import java.util.logging.Level; - +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -24,7 +24,8 @@ import vavi.sound.smaf.chunk.TrackChunk.FormatType; import vavi.sound.smaf.sequencer.SmafMessageStore; import vavi.sound.smaf.sequencer.WaveSequencer; -import vavi.util.Debug; + +import static java.lang.System.getLogger; /** @@ -47,14 +48,16 @@ public class WaveMessage extends SmafMessage implements WaveSequencer, MidiConvertible, Serializable { + private static final Logger logger = getLogger(WaveMessage.class.getName()); + /** smaf channel 0 ~ 3 */ - private int channel; + private final int channel; /** */ - private int number; + private final int number; /** */ - private int gateTime; + private final int gateTime; /** * for reading @@ -210,7 +213,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) /* */ @Override public void sequence() throws InvalidSmafDataException { -Debug.println(Level.FINE, "WAVE PLAY: " + number); +logger.log(Level.DEBUG, "WAVE PLAY: " + number); AudioEngine engine = Factory.getAudioEngine(); engine.start(number); } diff --git a/src/main/java/vavi/sound/smaf/message/graphics/BackDropColorDefinitionMessage.java b/src/main/java/vavi/sound/smaf/message/graphics/BackDropColorDefinitionMessage.java index 0bcd030..4fad5ac 100644 --- a/src/main/java/vavi/sound/smaf/message/graphics/BackDropColorDefinitionMessage.java +++ b/src/main/java/vavi/sound/smaf/message/graphics/BackDropColorDefinitionMessage.java @@ -31,7 +31,7 @@ public class BackDropColorDefinitionMessage extends ShortMessage { /** */ - private int backDropColor; + private final int backDropColor; /** * @param duration diff --git a/src/main/java/vavi/sound/smaf/message/graphics/UserMessage.java b/src/main/java/vavi/sound/smaf/message/graphics/UserMessage.java index e17b8ce..ad1fbc1 100644 --- a/src/main/java/vavi/sound/smaf/message/graphics/UserMessage.java +++ b/src/main/java/vavi/sound/smaf/message/graphics/UserMessage.java @@ -31,7 +31,7 @@ public class UserMessage extends ShortMessage { /** */ - private int userEventId; + private final int userEventId; /** * @param duration diff --git a/src/main/java/vavi/sound/smaf/message/yamaha/YamahaMessage.java b/src/main/java/vavi/sound/smaf/message/yamaha/YamahaMessage.java index a7c00d2..2cc6de8 100644 --- a/src/main/java/vavi/sound/smaf/message/yamaha/YamahaMessage.java +++ b/src/main/java/vavi/sound/smaf/message/yamaha/YamahaMessage.java @@ -6,7 +6,8 @@ package vavi.sound.smaf.message.yamaha; -import java.util.logging.Level; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; import javax.sound.midi.MidiEvent; @@ -20,9 +21,10 @@ import vavi.sound.smaf.sequencer.MachineDependentSequencer; import vavi.sound.smaf.sequencer.SmafMessageStore; import vavi.sound.smaf.sequencer.WaveSequencer; -import vavi.util.Debug; import vavi.util.StringUtil; +import static java.lang.System.getLogger; + /** * YamahaMessage. @@ -33,6 +35,8 @@ public class YamahaMessage extends MachineDependentMessage implements MachineDependentSequencer, MidiConvertible { + private static final Logger logger = getLogger(YamahaMessage.class.getName()); + /** * *
  • [MA-3] stream PCM pair @@ -133,7 +137,7 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce // MidiEvent[] events = new MidiEvent[1]; // javax.sound.midi.SysexMessage sysexMessage = new javax.sound.midi.SysexMessage(); -//Debug.println("(" + StringUtil.toHex2(command) + "): " + channel + "ch, " + StringUtil.toHex2(value)); +//logger.log(Level.DEBUG, "(" + StringUtil.toHex2(command) + "): " + channel + "ch, " + StringUtil.toHex2(value)); // byte[] temp = new byte[data.length + 1]; // temp[0] = (byte) 0xf0; // System.arraycopy(data, 0, temp, 1, data.length); @@ -162,20 +166,20 @@ public MidiEvent[] getMidiEvents(MidiContext context) throws InvalidMidiDataExce /* TODO super appropriate right now */ @Override public void sequence() throws InvalidSmafDataException { -Debug.println(Level.INFO, "yamaha: " + data.length + "\n" + StringUtil.getDump(data, 64)); +logger.log(Level.INFO, "yamaha: " + data.length + "\n" + StringUtil.getDump(data, 64)); switch (data[1]) { case 0x79: switch (data[3]) { case 0x7f: switch (data[4]) { case 0x20: { // -Debug.println(Level.FINE, "YAMAHA UNKNOWN: "); +logger.log(Level.DEBUG, "YAMAHA UNKNOWN: "); AudioEngine engine = WaveSequencer.Factory.getAudioEngine(); engine.start(2); break; } case 0x00: { // volume -Debug.println(Level.FINE, "YAMAHA VOLUME: "); +logger.log(Level.DEBUG, "YAMAHA VOLUME: "); AudioEngine engine = WaveSequencer.Factory.getAudioEngine(); engine.start(1); break; diff --git a/src/main/java/vavi/sound/smaf/sequencer/SmafMessageStore.java b/src/main/java/vavi/sound/smaf/sequencer/SmafMessageStore.java index 641c5a3..268a85b 100644 --- a/src/main/java/vavi/sound/smaf/sequencer/SmafMessageStore.java +++ b/src/main/java/vavi/sound/smaf/sequencer/SmafMessageStore.java @@ -27,7 +27,7 @@ public class SmafMessageStore { private static int currentId = 0; /** */ - private static Map stores = new HashMap<>(); + private static final Map stores = new HashMap<>(); private SmafMessageStore() { } diff --git a/src/main/java/vavi/sound/smaf/sequencer/WaveSequencer.java b/src/main/java/vavi/sound/smaf/sequencer/WaveSequencer.java index 7d83f08..30e025d 100644 --- a/src/main/java/vavi/sound/smaf/sequencer/WaveSequencer.java +++ b/src/main/java/vavi/sound/smaf/sequencer/WaveSequencer.java @@ -33,7 +33,7 @@ public interface WaveSequencer { class Factory extends PrefixedClassPropertiesFactory { /** */ - private static ThreadLocal audioEngineStore = new ThreadLocal<>(); + private static final ThreadLocal audioEngineStore = new ThreadLocal<>(); /** * Second time or later. @@ -54,7 +54,7 @@ public static AudioEngine getAudioEngine(int format) { } /** */ - private static Factory instance = new Factory(); + private static final Factory instance = new Factory(); /** */ private Factory() { diff --git a/src/test/java/PlayMFi.java b/src/test/java/PlayMFi.java index 0ff33e6..ba3686e 100644 --- a/src/test/java/PlayMFi.java +++ b/src/test/java/PlayMFi.java @@ -5,14 +5,11 @@ */ import java.io.File; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.concurrent.CountDownLatch; import javax.sound.midi.MidiSystem; import javax.sound.midi.Soundbank; -import org.junit.jupiter.api.BeforeEach; import vavi.sound.mfi.MetaEventListener; import vavi.sound.mfi.MfiSystem; import vavi.sound.mfi.Sequence; diff --git a/src/test/java/SoundFontTest.java b/src/test/java/SoundFontTest.java index abc7714..9238c56 100644 --- a/src/test/java/SoundFontTest.java +++ b/src/test/java/SoundFontTest.java @@ -15,7 +15,6 @@ import javax.sound.midi.Soundbank; import javax.sound.midi.Synthesizer; -import vavi.sound.SoundUtil; import vavi.sound.midi.MidiUtil; import vavi.util.Debug; import vavi.util.properties.annotation.Property; diff --git a/src/test/java/vavi/sound/adpcm/ms/MsInputStreamTest.java b/src/test/java/vavi/sound/adpcm/ms/MsInputStreamTest.java index 0dab566..b6d7a54 100644 --- a/src/test/java/vavi/sound/adpcm/ms/MsInputStreamTest.java +++ b/src/test/java/vavi/sound/adpcm/ms/MsInputStreamTest.java @@ -20,7 +20,6 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; -import javax.sound.sampled.LineEvent; import javax.sound.sampled.SourceDataLine; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/vavi/sound/mfi/vavi/VaviMfiFileWriterTest.java b/src/test/java/vavi/sound/mfi/vavi/VaviMfiFileWriterTest.java index ed14d46..1ce6d4e 100644 --- a/src/test/java/vavi/sound/mfi/vavi/VaviMfiFileWriterTest.java +++ b/src/test/java/vavi/sound/mfi/vavi/VaviMfiFileWriterTest.java @@ -12,13 +12,8 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.NoSuchElementException; import java.util.logging.Level; -import javax.sound.midi.MidiEvent; -import javax.sound.midi.MidiMessage; -import javax.sound.midi.ShortMessage; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -32,7 +27,6 @@ import vavi.sound.mfi.vavi.track.CuePointMessage; import vavi.sound.mfi.vavi.track.EndOfTrackMessage; import vavi.sound.mfi.vavi.track.TempoMessage; -import vavi.sound.midi.MidiUtil; import vavi.util.Debug; import vavi.util.win32.WAVE; @@ -117,7 +111,7 @@ public void test1() throws Exception { /** * @param pcm wave, any sampling rate, 16bit, mono */ - private void d505i(Track track, byte[] pcm, int sampleRate, int delta) + private static void d505i(Track track, byte[] pcm, int sampleRate, int delta) throws InvalidMfiDataException { // adpcm vol diff --git a/src/test/java/vavi/sound/mfi/vavi/sequencer/MachineDependentSequencerTest.java b/src/test/java/vavi/sound/mfi/vavi/sequencer/MachineDependentSequencerTest.java index 62b2a01..2d26a86 100644 --- a/src/test/java/vavi/sound/mfi/vavi/sequencer/MachineDependentSequencerTest.java +++ b/src/test/java/vavi/sound/mfi/vavi/sequencer/MachineDependentSequencerTest.java @@ -12,6 +12,7 @@ import vavi.util.properties.PrefixedClassPropertiesFactory; import vavi.util.properties.PrefixedPropertiesFactory; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -30,21 +31,21 @@ public void test() { MachineDependentSequencer mds = machineDependentSequencerFactory.get(97); Debug.println(mds); - assertTrue(mds instanceof vavi.sound.mfi.vavi.mitsubishi.MitsubishiSequencer); + assertInstanceOf(vavi.sound.mfi.vavi.mitsubishi.MitsubishiSequencer.class, mds); mds = machineDependentSequencerFactory.get(17); - assertTrue(mds instanceof vavi.sound.mfi.vavi.nec.NecSequencer); + assertInstanceOf(vavi.sound.mfi.vavi.nec.NecSequencer.class, mds); mds = machineDependentSequencerFactory.get(33); - assertTrue(mds instanceof vavi.sound.mfi.vavi.fujitsu.FujitsuSequencer); + assertInstanceOf(vavi.sound.mfi.vavi.fujitsu.FujitsuSequencer.class, mds); mds = machineDependentSequencerFactory.get(49); - assertTrue(mds instanceof vavi.sound.mfi.vavi.sony.SonySequencer); + assertInstanceOf(vavi.sound.mfi.vavi.sony.SonySequencer.class, mds); mds = machineDependentSequencerFactory.get(65); - assertTrue(mds instanceof vavi.sound.mfi.vavi.panasonic.PanasonicSequencer); + assertInstanceOf(vavi.sound.mfi.vavi.panasonic.PanasonicSequencer.class, mds); mds = machineDependentSequencerFactory.get(113); - assertTrue(mds instanceof vavi.sound.mfi.vavi.sharp.SharpSequencer); + assertInstanceOf(vavi.sound.mfi.vavi.sharp.SharpSequencer.class, mds); } } diff --git a/src/test/java/vavi/sound/mobile/BasicAudioEngineTest.java b/src/test/java/vavi/sound/mobile/BasicAudioEngineTest.java index a9a5201..8cda5c4 100644 --- a/src/test/java/vavi/sound/mobile/BasicAudioEngineTest.java +++ b/src/test/java/vavi/sound/mobile/BasicAudioEngineTest.java @@ -65,8 +65,8 @@ public void test() throws Exception { /** */ public static class WrappedLineOutputStream extends OutputStream { - SourceDataLine line; - OutputStream out; + final SourceDataLine line; + final OutputStream out; public WrappedLineOutputStream(SourceDataLine line, OutputStream out) { this.out = out; this.line = line; diff --git a/src/test/java/vavi/sound/pcm/resampling/ssrc/SSRCTest.java b/src/test/java/vavi/sound/pcm/resampling/ssrc/SSRCTest.java index f4d72e8..eb691e4 100644 --- a/src/test/java/vavi/sound/pcm/resampling/ssrc/SSRCTest.java +++ b/src/test/java/vavi/sound/pcm/resampling/ssrc/SSRCTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import vavi.io.LittleEndianDataInputStream; @@ -156,7 +155,7 @@ public void test2() throws Exception { } /** */ - private void writeDouble(byte[] buffer, int offset, double value) { + private static void writeDouble(byte[] buffer, int offset, double value) { long l = Double.doubleToLongBits(value); buffer[offset * 8 + 0] = (byte) (l & 0x00000000000000ffL); buffer[offset * 8 + 1] = (byte) ((l & 0x000000000000ff00L) >> 8); diff --git a/src/test/java/vavi/sound/pcm/resampling/ssrc/fftsgTest.java b/src/test/java/vavi/sound/pcm/resampling/ssrc/fftsgTest.java index 921b7c0..aabd555 100644 --- a/src/test/java/vavi/sound/pcm/resampling/ssrc/fftsgTest.java +++ b/src/test/java/vavi/sound/pcm/resampling/ssrc/fftsgTest.java @@ -127,7 +127,7 @@ public void testDFST() throws Exception { } /** */ - private void putData(int nini, int nend, double[] a) { + private static void putData(int nini, int nend, double[] a) { int[] seed = new int[] { 0 }; for (int j = nini; j <= nend; j++) { diff --git a/src/test/java/vavi/sound/sampled/adpcm/ima/ImaWaveAudioFileReaderTest.java b/src/test/java/vavi/sound/sampled/adpcm/ima/ImaWaveAudioFileReaderTest.java index 82f5599..0e30f94 100644 --- a/src/test/java/vavi/sound/sampled/adpcm/ima/ImaWaveAudioFileReaderTest.java +++ b/src/test/java/vavi/sound/sampled/adpcm/ima/ImaWaveAudioFileReaderTest.java @@ -20,7 +20,6 @@ import javax.sound.sampled.SourceDataLine; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import vavi.util.Debug; From 20db8d59b2e566a33a0facfa6c2729df38dd9009 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sat, 22 Jun 2024 05:42:24 +0900 Subject: [PATCH 6/8] update settings --- README.md | 4 +++- pom.xml | 12 ++++++------ src/test/resources/logging.properties | 1 - 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 373d562..7116030 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ A. yes you can, follow those steps * on macos m2 ultra 1st pass is in a blink of an eye * ~~`ima`, `ms` adpcm: wav reader~~ * ~~`tritonus:tritonus-remaining:org.tritonus.sampled.file.WaveAudioFileReader`~~ + * use service provider for mfi, smaf sequencer + * service loader instead of vavi.properties --- -images by melody, cellphone \ No newline at end of file +images by melody, cellphone diff --git a/pom.xml b/pom.xml index 473bae1..02c148b 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ TODO org.codehaus.mojo properties-maven-plugin - 1.1.0 + 1.2.1 read-properties @@ -164,9 +164,9 @@ TODO -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties - -Dvavi.test.dev.null=${dev.null} - -Dvavi.test.volume=${vavi.test.volume} - -Dvavi.test.volume.midi=${vavi.test.volume.midi} + -Dvavi.test.dev.null=@{dev.null} + -Dvavi.test.volume=@{vavi.test.volume} + -Dvavi.test.volume.midi=@{vavi.test.volume.midi} -Dvavi.test.version=${project.version} false @@ -202,7 +202,7 @@ TODO com.github.umjammer vavi-commons - 1.1.12 + 1.1.13 com.github.umjammer @@ -223,7 +223,7 @@ TODO vavi vavi-sound-nda - 1.0.13 + 1.0.14 com.github.umjammer diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties index 3687257..b82ecda 100644 --- a/src/test/resources/logging.properties +++ b/src/test/resources/logging.properties @@ -4,4 +4,3 @@ java.util.logging.ConsoleHandler.level=ALL java.util.logging.ConsoleHandler.formatter=vavi.util.logging.VaviFormatter vavi.util.level=FINE - From 8efca7c244407dd90b3b826a833a1992837297cf Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sat, 22 Jun 2024 05:43:15 +0900 Subject: [PATCH 7/8] bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 02c148b..a0b41ff 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ vavi vavi-sound - 1.0.18 + 1.0.19 Vavi Sound API https://github.com/umjammer/vavi-sound From 8e19bc843075bd1b662c072f2d032bb7070967e3 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Sat, 22 Jun 2024 05:53:53 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=A5=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8f4fabb..a3fca81 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -12,7 +12,7 @@ on: jobs: build: - runs-on: macos-latest + runs-on: macos-13 steps: - name: Checkout repository