-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#314] Draft of cassette player + zx-spectrum-ula fixes
+ emuStudio deps versions update + gradle 8.0.2
- Loading branch information
Showing
40 changed files
with
1,462 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This file is part of emuStudio. | ||
* | ||
* Copyright (C) 2006-2023 Peter Jakubčo | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import org.apache.tools.ant.filters.ReplaceTokens | ||
|
||
plugins { | ||
id 'java' | ||
id 'com.adarshr.test-logger' version '3.1.0' | ||
} | ||
|
||
dependencies { | ||
implementation libs.emuLib | ||
implementation libs.slf4JApi | ||
implementation libs.jcipAnnotations | ||
// cpuLib project(":plugins:cpu:8080-cpu") | ||
|
||
testImplementation libs.junit | ||
testImplementation libs.slf4JSimple | ||
testImplementation libs.easyMock | ||
} | ||
|
||
jar { | ||
archiveVersion = '' | ||
manifest { | ||
attributes manifestAttributes('') | ||
} | ||
} | ||
|
||
processResources { | ||
filesMatching("**/*.properties") { | ||
filter ReplaceTokens, tokens: [ | ||
"project.version": project.version, | ||
"today.year" : new Date().format("yyyy") | ||
] | ||
} | ||
} | ||
|
||
compileJava.options.encoding = 'UTF-8' | ||
compileTestJava.options.encoding = 'UTF-8' | ||
javadoc.options.encoding = 'UTF-8' |
144 changes: 144 additions & 0 deletions
144
...player/src/main/java/net/emustudio/plugins/device/cassette_player/CassetteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* This file is part of emuStudio. | ||
* | ||
* Copyright (C) 2006-2023 Peter Jakubčo | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.emustudio.plugins.device.cassette_player; | ||
|
||
import net.emustudio.plugins.device.cassette_player.loaders.Loader; | ||
import net.jcip.annotations.GuardedBy; | ||
import net.jcip.annotations.ThreadSafe; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@ThreadSafe | ||
public class CassetteController implements AutoCloseable { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(CassetteController.class); | ||
|
||
public enum CassetteState { | ||
UNLOADED, | ||
PLAYING, | ||
STOPPED, | ||
CLOSED | ||
} | ||
|
||
private final Loader.CassetteListener listener; | ||
private final ExecutorService playPool = Executors.newFixedThreadPool(1); | ||
|
||
private final Object stateLock = new Object(); | ||
@GuardedBy("stateLock") | ||
private CassetteState state = CassetteState.UNLOADED; | ||
@GuardedBy("stateLock") | ||
private Loader loader; | ||
@GuardedBy("stateLock") | ||
private Future<?> playFuture; | ||
|
||
public CassetteController(Loader.CassetteListener listener) { | ||
this.listener = Objects.requireNonNull(listener); | ||
} | ||
|
||
public CassetteState reset() { | ||
return stop(true); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
synchronized (stateLock) { | ||
this.state = CassetteState.CLOSED; | ||
Future<?> tmpFuture = this.playFuture; | ||
this.playFuture = null; | ||
if (tmpFuture != null) { | ||
tmpFuture.cancel(true); | ||
} | ||
playPool.shutdown(); | ||
} | ||
try { | ||
if (!playPool.awaitTermination(5, TimeUnit.SECONDS)) { | ||
playPool.shutdownNow(); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
public CassetteState load(Path path) { | ||
Optional<CassetteState> optResult = Loader.create(path).map(tmpLoader -> { | ||
synchronized (stateLock) { | ||
switch (state) { | ||
case UNLOADED: | ||
case STOPPED: | ||
this.loader = tmpLoader; | ||
this.state = CassetteState.STOPPED; | ||
} | ||
return this.state; | ||
} | ||
}); | ||
if (optResult.isPresent()) { | ||
return optResult.get(); | ||
} | ||
synchronized (stateLock) { | ||
return this.state; | ||
} | ||
} | ||
|
||
public CassetteState play() { | ||
synchronized (stateLock) { | ||
if (this.state == CassetteState.STOPPED) { | ||
Loader tmpLoader = this.loader; | ||
if (tmpLoader != null) { | ||
this.state = CassetteState.PLAYING; | ||
this.playFuture = playPool.submit(() -> { | ||
try { | ||
tmpLoader.load(listener); | ||
} catch (IOException e) { | ||
LOGGER.error("Could not load cassette", e); | ||
Thread.currentThread().interrupt(); | ||
} | ||
}); | ||
} | ||
} | ||
return this.state; | ||
} | ||
} | ||
|
||
public CassetteState stop(boolean unload) { | ||
synchronized (stateLock) { | ||
if (this.state == CassetteState.PLAYING) { | ||
Future<?> tmpFuture = this.playFuture; | ||
this.playFuture = null; | ||
if (tmpFuture != null) { | ||
tmpFuture.cancel(true); | ||
} | ||
if (unload) { | ||
this.loader = null; | ||
this.state = CassetteState.UNLOADED; | ||
} else { | ||
this.state = CassetteState.STOPPED; | ||
} | ||
} | ||
return this.state; | ||
} | ||
} | ||
} |
Oops, something went wrong.