Skip to content

Commit

Permalink
Provide refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
numq committed Feb 8, 2025
1 parent 2efcf8b commit 9da4cf5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions example/src/main/kotlin/application/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ import com.github.numq.stretch.Stretch
import interaction.InteractionScreen
import playback.PlaybackService

const val APP_NAME = "Stretch"

fun main() {
val pathToBinaries = Thread.currentThread().getContextClassLoader().getResource("bin")?.file

checkNotNull(pathToBinaries) { "Binaries not found" }

Stretch.load(libstretch = "$pathToBinaries\\libstretch.dll").getOrThrow()
Stretch.load(stretch = "$pathToBinaries\\stretch.dll").getOrThrow()

singleWindowApplication(state = WindowState(width = 512.dp, height = 512.dp)) {
singleWindowApplication(state = WindowState(width = 512.dp, height = 512.dp), title = APP_NAME) {
val playbackService = remember { PlaybackService.create().getOrThrow() }

val (throwable, setThrowable) = remember { mutableStateOf<Throwable?>(null) }
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(stretch VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 23)

set(CMAKE_SHARED_LIBRARY_PREFIX "")

add_library(stretch SHARED src/Java_com_github_numq_stretch_NativeStretch.cpp)

find_package(JNI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ Java_com_github_numq_stretch_NativeStretch_processNative(JNIEnv *env, jclass thi
reinterpret_cast<const jbyte *>(outputInterleaved.data()));

return result;

} catch (const std::exception &e) {
handleException(env, e.what());
return nullptr;
Expand Down
6 changes: 3 additions & 3 deletions library/src/main/kotlin/com/github/numq/stretch/Stretch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ interface Stretch : AutoCloseable {
/**
* Loads the native library.
*
* @param libstretch the path to the libstretch library.
* @param stretch the path to the `stretch` binary.
* @return a [Result] indicating the success or failure of the operation.
*/
fun load(libstretch: String) = runCatching {
System.load(libstretch)
fun load(stretch: String) = runCatching {
System.load(stretch)
}.onSuccess {
isLoaded = true
}
Expand Down

0 comments on commit 9da4cf5

Please sign in to comment.