Skip to content

Commit

Permalink
Merge pull request #22 from umjammer/1.0.10
Browse files Browse the repository at this point in the history
1.0.10
  • Loading branch information
umjammer authored Jan 13, 2025
2 parents a820487 + 86259ed commit bd170d2
Show file tree
Hide file tree
Showing 140 changed files with 3,323 additions and 1,164 deletions.
90 changes: 49 additions & 41 deletions README.md

Large diffs are not rendered by default.

100 changes: 91 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-sound-sandbox</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>

<name>Vavi Sound API (Sandbox)</name>
<url>https://github.com/umjammer/vavi-sound-sandbox</url>
Expand Down Expand Up @@ -92,6 +92,86 @@
</plugins>
</build>
</profile>

<profile>
<id>local (not on ci)</id>
<activation>
<property>
<name>!env.GITHUB_WORKFLOW</name>
</property>
</activation>
<properties>
<javaVersion>21</javaVersion>
</properties>
<pluginRepositories>
<pluginRepository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>com.github.umjammer</groupId>
<artifactId>careless-maven-plugin</artifactId>
<version>0.0.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>careless</goal>
</goals>
</execution>
</executions>
<configuration>
<targets>
<target>
<path>.github/workflows/codeql-analysis.yml</path>
<ri>jobs.analyze.steps[2].name</ri>
<value>Set up JDK ${javaVersion}</value>
</target>
<target>
<path>.github/workflows/codeql-analysis.yml</path>
<ri>jobs.analyze.steps[2].with.java-version</ri>
<value>${javaVersion}</value>
</target>
<target>
<path>.github/workflows/maven.yml</path>
<ri>jobs.build.steps[2].name</ri>
<value>Set up JDK ${javaVersion}</value>
</target>
<target>
<path>.github/workflows/maven.yml</path>
<ri>jobs.build.steps[2].with.java-version</ri>
<value>${javaVersion}</value>
</target>
<target>
<path>pom.xml</path>
<ri>//*[local-name()='artifactId' and text()='maven-compiler-plugin']/..//*[local-name()='release' or local-name()='source']/text()</ri>
<value>${javaVersion}</value>
</target>
<target>
<path>jitpack.yml</path>
<ri>jdk[0]</ri>
<value>openjdk${javaVersion}</value>
</target>
<target>
<path>README.md</path>
<ri>img\.shields\.io\/badge\/Java-(\d+?)-b07219</ri>
<value>${javaVersion}</value>
</target>
<target>
<path>pom.xml</path>
<ri>//*[local-name()='project']/*[local-name()='version']/text()</ri>
<value>.*-SNAPSHOT</value>
<negative>true</negative>
</target>
</targets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
Expand All @@ -104,9 +184,10 @@
<source>21</source> <!-- TODO release causes compilation failure why? -->
<target>21</target>
<compilerArgs>
<arg>--add-modules=jdk.incubator.vector</arg>
<arg>--add-exports</arg>
<arg>java.desktop/com.sun.media.sound=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.base/sun.nio.ch=ALL-UNNAMED</arg>
</compilerArgs>
<!-- https://stackoverflow.com/a/30472473 -->
<fork>true</fork>
Expand Down Expand Up @@ -155,8 +236,9 @@
<configuration>
<argLine>
-Xmx4G
--add-modules jdk.incubator.vector
--add-exports java.desktop/com.sun.media.sound=ALL-UNNAMED
--add-exports=java.desktop/com.sun.media.sound=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
-javaagent:${project.build.directory}/vavi-instrumentation.jar
-Dvavix.lang.instrumentation.VaviInstrumentation.1=vavix.lang.instrumentation.PropertiesClassFileTransformer
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
Expand Down Expand Up @@ -255,7 +337,7 @@
<dependency>
<groupId>com.github.umjammer</groupId> <!-- vavi / com.github.umjammer -->
<artifactId>vavi-sound</artifactId>
<version>1.0.19</version>
<version>1.0.20</version>
<exclusions>
<exclusion>
<groupId>com.github.umjammer</groupId>
Expand Down Expand Up @@ -372,7 +454,7 @@
<dependency>
<groupId>com.github.umjammer</groupId> <!-- drogatkin / com.github.umjammer -->
<artifactId>vavi-sound-flac</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -448,9 +530,9 @@
</dependency>

<dependency>
<groupId>com.github.umjammer</groupId> <!-- com.github.umjammer -->
<groupId>com.github.umjammer</groupId> <!-- com.github.umjammer / vavi -->
<artifactId>vavi-util-screenscraping</artifactId>
<version>1.0.14</version>
<version>1.0.15</version>
<scope>test</scope>
</dependency>

Expand All @@ -464,7 +546,7 @@
<dependency>
<groupId>com.github.umjammer.vavi-commons</groupId>
<artifactId>vavi-instrumentation</artifactId>
<version>1.1.12</version>
<version>1.1.14</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/jp/or/rim/kt/kemusiro/sound/ChangeInstrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,55 @@

package jp.or.rim.kt.kemusiro.sound;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.ShortMessage;

import vavi.util.Debug;


/**
* A class that represents an event that changes the tone.
*
* @author Kenichi Miyata (kemusiro&#x40;kt.rim.or.jp)
* @version $Revision: 1.2 $
*/
public class ChangeInstrument extends MusicEvent {
public class ChangeInstrument extends MusicEvent implements MidiConvertible {

private final Instrument instrument;

/**
* Creates an event to change the tone.
*
* @param newTick tick
* @param newChannel channel number
* @param newInstrument new tone
* @param tick tick
* @param channel channel number
* @param instrument new tone
*/
public ChangeInstrument(int newTick, int newChannel, Instrument newInstrument) {
tick = newTick;
channel = newChannel;
instrument = newInstrument;
public ChangeInstrument(int tick, int channel, Instrument instrument) {
this.tick = tick;
this.channel = channel;
this.instrument = instrument;
Debug.println("tick: " + tick + ", channel: " + channel + ", instrument: " + instrument);
}

public Instrument getInstrument() {
return instrument;
}

@Override
public String toString() {
return "Change Instrument " + instrument.toString();
return "Change Instrument " + instrument;
}

@Override
public MidiEvent[] convert(MidiContext context) throws InvalidMidiDataException {
ShortMessage shortMessage = new ShortMessage();
shortMessage.setMessage(ShortMessage.PROGRAM_CHANGE,
channel % 16,
context.getBank(instrument),
context.getProgram(instrument));
return new MidiEvent[] {
new MidiEvent(shortMessage, tick)
};
}
}
36 changes: 31 additions & 5 deletions src/main/java/jp/or/rim/kt/kemusiro/sound/ChangeTempo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,52 @@

package jp.or.rim.kt.kemusiro.sound;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;

import vavi.sound.midi.MidiConstants.MetaEvent;


/**
* A class that represents an event that changes the tempo.
*
* @author Kenichi Miyata (kemusiro&#x40;kt.rim.or.jp)
* @version $Revision: 1.2 $
*/
public class ChangeTempo extends MusicEvent {
public class ChangeTempo extends MusicEvent implements MidiConvertible {

private final int tempo;

public ChangeTempo(int newTick, int newChannel, int newTempo) {
tick = newTick;
channel = newChannel;
tempo = newTempo;
public ChangeTempo(int tick, int channel, int tempo) {
this.tick = tick;
this.channel = channel;
this.tempo = tempo;
}

public int getTempo() {
return tempo;
}

@Override
public String toString() {
return "Change Tempo " + tempo;
}

@Override
public MidiEvent[] convert(MidiContext context) throws InvalidMidiDataException {
int tempo = context.getMidiTempo(this.tempo);
MetaMessage metaMessage = new MetaMessage();
metaMessage.setMessage(
MetaEvent.META_TEMPO.number(),
new byte[] {
(byte) ((tempo / 0x10000) & 0xff),
(byte) (((tempo % 0x10000) / 0x100) & 0xff),
(byte) ((tempo % 0x100) & 0xff)
},
3);
return new MidiEvent[] {
new MidiEvent(metaMessage, tick)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package jp.or.rim.kt.kemusiro.sound;

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.Clip;
Expand All @@ -12,6 +14,8 @@

import vavi.util.Debug;

import static java.lang.System.getLogger;


/**
* Play with the already created byte array.
Expand All @@ -21,6 +25,8 @@
*/
public class ClipSoundPlayer extends SoundPlayer {

private static final Logger logger = getLogger(ClipSoundPlayer.class.getName());

private Clip line = null;

/**
Expand All @@ -38,7 +44,7 @@ public ClipSoundPlayer(int rate, int depth, byte[] array) {
line = (Clip) AudioSystem.getLine(info);
line.open(format, array, 0, array.length);
} catch (LineUnavailableException e) {
Debug.printStackTrace(e);
logger.log(Level.ERROR, e.getMessage(), e);
}
}

Expand Down
25 changes: 22 additions & 3 deletions src/main/java/jp/or/rim/kt/kemusiro/sound/FMGeneralInstrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ public class FMGeneralInstrument extends Instrument {

private static final List<FMParameter> parameters = new ArrayList<>();

public static int[] getToneNumbers() {
return parameters.stream().mapToInt(FMParameter::getToneNumber).toArray();
}

public FMGeneralInstrument(int number) {
FMParameter p = findParameter(number);
if (p == null) {
throw new RuntimeException("can't find tone number: " + number);
throw new IllegalArgumentException("can't find tone number: " + number);
} else {
switch (p.getAlgorithm()) {
case 0:
Expand Down Expand Up @@ -66,7 +70,7 @@ public FMGeneralInstrument(int number) {
wave = new FMAlgorithm7(p);
break;
default:
throw new RuntimeException("invalid algorithm number");
throw new IllegalStateException("invalid algorithm number: " + p.getToneNumber());
}
}
envelope = new DummyEnvelope();
Expand All @@ -82,13 +86,28 @@ private static FMParameter findParameter(int number) {
}

public static void readParameterByResource() throws IOException {
InputStream is = FMGeneralInstrument.class.getResourceAsStream("/fmparameters.txt");
InputStream is = FMGeneralInstrument.class.getResourceAsStream("fmparameters.txt");
if (is == null) {
throw new IOException("no fmparameters.txt in classpath");
}
readParameter(new InputStreamReader(is));
}

/**
* <pre>
* toneNumber
* algorithm
* Op ---- x4
* mul
* att
* dec
* sus
* rel
* max
* ----
* </pre>
* 30 lines x2
*/
public static void readParameter(Reader reader) throws IOException {
try (BufferedReader in = new BufferedReader(reader)) {
String line;
Expand Down
Loading

0 comments on commit bd170d2

Please sign in to comment.