Skip to content

Commit

Permalink
Make things build again without Playtime
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Nov 1, 2023
1 parent d0f6fdf commit 98d0974
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 29 deletions.
2 changes: 2 additions & 0 deletions main/src/base/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn notify_user_on_error(result: Result<(), Box<dyn Error>>) {
}
}

#[allow(dead_code)]
pub fn notify_user_on_anyhow_error(result: anyhow::Result<()>) {
if let Err(e) = result {
notify_user_about_anyhow_error(e);
Expand All @@ -43,6 +44,7 @@ pub fn notify_user_about_error(e: Box<dyn Error>) {
alert(e.to_string());
}

#[allow(dead_code)]
pub fn notify_user_about_anyhow_error(e: anyhow::Error) {
alert(e.to_string());
}
Expand Down
2 changes: 2 additions & 0 deletions main/src/domain/audio_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl RealearnAudioHook {
.on_post(block_props.to_playtime(), args.reg);
}
// Record some metrics
let _ = args;
if let Some(time_of_last_run) = self.time_of_last_run {
record_duration("audio_callback_total", time_of_last_run.elapsed());
}
Expand Down Expand Up @@ -370,6 +371,7 @@ impl RealearnAudioHook {
}
}
}
let _ = block_props;
}
}

Expand Down
3 changes: 1 addition & 2 deletions main/src/domain/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::domain::{
VirtualMappingSnapshotIdForLoad,
};
use base::{NamedChannelSender, SenderToNormalThread};
use playtime_clip_engine::base::ClipMatrixEvent;
use pot::{CurrentPreset, OptFilter, PotFavorites, PotFilterExcludes, PotIntegration};
use pot::{PotUnit, PresetId, SharedRuntimePotUnit};
use realearn_api::persistence::PotFilterKind;
Expand Down Expand Up @@ -429,7 +428,7 @@ impl InstanceState {
self.clip_matrix_event_sender
.send_complaining(QualifiedClipMatrixEvent {
instance_id: self.instance_id,
event: ClipMatrixEvent::EverythingChanged,
event: playtime_clip_engine::base::ClipMatrixEvent::EverythingChanged,
});
true
}
Expand Down
2 changes: 2 additions & 0 deletions main/src/infrastructure/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub use osc_device_management::*;
mod virtual_control;
pub use virtual_control::*;

#[cfg(feature = "playtime")]
mod license_management;
#[cfg(feature = "playtime")]
pub use license_management::*;

#[cfg(feature = "playtime")]
Expand Down
47 changes: 29 additions & 18 deletions main/src/infrastructure/plugin/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ use crate::domain::{
};
use crate::infrastructure::data::{
ExtendedPresetManager, FileBasedControllerPresetManager, FileBasedMainPresetManager,
FileBasedPresetLinkManager, LicenseManager, OscDevice, OscDeviceManager,
SharedControllerPresetManager, SharedLicenseManager, SharedMainPresetManager,
SharedOscDeviceManager, SharedPresetLinkManager,
FileBasedPresetLinkManager, OscDevice, OscDeviceManager, SharedControllerPresetManager,
SharedMainPresetManager, SharedOscDeviceManager, SharedPresetLinkManager,
};
use crate::infrastructure::plugin::debug_util;
use crate::infrastructure::server;
use crate::infrastructure::server::{
MetricsReporter, RealearnServer, SharedRealearnServer, COMPANION_WEB_APP_URL,
};
use crate::infrastructure::ui::{AppLibrary, MainPanel, MessagePanel};
use crate::infrastructure::ui::{MainPanel, MessagePanel};
use base::default_util::is_default;
use base::{
make_available_globally_in_main_thread, metrics_util, Global, NamedChannelSender,
Expand All @@ -39,7 +38,6 @@ use crate::infrastructure::plugin::allocator::{
};
use crate::infrastructure::plugin::tracing_util::setup_tracing;
use crate::infrastructure::server::services::RealearnServices;
use anyhow::{anyhow, Context};
use once_cell::sync::Lazy;
use realearn_api::persistence::{
Envelope, FxChainDescriptor, FxDescriptor, TargetTouchCause, TrackDescriptor, TrackFxChain,
Expand Down Expand Up @@ -96,7 +94,8 @@ pub type RealearnControlSurface =
#[derive(Debug)]
pub struct App {
state: RefCell<AppState>,
license_manager: SharedLicenseManager,
#[cfg(feature = "playtime")]
license_manager: crate::infrastructure::data::SharedLicenseManager,
controller_preset_manager: SharedControllerPresetManager,
main_preset_manager: SharedMainPresetManager,
preset_link_manager: SharedPresetLinkManager,
Expand Down Expand Up @@ -260,9 +259,12 @@ impl App {
};
App {
state: RefCell::new(AppState::Uninitialized(uninitialized_state)),
license_manager: Rc::new(RefCell::new(LicenseManager::new(
App::helgoboss_resource_dir_path().join("licensing.json"),
))),
#[cfg(feature = "playtime")]
license_manager: Rc::new(RefCell::new(
crate::infrastructure::data::LicenseManager::new(
App::helgoboss_resource_dir_path().join("licensing.json"),
),
)),
controller_preset_manager: Rc::new(RefCell::new(
FileBasedControllerPresetManager::new(
App::realearn_preset_dir_path().join("controller"),
Expand Down Expand Up @@ -791,6 +793,7 @@ impl App {
Reaper::get().resource_path().join("Helgoboss")
}

#[cfg(feature = "playtime")]
pub fn app_base_dir_path() -> PathBuf {
App::helgoboss_resource_dir_path().join("App")
}
Expand All @@ -805,6 +808,7 @@ impl App {
.join("Data/helgoboss/realearn")
}

#[cfg(feature = "playtime")]
pub fn app_archive_file_path() -> PathBuf {
Reaper::get()
.resource_path()
Expand Down Expand Up @@ -865,9 +869,20 @@ impl App {
&APP_LOGGER
}

pub fn get_or_load_app_library() -> anyhow::Result<&'static AppLibrary> {
#[cfg(feature = "playtime")]
pub fn get_or_load_app_library(
) -> anyhow::Result<&'static crate::infrastructure::ui::AppLibrary> {
use crate::infrastructure::ui::AppLibrary;
fn load_app_library() -> anyhow::Result<AppLibrary> {
let app_archive_file = App::app_archive_file_path();
let app_base_dir = App::app_base_dir_path();
decompress_app(&app_archive_file, &app_base_dir)?;
AppLibrary::load(app_base_dir)
}
static APP_LIBRARY: Lazy<anyhow::Result<AppLibrary>> = Lazy::new(load_app_library);
APP_LIBRARY.as_ref().map_err(|e| anyhow!(e.to_string()))
APP_LIBRARY
.as_ref()
.map_err(|e| anyhow::anyhow!(e.to_string()))
}

pub fn sessions_changed(&self) -> impl LocalObservable<'static, Item = (), Err = ()> + 'static {
Expand All @@ -887,6 +902,7 @@ impl App {
})
}

#[allow(dead_code)]
pub fn find_main_panel_by_session_id(&self, session_id: &str) -> Option<SharedView<MainPanel>> {
self.instances.borrow().iter().find_map(|i| {
if i.session.upgrade()?.borrow().id() == session_id {
Expand Down Expand Up @@ -1921,14 +1937,9 @@ impl RealearnWindowSnitch for RealearnSnitch {
}
}

fn load_app_library() -> anyhow::Result<AppLibrary> {
let app_archive_file = App::app_archive_file_path();
let app_base_dir = App::app_base_dir_path();
decompress_app(&app_archive_file, &app_base_dir)?;
AppLibrary::load(app_base_dir)
}

#[cfg(feature = "playtime")]
fn decompress_app(archive_file: &Path, destination_dir: &Path) -> anyhow::Result<()> {
use anyhow::Context;
let archive_file =
fs::File::open(archive_file).context("Couldn't open app archive file. Maybe you installed ReaLearn manually (without ReaPack) and forgot to add the app archive?")?;
let tar = zstd::Decoder::new(&archive_file).context("Couldn't decode app archive file.")?;
Expand Down
9 changes: 9 additions & 0 deletions main/src/infrastructure/ui/header_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl HeaderPanel {
let main_preset_manager = main_preset_manager.borrow();
let text_from_clipboard = Rc::new(get_text_from_clipboard().unwrap_or_default());
let text_from_clipboard_clone = text_from_clipboard.clone();
#[cfg(feature = "playtime")]
let app_is_open = self.panel_manager().borrow().app_panel_is_open();
let data_object_from_clipboard = if text_from_clipboard.is_empty() {
None
Expand Down Expand Up @@ -586,7 +587,9 @@ impl HeaderPanel {
MainMenuAction::ReloadAllPresets
}),
item("Open Pot Browser", || MainMenuAction::OpenPotBrowser),
#[cfg(feature = "playtime")]
item("Show App", || MainMenuAction::ShowApp),
#[cfg(feature = "playtime")]
item_with_opts(
"Close App",
ItemOpts {
Expand Down Expand Up @@ -759,9 +762,11 @@ impl HeaderPanel {
MainMenuAction::OpenPotBrowser => {
self.show_pot_browser();
}
#[cfg(feature = "playtime")]
MainMenuAction::ShowApp => {
self.show_app();
}
#[cfg(feature = "playtime")]
MainMenuAction::CloseApp => {
self.close_app();
}
Expand Down Expand Up @@ -2294,10 +2299,12 @@ impl HeaderPanel {
Ok(())
}

#[cfg(feature = "playtime")]
fn show_app(&self) {
self.panel_manager().borrow().show_app_panel();
}

#[cfg(feature = "playtime")]
fn close_app(&self) {
self.panel_manager().borrow().close_app_panel();
}
Expand Down Expand Up @@ -3013,7 +3020,9 @@ enum MainMenuAction {
LinkToPreset(PresetLinkScope, FxId, String),
ReloadAllPresets,
OpenPotBrowser,
#[cfg(feature = "playtime")]
ShowApp,
#[cfg(feature = "playtime")]
CloseApp,
OpenPresetFolder,
EditNewOscDevice,
Expand Down
18 changes: 12 additions & 6 deletions main/src/infrastructure/ui/independent_panel_manager.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::infrastructure::ui::{AppPanel, MainPanel, MappingPanel, SessionMessagePanel};
use crate::infrastructure::ui::{MainPanel, MappingPanel, SessionMessagePanel};
use reaper_high::Reaper;
use slog::debug;

use crate::application::{Affected, Session, SessionProp, SharedMapping, WeakSession};
use crate::base::notification;
use crate::domain::{
Compartment, MappingId, MappingMatchedEvent, TargetControlEvent, TargetValueChangedEvent,
};
use crate::infrastructure::plugin::App;
use swell_ui::{SharedView, View, WeakView, Window};

const MAX_PANEL_COUNT: u32 = 4;
Expand All @@ -20,7 +18,8 @@ pub struct IndependentPanelManager {
mapping_panels: Vec<SharedView<MappingPanel>>,
message_panel: SharedView<SessionMessagePanel>,
/// We have at most one app instance open per ReaLearn instance.
app_panel: SharedView<AppPanel>,
#[cfg(feature = "playtime")]
app_panel: SharedView<crate::infrastructure::ui::AppPanel>,
}

impl IndependentPanelManager {
Expand All @@ -30,7 +29,8 @@ impl IndependentPanelManager {
main_panel,
mapping_panels: Default::default(),
message_panel: SharedView::new(SessionMessagePanel::new(session.clone())),
app_panel: SharedView::new(AppPanel::new(session)),
#[cfg(feature = "playtime")]
app_panel: SharedView::new(crate::infrastructure::ui::AppPanel::new(session)),
}
}

Expand All @@ -46,7 +46,8 @@ impl IndependentPanelManager {
});
}

pub fn app_panel(&self) -> &SharedView<AppPanel> {
#[cfg(feature = "playtime")]
pub fn app_panel(&self) -> &SharedView<crate::infrastructure::ui::AppPanel> {
&self.app_panel
}

Expand Down Expand Up @@ -97,19 +98,23 @@ impl IndependentPanelManager {
self.message_panel.clone().open(reaper_main_window());
}

#[cfg(feature = "playtime")]
pub fn show_app_panel(&self) {
let result = self.show_app_panel_internal();
notification::notify_user_on_anyhow_error(result);
}

#[cfg(feature = "playtime")]
pub fn close_app_panel(&self) {
self.app_panel.clone().close();
}

#[cfg(feature = "playtime")]
pub fn app_panel_is_open(&self) -> bool {
self.app_panel.is_open()
}

#[cfg(feature = "playtime")]
fn show_app_panel_internal(&self) -> anyhow::Result<()> {
if let Some(window) = self.app_panel.view_context().window() {
// If window already open (and maybe just hidden), simply show it.
Expand Down Expand Up @@ -162,6 +167,7 @@ impl IndependentPanelManager {
p.close()
}
self.mapping_panels.clear();
#[cfg(feature = "playtime")]
self.app_panel.close();
}

Expand Down
6 changes: 3 additions & 3 deletions main/src/infrastructure/ui/main_panel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::infrastructure::ui::{
bindings::root, util, AppPanel, HeaderPanel, IndependentPanelManager, MappingRowsPanel,
bindings::root, util, HeaderPanel, IndependentPanelManager, MappingRowsPanel,
SharedIndependentPanelManager, SharedMainState,
};

Expand All @@ -23,7 +23,6 @@ use crate::infrastructure::server::http::{
send_projection_feedback_to_subscribed_clients, send_updated_controller_routing,
};
use crate::infrastructure::ui::util::{header_panel_height, parse_tags_from_csv};
use anyhow::anyhow;
use base::SoundPlayer;
use rxrust::prelude::*;
use std::rc::{Rc, Weak};
Expand Down Expand Up @@ -293,7 +292,8 @@ impl MainPanel {
}
}

pub fn app_panel(&self) -> anyhow::Result<SharedView<AppPanel>> {
#[cfg(feature = "playtime")]
pub fn app_panel(&self) -> anyhow::Result<SharedView<crate::infrastructure::ui::AppPanel>> {
let activate_data = self
.active_data
.borrow()
Expand Down
2 changes: 2 additions & 0 deletions main/src/infrastructure/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ mod advanced_script_editor_panel;
#[cfg(feature = "egui")]
pub use advanced_script_editor_panel::*;

#[cfg(feature = "playtime")]
mod app;
#[cfg(feature = "playtime")]
pub use app::*;

#[cfg(feature = "egui")]
Expand Down

0 comments on commit 98d0974

Please sign in to comment.