Skip to content

Commit

Permalink
Edit Verse waveform updates on theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
darrellcolehill committed May 23, 2024
1 parent e24191e commit 4bcf7b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.wycliffeassociates.otter.jvm.controls.waveform.AudioSlider
import org.wycliffeassociates.otter.jvm.controls.waveform.MarkerPlacementWaveform
import org.wycliffeassociates.otter.jvm.markerapp.app.viewmodel.VerseMarkerViewModel
import org.wycliffeassociates.otter.jvm.utils.ListenerDisposer
import org.wycliffeassociates.otter.jvm.utils.onChangeWithDisposer
import org.wycliffeassociates.otter.jvm.workbookplugin.plugin.PluginCloseRequestEvent
import org.wycliffeassociates.otter.jvm.workbookplugin.plugin.PluginEntrypoint
import tornadofx.*
Expand All @@ -47,7 +48,11 @@ class MarkerView : PluginEntrypoint() {
super.onDock()
viewModel.onDock {
viewModel.compositeDisposable.add(
viewModel.waveform.observeOnFx().subscribe { waveform.addWaveformImage(it) }
viewModel.waveform
.observeOnFx()
.subscribe {
waveform.addWaveformImage(it)
}
)
}
slider?.let {
Expand All @@ -56,8 +61,24 @@ class MarkerView : PluginEntrypoint() {
waveform.markers.bind(viewModel.markers) { it }
waveform.initializeMarkers()
viewModel.cleanupWaveform = waveform::cleanup

subscribeOnThemeChange()
}


private fun subscribeOnThemeChange() {
viewModel.themeColorProperty.onChangeWithDisposer {
viewModel.onThemeChange()
slider?.let {
viewModel.initializeAudioController(it)
}
waveform.markers.bind(viewModel.markers) { it }
waveform.initializeMarkers()

}.apply { disposables.add(this) }
}


init {
tryImportStylesheet(resources["/css/verse-marker-app.css"])
tryImportStylesheet(resources["/css/scrolling-waveform.css"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.wycliffeassociates.otter.common.data.audio.AudioMarker
import org.wycliffeassociates.otter.common.data.audio.BookMarker
import org.wycliffeassociates.otter.common.data.audio.ChapterMarker
import org.wycliffeassociates.otter.common.data.audio.VerseMarker
import org.wycliffeassociates.otter.common.data.getWaveformColors
import org.wycliffeassociates.otter.jvm.controls.model.SECONDS_ON_SCREEN
import org.wycliffeassociates.otter.jvm.workbookplugin.plugin.PluginCloseFinishedEvent
import org.wycliffeassociates.otter.common.domain.model.MarkerItem
Expand All @@ -54,9 +55,6 @@ import org.wycliffeassociates.otter.jvm.controls.waveform.ObservableWaveformBuil
import org.wycliffeassociates.otter.jvm.controls.waveform.WAVEFORM_MAX_HEIGHT
import java.util.regex.Pattern

private const val WAV_COLOR = "#0A337390"
private const val BACKGROUND_COLOR = "#FFFFFF"

class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {

private val logger = LoggerFactory.getLogger(VerseMarkerViewModel::class.java)
Expand Down Expand Up @@ -90,6 +88,7 @@ class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {
val compositeDisposable = CompositeDisposable()
override val positionProperty = SimpleDoubleProperty(0.0)
override var imageWidthProperty = SimpleDoubleProperty()
private val onThemeChangeAction = SimpleObjectProperty<() -> Unit>()

override var resumeAfterScroll = false

Expand All @@ -102,6 +101,7 @@ class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {
}

fun onDock(op: () -> Unit) {
onThemeChangeAction.set(op)
timer?.start()
isLoadingProperty.set(true)
val audio = loadAudio()
Expand All @@ -124,6 +124,18 @@ class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {
)
}


fun onThemeChange() {
val audioFile = loadAudio()
audioFile.let {
pause()
asyncBuilder.cancel()
cleanupWaveform()
createWaveformImages(OratureAudioFile(it.file))
onThemeChangeAction.value.invoke()
}
}

private fun loadAudio(): OratureAudioFile {
val scope = scope as ParameterizedScope
val player = (scope.workspace.params["audioConnectionFactory"] as AudioConnectionFactory).getPlayer()
Expand Down Expand Up @@ -167,7 +179,7 @@ class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {
if (bookSlug == null || chapterNumber == null) return arrayOf()

val chapterNumber = Integer.parseInt(chapterNumber)
return when(chapterNumber) {
return when (chapterNumber) {
1 -> arrayOf(BookMarker(bookSlug, 0), ChapterMarker(chapterNumber, 0))
else -> arrayOf(ChapterMarker(chapterNumber, 0))
}
Expand Down Expand Up @@ -252,21 +264,23 @@ class VerseMarkerViewModel : ViewModel(), IMarkerViewModel {
private fun createWaveformImages(audio: OratureAudioFile) {
imageWidthProperty.set(computeImageWidth(SECONDS_ON_SCREEN))

val waveformColors = getWaveformColors(themeColorProperty.value)

waveform = asyncBuilder.buildAsync(
audio.reader(),
width = imageWidthProperty.value.toInt(),
height = Screen.getMainScreen().platformHeight,
wavColor = Color.web(WAV_COLOR),
background = Color.web(BACKGROUND_COLOR)
wavColor = Color.web(waveformColors.wavColorHex),
background = Color.web(waveformColors.backgroundColorHex)
)

asyncBuilder
.build(
audio.reader(),
width = Screen.getMainScreen().platformWidth,
height = 50,
wavColor = Color.web(WAV_COLOR),
background = Color.web(BACKGROUND_COLOR)
wavColor = Color.web(waveformColors.wavColorHex),
background = Color.web(waveformColors.backgroundColorHex)
)
.observeOnFx()
.map { image ->
Expand Down

0 comments on commit 4bcf7b0

Please sign in to comment.