Skip to content

Commit

Permalink
App: Make transport actions affect correct project tab
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Apr 23, 2024
1 parent b417088 commit fc0abe1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 69 deletions.
75 changes: 39 additions & 36 deletions main/src/infrastructure/proto/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,12 @@ impl MatrixVolumeKind {
#[repr(i32)]
pub enum TriggerInstanceAction {
ShowHelgoboxPlugin = 0,
ArrangementTogglePlayStop = 1,
ArrangementPlay = 2,
ArrangementStop = 3,
ArrangementPause = 4,
ArrangementStartRecording = 5,
ArrangementStopRecording = 6,
}
impl TriggerInstanceAction {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -1634,6 +1640,24 @@ impl TriggerInstanceAction {
TriggerInstanceAction::ShowHelgoboxPlugin => {
"TRIGGER_INSTANCE_ACTION_SHOW_HELGOBOX_PLUGIN"
}
TriggerInstanceAction::ArrangementTogglePlayStop => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_TOGGLE_PLAY_STOP"
}
TriggerInstanceAction::ArrangementPlay => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_PLAY"
}
TriggerInstanceAction::ArrangementStop => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_STOP"
}
TriggerInstanceAction::ArrangementPause => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_PAUSE"
}
TriggerInstanceAction::ArrangementStartRecording => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_START_RECORDING"
}
TriggerInstanceAction::ArrangementStopRecording => {
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_STOP_RECORDING"
}
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -1642,6 +1666,18 @@ impl TriggerInstanceAction {
"TRIGGER_INSTANCE_ACTION_SHOW_HELGOBOX_PLUGIN" => {
Some(Self::ShowHelgoboxPlugin)
}
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_TOGGLE_PLAY_STOP" => {
Some(Self::ArrangementTogglePlayStop)
}
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_PLAY" => Some(Self::ArrangementPlay),
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_STOP" => Some(Self::ArrangementStop),
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_PAUSE" => Some(Self::ArrangementPause),
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_START_RECORDING" => {
Some(Self::ArrangementStartRecording)
}
"TRIGGER_INSTANCE_ACTION_ARRANGEMENT_STOP_RECORDING" => {
Some(Self::ArrangementStopRecording)
}
_ => None,
}
}
Expand Down Expand Up @@ -1832,12 +1868,7 @@ impl TriggerMatrixAction {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum TriggerGlobalAction {
ArrangementTogglePlayStop = 0,
ArrangementPlay = 2,
ArrangementStop = 3,
ArrangementPause = 4,
ArrangementStartRecording = 5,
ArrangementStopRecording = 6,
Placeholder = 0,
}
impl TriggerGlobalAction {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -1846,41 +1877,13 @@ impl TriggerGlobalAction {
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
TriggerGlobalAction::ArrangementTogglePlayStop => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_TOGGLE_PLAY_STOP"
}
TriggerGlobalAction::ArrangementPlay => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_PLAY"
}
TriggerGlobalAction::ArrangementStop => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_STOP"
}
TriggerGlobalAction::ArrangementPause => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_PAUSE"
}
TriggerGlobalAction::ArrangementStartRecording => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_START_RECORDING"
}
TriggerGlobalAction::ArrangementStopRecording => {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_STOP_RECORDING"
}
TriggerGlobalAction::Placeholder => "TRIGGER_GLOBAL_ACTION_PLACEHOLDER",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_TOGGLE_PLAY_STOP" => {
Some(Self::ArrangementTogglePlayStop)
}
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_PLAY" => Some(Self::ArrangementPlay),
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_STOP" => Some(Self::ArrangementStop),
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_PAUSE" => Some(Self::ArrangementPause),
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_START_RECORDING" => {
Some(Self::ArrangementStartRecording)
}
"TRIGGER_GLOBAL_ACTION_ARRANGEMENT_STOP_RECORDING" => {
Some(Self::ArrangementStopRecording)
}
"TRIGGER_GLOBAL_ACTION_PLACEHOLDER" => Some(Self::Placeholder),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/proto/initial_playtime_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn create_initial_matrix_updates(matrix: Option<&Matrix>) -> Vec<OccasionalM
Update::tempo_tap_volume(matrix),
Update::pan(master_track.pan().reaper_value()),
Update::mute(master_track.is_muted()),
Update::tempo(matrix.tempo()),
Update::tempo(matrix),
Update::sequencer_play_state(matrix.sequencer().status()),
Update::complete_persistent_data(matrix),
Update::history_state(matrix),
Expand Down
67 changes: 36 additions & 31 deletions main/src/infrastructure/proto/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::infrastructure::proto::{
use anyhow::Context;
use base::spawn_in_main_thread;
use helgoboss_license_api::persistence::LicenseKey;
use reaper_high::Reaper;
use reaper_high::{OrCurrentProject, Reaper};

use crate::domain::{CompartmentKind, UnitId};
use crate::infrastructure::api::convert::from_data;
Expand Down Expand Up @@ -284,30 +284,8 @@ impl ProtoRequestHandler {
pub fn trigger_global(&self, req: TriggerGlobalRequest) -> Result<Response<Empty>, Status> {
let action = TriggerGlobalAction::try_from(req.action)
.map_err(|_| Status::invalid_argument("unknown trigger global action"))?;
let project = Reaper::get().current_project();
match action {
TriggerGlobalAction::ArrangementTogglePlayStop => {
if project.is_playing() {
project.stop();
} else {
project.play();
}
}
TriggerGlobalAction::ArrangementPlay => {
project.play();
}
TriggerGlobalAction::ArrangementStop => {
project.stop();
}
TriggerGlobalAction::ArrangementPause => {
project.pause();
}
TriggerGlobalAction::ArrangementStartRecording => {
Reaper::get().enable_record_in_current_project();
}
TriggerGlobalAction::ArrangementStopRecording => {
Reaper::get().disable_record_in_current_project();
}
TriggerGlobalAction::Placeholder => {}
}
Ok(Response::new(Empty {}))
}
Expand All @@ -327,14 +305,41 @@ impl ProtoRequestHandler {
pub fn trigger_instance(&self, req: TriggerInstanceRequest) -> Result<Response<Empty>, Status> {
let action = TriggerInstanceAction::try_from(req.action)
.map_err(|_| Status::invalid_argument("unknown trigger instance action"))?;
self.handle_instance_command(req.instance_id, |instance| match action {
TriggerInstanceAction::ShowHelgoboxPlugin => {
instance
.processor_context()
.containing_fx()
.show_in_floating_window();
Ok(())
self.handle_instance_command(req.instance_id, |instance| {
let project = instance.processor_context().project().or_current_project();
match action {
TriggerInstanceAction::ShowHelgoboxPlugin => {
instance
.processor_context()
.containing_fx()
.show_in_floating_window();
}
TriggerInstanceAction::ArrangementTogglePlayStop => {
if project.is_playing() {
project.stop();
} else {
project.play();
}
}
TriggerInstanceAction::ArrangementPlay => {
project.play();
}
TriggerInstanceAction::ArrangementStop => {
project.stop();
}
TriggerInstanceAction::ArrangementPause => {
project.pause();
}
TriggerInstanceAction::ArrangementStartRecording => {
// Recording not supported per project
Reaper::get().enable_record_in_current_project();
}
TriggerInstanceAction::ArrangementStopRecording => {
// Recording not supported per project
Reaper::get().disable_record_in_current_project();
}
}
Ok(())
})
}

Expand Down
2 changes: 1 addition & 1 deletion playtime-clip-engine

0 comments on commit fc0abe1

Please sign in to comment.