Skip to content

Commit

Permalink
Translation Record with plugin (#1167)
Browse files Browse the repository at this point in the history
* record & record again with ocenaudio

* record individual verse as separate new take

* comment on condition

* update comment

* Merge branch 'dev' into aw-use-external-plugin

* refactor with native plugin check

* Blind Draft record with external plugin

* avoid updating steps/chunks when returning from plugin

* blind draft on dock when returning from plugin

* record with plugin in Peer edit (checkings)

* deactivate loading in Chapter Review when returning from plugin

* force-trigger dock() when new audio is recorded

this only applies to nonempty recording

* handle edge case with navigation after returning from plugin in Checking

* refactor plugin to arguments

* verse text in narration when plugin opened

* add plugin record() API
  • Loading branch information
AnonymousWalker authored Jul 25, 2024
1 parent 7faa564 commit 6f33fde
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class PluginActions @Inject constructor(
}
}

fun record(take: Take, params: PluginParameters): Single<Result> {
return launchPlugin(PluginType.RECORDER, take, params)
.map { it.second }
}

fun import(
audio: AssociatedAudio,
projectAudioDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ class UndoChunkingPageEvent: FXEvent()
class RedoChunkingPageEvent: FXEvent()
class GoToNextChapterEvent: FXEvent()
class GoToPreviousChapterEvent: FXEvent()
class OpenInPluginEvent: FXEvent()
class OpenInPluginEvent: FXEvent()

/**
* Use this event to avoid unwanted refresh of steps or chunk list
* when returning from an external plugin.
*/
class ReturnFromPluginEvent: FXEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import javafx.collections.ObservableList
import javafx.scene.canvas.Canvas
import javafx.scene.canvas.GraphicsContext
import org.slf4j.LoggerFactory
import org.wycliffeassociates.otter.assets.initialization.DEFAULT_RECORDER_NAME
import org.wycliffeassociates.otter.common.audio.AudioFileReader
import org.wycliffeassociates.otter.common.audio.DEFAULT_SAMPLE_RATE
import org.wycliffeassociates.otter.common.data.ColorTheme
Expand Down Expand Up @@ -666,8 +665,9 @@ class NarrationViewModel : ViewModel() {
}

fun recordAgain(verseIndex: Int): NarrationStateTransition? {
val selectedPluginName = audioPluginViewModel.selectedRecorderProperty.value.name
return if (selectedPluginName != DEFAULT_RECORDER_NAME) {
val selectedPlugin = audioPluginViewModel.getPlugin(PluginType.RECORDER)
.blockingGet()
return if (!selectedPlugin.isNativePlugin()) {
openInAudioPlugin(verseIndex)
null
} else {
Expand Down Expand Up @@ -809,8 +809,9 @@ class NarrationViewModel : ViewModel() {
}

fun record(index: Int): NarrationStateTransition? {
val selectedPluginName = audioPluginViewModel.selectedRecorderProperty.value.name
return if (selectedPluginName != DEFAULT_RECORDER_NAME) {
val selectedPlugin = audioPluginViewModel.getPlugin(PluginType.RECORDER)
.blockingGet()
return if (!selectedPlugin.isNativePlugin()) {
openInAudioPlugin(index)
null
} else {
Expand Down Expand Up @@ -902,6 +903,7 @@ class NarrationViewModel : ViewModel() {
.flatMapSingle { plugin ->
pluginOpenedProperty.set(true)
workbookDataStore.activeTakeNumberProperty.set(1)
workbookDataStore.activeChunkProperty.set(chunksList[verseIndex])
FX.eventbus.fire(PluginOpenedEvent(pluginType, plugin.isNativePlugin()))
audioPluginViewModel.edit(file)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.wycliffeassociates.otter.jvm.controls.event.ChunkingStepSelectedEvent
import org.wycliffeassociates.otter.jvm.controls.event.GoToNextChapterEvent
import org.wycliffeassociates.otter.jvm.controls.event.GoToPreviousChapterEvent
import org.wycliffeassociates.otter.jvm.controls.event.NavigateChapterEvent
import org.wycliffeassociates.otter.jvm.controls.event.ReturnFromPluginEvent
import org.wycliffeassociates.otter.jvm.controls.model.ChunkingStep
import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.BlindDraft
import org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation.Chunking
Expand Down Expand Up @@ -150,11 +151,26 @@ class ChunkingTranslationPage : View() {

override fun onDock() {
super.onDock()
viewModel.dockPage()
when (viewModel.pluginOpenedProperty.value) {
true -> {
// returning from plugin
FX.eventbus.fire(ReturnFromPluginEvent())
}
false -> {
viewModel.dockPage()
}
}
}

override fun onUndock() {
super.onUndock()
viewModel.undockPage()
when (viewModel.pluginOpenedProperty.value) {
true -> {
// no-op, opening plugin
}
false -> {
viewModel.undockPage()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.wycliffeassociates.otter.jvm.workbookapp.ui.screens.translation

import com.github.thomasnield.rxkotlinfx.toLazyBinding
import javafx.beans.property.SimpleObjectProperty
import javafx.geometry.Side
import javafx.scene.Node
Expand All @@ -30,6 +31,7 @@ import org.slf4j.LoggerFactory
import org.wycliffeassociates.otter.jvm.controls.Shortcut
import org.wycliffeassociates.otter.jvm.controls.TakeSelectionAnimationMediator
import org.wycliffeassociates.otter.jvm.controls.customizeScrollbarSkin
import org.wycliffeassociates.otter.jvm.controls.dialog.PluginOpenedPage
import org.wycliffeassociates.otter.jvm.controls.media.simpleaudioplayer
import org.wycliffeassociates.otter.jvm.controls.styles.tryImportStylesheet
import org.wycliffeassociates.otter.jvm.workbookapp.ui.components.ChunkTakeCard
Expand All @@ -39,8 +41,11 @@ import org.wycliffeassociates.otter.jvm.controls.event.TakeAction
import org.wycliffeassociates.otter.jvm.controls.event.UndoChunkingPageEvent
import org.wycliffeassociates.otter.jvm.utils.ListenerDisposer
import org.wycliffeassociates.otter.jvm.utils.onChangeWithDisposer
import org.wycliffeassociates.otter.jvm.workbookapp.plugin.PluginOpenedEvent
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.BlindDraftViewModel
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.RecorderViewModel
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.SettingsViewModel
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.TranslationViewModel2
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.WorkbookDataStore
import tornadofx.*

Expand All @@ -50,12 +55,16 @@ class BlindDraft : View() {
val viewModel: BlindDraftViewModel by inject()
val recorderViewModel: RecorderViewModel by inject()
val workbookDataStore: WorkbookDataStore by inject()
val settingsViewModel: SettingsViewModel by inject()
val translationViewModel: TranslationViewModel2 by inject()

private val mainSectionProperty = SimpleObjectProperty<Node>(null)
private val takesView = buildTakesArea()
private val recordingView = buildRecordingArea()
private val hideSourceAudio = mainSectionProperty.booleanBinding { it == recordingView }
private val eventSubscriptions = mutableListOf<EventRegistration>()
private val listenerDisposers = mutableListOf<ListenerDisposer>()
private val pluginOpenedPage = createPluginOpenedPage()

override val root = borderpane {
addClass("blind-draft")
Expand Down Expand Up @@ -131,10 +140,11 @@ class BlindDraft : View() {
graphic = FontIcon(MaterialDesign.MDI_MICROPHONE)

action {
viewModel.onRecordNew()
mainSectionProperty.set(recordingView)
recorderViewModel.onViewReady(takesView.width.toInt()) // use the width of the existing component
recorderViewModel.toggle()
viewModel.onRecordNew {
mainSectionProperty.set(recordingView)
recorderViewModel.onViewReady(takesView.width.toInt()) // use the width of the existing component
recorderViewModel.toggle()
}
}
}
}
Expand Down Expand Up @@ -167,24 +177,64 @@ class BlindDraft : View() {

override fun onDock() {
super.onDock()
logger.info("Blind Draft docked.")
recorderViewModel.waveformCanvas = recordingView.waveformCanvas
recorderViewModel.volumeCanvas = recordingView.volumeCanvas
mainSectionProperty.set(takesView)
viewModel.dockBlindDraft()
when (viewModel.pluginOpenedProperty.value) {
true -> {
// navigate back from plugin
viewModel.pluginOpenedProperty.set(false)
translationViewModel.loadingStepProperty.set(false)
}
false -> {
logger.info("Blind Draft docked.")
viewModel.dockBlindDraft()
}
}
subscribeEvents()
}

override fun onUndock() {
super.onUndock()
logger.info("Blind Draft undocked.")
when (viewModel.pluginOpenedProperty.value) {
true -> {
/* no-op, opening plugin */
}
false -> {
logger.info("Blind Draft undocked.")
viewModel.undockBlindDraft()
}
}
unsubscribeEvents()
viewModel.undockBlindDraft()
if (mainSectionProperty.value == recordingView) {
recorderViewModel.cancel()
}
}

private fun createPluginOpenedPage(): PluginOpenedPage {
return find<PluginOpenedPage>().apply {
licenseProperty.bind(workbookDataStore.sourceLicenseProperty)
sourceTextProperty.bind(workbookDataStore.sourceTextBinding())
sourceContentTitleProperty.bind(workbookDataStore.activeTitleBinding())
orientationProperty.bind(settingsViewModel.orientationProperty)
sourceOrientationProperty.bind(settingsViewModel.sourceOrientationProperty)

sourceSpeedRateProperty.bind(
workbookDataStore.activeWorkbookProperty.select {
it.translation.sourceRate.toLazyBinding()
}
)

targetSpeedRateProperty.bind(
workbookDataStore.activeWorkbookProperty.select {
it.translation.targetRate.toLazyBinding()
}
)

playerProperty.bind(viewModel.sourcePlayerProperty)
}
}

private fun subscribeEvents() {
addShortcut()

Expand Down Expand Up @@ -213,6 +263,12 @@ class BlindDraft : View() {
subscribe<RedoChunkingPageEvent> {
viewModel.redo()
}.also { eventSubscriptions.add(it) }

subscribe<PluginOpenedEvent> { pluginInfo ->
if (!pluginInfo.isNative) {
workspace.dock(pluginOpenedPage)
}
}.let { eventSubscriptions.add(it) }
}

private fun unsubscribeEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import org.wycliffeassociates.otter.jvm.workbookapp.plugin.PluginOpenedEvent
import org.wycliffeassociates.otter.jvm.workbookapp.ui.narration.SnackBarEvent
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.ChapterReviewViewModel
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.SettingsViewModel
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.TranslationViewModel2
import org.wycliffeassociates.otter.jvm.workbookapp.ui.viewmodel.WorkbookDataStore
import tornadofx.*

Expand All @@ -67,6 +68,7 @@ class ChapterReview : View() {
val viewModel: ChapterReviewViewModel by inject()
val settingsViewModel: SettingsViewModel by inject()
private val workbookDataStore: WorkbookDataStore by inject()
private val translationViewModel: TranslationViewModel2 by inject()

private lateinit var waveform: MarkerWaveform
private val audioScrollBar = createAudioScrollBar(
Expand Down Expand Up @@ -203,10 +205,11 @@ class ChapterReview : View() {
when (viewModel.pluginOpenedProperty.value) {
true -> { // navigate back from plugin
viewModel.pluginOpenedProperty.set(false)
translationViewModel.loadingStepProperty.set(false)
viewModel.reloadAudio().subscribe()
}

else -> {
false -> {
logger.info("Final Review docked.")
viewModel.subscribeOnWaveformImagesProperty.set(::subscribeOnWaveformImages)
viewModel.cleanupWaveformProperty.set(waveform::cleanup)
Expand Down
Loading

0 comments on commit 6f33fde

Please sign in to comment.