| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
#![allow(clippy::needless_pass_by_value)] |
| 114 |
|
| 115 |
pub mod bulk; |
| 116 |
pub mod detail; |
| 117 |
pub mod edit; |
| 118 |
pub mod export; |
| 119 |
pub mod files; |
| 120 |
pub mod filters; |
| 121 |
pub mod forge; |
| 122 |
pub mod help; |
| 123 |
pub mod importing; |
| 124 |
pub mod integrity; |
| 125 |
pub mod library; |
| 126 |
pub mod naming; |
| 127 |
pub mod panel; |
| 128 |
pub mod queue; |
| 129 |
pub mod settings; |
| 130 |
pub mod shell; |
| 131 |
pub mod sync; |
| 132 |
pub mod toolbar; |
| 133 |
|
| 134 |
use audiofiles_core::config_key::ConfigKey; |
| 135 |
use quasi_router::Router; |
| 136 |
|
| 137 |
use crate::backend::Backend; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
pub trait Config { |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
fn get(&self, key: ConfigKey) -> Result<Option<String>, String>; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
fn set(&self, key: ConfigKey, value: &str) -> Result<(), String>; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
pub struct FromBackend<'a>(pub &'a dyn Backend); |
| 177 |
|
| 178 |
impl Config for FromBackend<'_> { |
| 179 |
fn get(&self, key: ConfigKey) -> Result<Option<String>, String> { |
| 180 |
self.0.get_config(key).map_err(|error| error.to_string()) |
| 181 |
} |
| 182 |
|
| 183 |
fn set(&self, key: ConfigKey, value: &str) -> Result<(), String> { |
| 184 |
self.0 |
| 185 |
.set_config(key, value) |
| 186 |
.map_err(|error| error.to_string()) |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 197 |
pub struct Status { |
| 198 |
|
| 199 |
pub state: State, |
| 200 |
|
| 201 |
pub last_sync_at: Option<String>, |
| 202 |
|
| 203 |
pub pending_changes: i64, |
| 204 |
|
| 205 |
pub last_error: Option<String>, |
| 206 |
|
| 207 |
pub auto_sync_enabled: bool, |
| 208 |
|
| 209 |
pub sync_interval_minutes: u32, |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 218 |
pub enum State { |
| 219 |
|
| 220 |
Disconnected, |
| 221 |
|
| 222 |
Authenticating, |
| 223 |
|
| 224 |
NeedsEncryption { |
| 225 |
|
| 226 |
|
| 227 |
has_server_key: bool, |
| 228 |
}, |
| 229 |
|
| 230 |
Ready, |
| 231 |
|
| 232 |
Syncing, |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 237 |
pub struct Subscription { |
| 238 |
|
| 239 |
pub active: bool, |
| 240 |
|
| 241 |
pub limit_bytes: i64, |
| 242 |
|
| 243 |
pub used_bytes: i64, |
| 244 |
|
| 245 |
pub interval: String, |
| 246 |
|
| 247 |
pub pending_limit_bytes: Option<i64>, |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
pub struct Pricing { |
| 257 |
|
| 258 |
pub min_bytes: i64, |
| 259 |
|
| 260 |
pub max_bytes: i64, |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
pub trait Sync { |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
fn available(&self) -> bool { |
| 287 |
true |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
fn status(&self) -> Status; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
fn connect(&self) -> Result<String, String>; |
| 298 |
|
| 299 |
|
| 300 |
fn cancel(&self); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
fn set_password(&self, password: &str, is_new: bool); |
| 308 |
|
| 309 |
|
| 310 |
fn sync_now(&self); |
| 311 |
|
| 312 |
|
| 313 |
fn set_auto(&self, enabled: bool); |
| 314 |
|
| 315 |
|
| 316 |
fn set_interval(&self, minutes: u32); |
| 317 |
|
| 318 |
|
| 319 |
fn clear_error(&self); |
| 320 |
|
| 321 |
|
| 322 |
fn disconnect(&self); |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
fn subscription(&self) -> Option<Subscription>; |
| 330 |
|
| 331 |
|
| 332 |
fn pricing(&self) -> Option<Pricing>; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
fn synced_library_bytes(&self) -> Option<i64>; |
| 343 |
|
| 344 |
|
| 345 |
fn quote_cents(&self, cap_bytes: i64, annual: bool) -> i64; |
| 346 |
|
| 347 |
|
| 348 |
fn refresh_subscription(&self); |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
fn subscribe(&self, cap_bytes: i64, annual: bool); |
| 356 |
|
| 357 |
|
| 358 |
fn queue_cap_change(&self, cap_bytes: i64); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
pub struct FromSyncManager<'a> { |
| 367 |
pub manager: &'a audiofiles_sync::SyncManager, |
| 368 |
pub backend: &'a dyn crate::backend::Backend, |
| 369 |
} |
| 370 |
|
| 371 |
impl Sync for FromSyncManager<'_> { |
| 372 |
fn status(&self) -> Status { |
| 373 |
let status = self.manager.status(); |
| 374 |
Status { |
| 375 |
state: match status.state { |
| 376 |
audiofiles_sync::SyncState::Disconnected => State::Disconnected, |
| 377 |
audiofiles_sync::SyncState::Authenticating => State::Authenticating, |
| 378 |
audiofiles_sync::SyncState::NeedsEncryption { has_server_key } => { |
| 379 |
State::NeedsEncryption { has_server_key } |
| 380 |
} |
| 381 |
audiofiles_sync::SyncState::Ready => State::Ready, |
| 382 |
audiofiles_sync::SyncState::Syncing => State::Syncing, |
| 383 |
}, |
| 384 |
last_sync_at: status.last_sync_at, |
| 385 |
pending_changes: status.pending_changes, |
| 386 |
last_error: status.last_error, |
| 387 |
auto_sync_enabled: status.auto_sync_enabled, |
| 388 |
sync_interval_minutes: status.sync_interval_minutes, |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
fn connect(&self) -> Result<String, String> { |
| 393 |
self.manager.start_auth().map_err(|error| error.to_string()) |
| 394 |
} |
| 395 |
|
| 396 |
fn cancel(&self) { |
| 397 |
self.manager.cancel_auth(); |
| 398 |
} |
| 399 |
|
| 400 |
fn set_password(&self, password: &str, is_new: bool) { |
| 401 |
self.manager.setup_encryption(password.to_owned(), is_new); |
| 402 |
} |
| 403 |
|
| 404 |
fn sync_now(&self) { |
| 405 |
self.manager.sync_now(); |
| 406 |
} |
| 407 |
|
| 408 |
fn set_auto(&self, enabled: bool) { |
| 409 |
self.manager.update_settings(Some(enabled), None); |
| 410 |
} |
| 411 |
|
| 412 |
fn set_interval(&self, minutes: u32) { |
| 413 |
self.manager.update_settings(None, Some(minutes)); |
| 414 |
} |
| 415 |
|
| 416 |
fn clear_error(&self) { |
| 417 |
self.manager.clear_last_error(); |
| 418 |
} |
| 419 |
|
| 420 |
fn disconnect(&self) { |
| 421 |
self.manager.disconnect(); |
| 422 |
} |
| 423 |
|
| 424 |
fn subscription(&self) -> Option<Subscription> { |
| 425 |
let status = self.manager.status(); |
| 426 |
status.subscription.map(|sub| Subscription { |
| 427 |
active: sub.active, |
| 428 |
limit_bytes: sub.storage_limit_bytes.unwrap_or(0), |
| 429 |
used_bytes: sub.storage_used_bytes.unwrap_or(0), |
| 430 |
interval: sub |
| 431 |
.interval |
| 432 |
.map_or_else(|| "monthly".to_owned(), |i| i.as_str().to_owned()), |
| 433 |
pending_limit_bytes: sub.pending_storage_limit_bytes, |
| 434 |
}) |
| 435 |
} |
| 436 |
|
| 437 |
fn pricing(&self) -> Option<Pricing> { |
| 438 |
self.manager.status().pricing.map(|pricing| Pricing { |
| 439 |
min_bytes: pricing.min_cap_bytes, |
| 440 |
max_bytes: pricing.max_cap_bytes, |
| 441 |
}) |
| 442 |
} |
| 443 |
|
| 444 |
fn synced_library_bytes(&self) -> Option<i64> { |
| 445 |
let (_, bytes) = self.backend.synced_storage_stats().ok()?; |
| 446 |
i64::try_from(bytes).ok() |
| 447 |
} |
| 448 |
|
| 449 |
fn quote_cents(&self, cap_bytes: i64, annual: bool) -> i64 { |
| 450 |
self.manager.status().pricing.map_or(0, |pricing| { |
| 451 |
pricing.quote_cents(cap_bytes, interval_of(annual)).0 |
| 452 |
}) |
| 453 |
} |
| 454 |
|
| 455 |
fn refresh_subscription(&self) { |
| 456 |
self.manager.fetch_subscription_status(); |
| 457 |
} |
| 458 |
|
| 459 |
fn subscribe(&self, cap_bytes: i64, annual: bool) { |
| 460 |
self.manager.subscribe(cap_bytes, interval_of(annual)); |
| 461 |
} |
| 462 |
|
| 463 |
fn queue_cap_change(&self, cap_bytes: i64) { |
| 464 |
self.manager.queue_cap_change(cap_bytes); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
fn interval_of(annual: bool) -> audiofiles_sync::BillingInterval { |
| 470 |
if annual { |
| 471 |
audiofiles_sync::BillingInterval::Annual |
| 472 |
} else { |
| 473 |
audiofiles_sync::BillingInterval::Monthly |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
pub struct Unconfigured; |
| 485 |
|
| 486 |
impl Sync for Unconfigured { |
| 487 |
fn available(&self) -> bool { |
| 488 |
false |
| 489 |
} |
| 490 |
|
| 491 |
fn status(&self) -> Status { |
| 492 |
Status { |
| 493 |
state: State::Disconnected, |
| 494 |
last_sync_at: None, |
| 495 |
pending_changes: 0, |
| 496 |
last_error: Some("Cloud sync is not configured for this build.".to_owned()), |
| 497 |
auto_sync_enabled: false, |
| 498 |
sync_interval_minutes: 0, |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
fn connect(&self) -> Result<String, String> { |
| 503 |
Err("Cloud sync is not configured for this build.".to_owned()) |
| 504 |
} |
| 505 |
|
| 506 |
fn cancel(&self) {} |
| 507 |
fn set_password(&self, _password: &str, _is_new: bool) {} |
| 508 |
fn sync_now(&self) {} |
| 509 |
fn set_auto(&self, _enabled: bool) {} |
| 510 |
fn set_interval(&self, _minutes: u32) {} |
| 511 |
fn clear_error(&self) {} |
| 512 |
fn disconnect(&self) {} |
| 513 |
fn subscription(&self) -> Option<Subscription> { |
| 514 |
None |
| 515 |
} |
| 516 |
fn pricing(&self) -> Option<Pricing> { |
| 517 |
None |
| 518 |
} |
| 519 |
fn synced_library_bytes(&self) -> Option<i64> { |
| 520 |
None |
| 521 |
} |
| 522 |
fn quote_cents(&self, _cap_bytes: i64, _annual: bool) -> i64 { |
| 523 |
0 |
| 524 |
} |
| 525 |
fn refresh_subscription(&self) {} |
| 526 |
fn subscribe(&self, _cap_bytes: i64, _annual: bool) {} |
| 527 |
fn queue_cap_change(&self, _cap_bytes: i64) {} |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
#[derive(Debug, Clone, PartialEq)] |
| 532 |
pub struct Sample { |
| 533 |
|
| 534 |
pub id: i64, |
| 535 |
|
| 536 |
pub name: String, |
| 537 |
|
| 538 |
pub duration: Option<f64>, |
| 539 |
|
| 540 |
pub bpm: Option<f64>, |
| 541 |
|
| 542 |
pub key: Option<String>, |
| 543 |
|
| 544 |
pub peak_db: Option<f64>, |
| 545 |
|
| 546 |
pub tags: Vec<String>, |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
pub directory: bool, |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
pub cloud_only: bool, |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] |
| 564 |
pub struct ColumnsShown { |
| 565 |
|
| 566 |
pub duration: bool, |
| 567 |
|
| 568 |
pub bpm: bool, |
| 569 |
|
| 570 |
pub key: bool, |
| 571 |
|
| 572 |
pub peak_db: bool, |
| 573 |
|
| 574 |
pub tags: bool, |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
pub trait Files { |
| 585 |
|
| 586 |
fn samples(&self) -> Vec<Sample>; |
| 587 |
|
| 588 |
|
| 589 |
fn columns(&self) -> ColumnsShown; |
| 590 |
|
| 591 |
|
| 592 |
fn sort(&self) -> (String, bool); |
| 593 |
|
| 594 |
|
| 595 |
fn current(&self) -> Option<i64>; |
| 596 |
|
| 597 |
|
| 598 |
fn open(&self, id: i64); |
| 599 |
|
| 600 |
|
| 601 |
fn play(&self, id: i64); |
| 602 |
|
| 603 |
|
| 604 |
fn sort_by(&self, column: &str); |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
fn enter(&self, id: i64); |
| 616 |
|
| 617 |
|
| 618 |
fn reveal(&self, id: i64); |
| 619 |
|
| 620 |
|
| 621 |
fn as_instrument(&self, id: i64); |
| 622 |
|
| 623 |
|
| 624 |
fn reanalyze(&self, id: i64); |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
fn delete(&self, id: i64); |
| 632 |
|
| 633 |
|
| 634 |
fn download(&self, id: i64); |
| 635 |
|
| 636 |
|
| 637 |
fn remove_from_collection(&self, id: i64); |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
fn add_to_collection(&self, id: i64, collection: i64); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
#[derive(Debug, Clone, PartialEq)] |
| 660 |
pub enum Intent { |
| 661 |
|
| 662 |
Open(i64), |
| 663 |
|
| 664 |
Play(i64), |
| 665 |
|
| 666 |
Enter(i64), |
| 667 |
|
| 668 |
Reveal(i64), |
| 669 |
|
| 670 |
Instrument(i64), |
| 671 |
|
| 672 |
Reanalyze(i64), |
| 673 |
|
| 674 |
Delete(i64), |
| 675 |
|
| 676 |
Download(i64), |
| 677 |
|
| 678 |
RemoveFromCollection(i64), |
| 679 |
|
| 680 |
AddToCollection(i64, i64), |
| 681 |
|
| 682 |
SortBy(String), |
| 683 |
|
| 684 |
Configure(Setting, String), |
| 685 |
|
| 686 |
StartExport, |
| 687 |
|
| 688 |
CancelExport, |
| 689 |
|
| 690 |
DismissExport, |
| 691 |
|
| 692 |
AddTag(String), |
| 693 |
|
| 694 |
RemoveTag(String), |
| 695 |
|
| 696 |
Suggest, |
| 697 |
|
| 698 |
AcceptSuggestion(String), |
| 699 |
|
| 700 |
CopyPath, |
| 701 |
|
| 702 |
Narrow(&'static str, Option<f64>, Option<f64>), |
| 703 |
|
| 704 |
KeyMode(bool), |
| 705 |
|
| 706 |
ToggleKey(String), |
| 707 |
|
| 708 |
ClearKeys, |
| 709 |
|
| 710 |
TypingTag(String), |
| 711 |
|
| 712 |
RequireTag(String), |
| 713 |
|
| 714 |
UnrequireTag(String), |
| 715 |
|
| 716 |
ClearTags, |
| 717 |
|
| 718 |
ClearFilters, |
| 719 |
|
| 720 |
Edit, |
| 721 |
|
| 722 |
Forge, |
| 723 |
|
| 724 |
FindSimilar, |
| 725 |
|
| 726 |
FindDuplicates, |
| 727 |
|
| 728 |
SpreadTag(String), |
| 729 |
|
| 730 |
StripTag(String), |
| 731 |
|
| 732 |
Search(String), |
| 733 |
|
| 734 |
Scope(bool), |
| 735 |
|
| 736 |
SaveCollection(String), |
| 737 |
|
| 738 |
Undo, |
| 739 |
|
| 740 |
TogglePanel(Panel), |
| 741 |
|
| 742 |
GoRoot, |
| 743 |
|
| 744 |
GoTo(i64, usize), |
| 745 |
|
| 746 |
Leave, |
| 747 |
|
| 748 |
OpenVault(i64), |
| 749 |
|
| 750 |
DeleteVault(i64), |
| 751 |
|
| 752 |
ToggleTag(String), |
| 753 |
|
| 754 |
RemoveTagEverywhere(String), |
| 755 |
|
| 756 |
OpenCollection(i64), |
| 757 |
|
| 758 |
CloseCollection, |
| 759 |
|
| 760 |
DeleteCollection(i64), |
| 761 |
|
| 762 |
StopPlayback, |
| 763 |
|
| 764 |
DismissHint, |
| 765 |
|
| 766 |
BulkTag(String, bool), |
| 767 |
|
| 768 |
BulkMove(Option<i64>), |
| 769 |
|
| 770 |
BulkRename(String), |
| 771 |
|
| 772 |
NamingDone, |
| 773 |
|
| 774 |
BulkDone, |
| 775 |
|
| 776 |
VaultsChanged(String), |
| 777 |
|
| 778 |
ContentsChanged(String), |
| 779 |
|
| 780 |
AcceptImport { again: bool }, |
| 781 |
|
| 782 |
CancelImport, |
| 783 |
|
| 784 |
OpenImportFolder, |
| 785 |
|
| 786 |
OpenQuickImport, |
| 787 |
|
| 788 |
OpenImportFiles, |
| 789 |
|
| 790 |
ChangeImportSource, |
| 791 |
|
| 792 |
Decide(Decision, String), |
| 793 |
|
| 794 |
BeginImport, |
| 795 |
|
| 796 |
StopImport, |
| 797 |
|
| 798 |
RetryImport, |
| 799 |
|
| 800 |
DismissImport, |
| 801 |
|
| 802 |
TagFolder(usize, String), |
| 803 |
|
| 804 |
TagEveryFolder(String), |
| 805 |
|
| 806 |
ApplyFolderTags, |
| 807 |
|
| 808 |
SkipFolderTags, |
| 809 |
|
| 810 |
Measure(Measure, bool), |
| 811 |
|
| 812 |
StartAnalysis, |
| 813 |
|
| 814 |
BackToTagging, |
| 815 |
|
| 816 |
SkipAnalysis, |
| 817 |
|
| 818 |
StopAnalysis, |
| 819 |
|
| 820 |
RetryAnalysis, |
| 821 |
|
| 822 |
OrderReview(Order), |
| 823 |
|
| 824 |
ReadReviewed(usize), |
| 825 |
|
| 826 |
Judge { |
| 827 |
|
| 828 |
at: usize, |
| 829 |
|
| 830 |
tag: String, |
| 831 |
|
| 832 |
accepted: bool, |
| 833 |
}, |
| 834 |
|
| 835 |
JudgeAll(bool), |
| 836 |
|
| 837 |
ApplySuggestions, |
| 838 |
|
| 839 |
DiscardSuggestions, |
| 840 |
|
| 841 |
KeepFailed, |
| 842 |
|
| 843 |
PurgeFailed(Option<usize>), |
| 844 |
|
| 845 |
StopSweep, |
| 846 |
|
| 847 |
PauseMigration, |
| 848 |
|
| 849 |
SliceBy(Chop), |
| 850 |
|
| 851 |
Turn(Knob, String), |
| 852 |
|
| 853 |
PreviewSlices, |
| 854 |
|
| 855 |
Chop, |
| 856 |
|
| 857 |
ChooseDevice(String), |
| 858 |
|
| 859 |
Conform, |
| 860 |
|
| 861 |
TrimSilence, |
| 862 |
|
| 863 |
ReadGroup(usize), |
| 864 |
|
| 865 |
TickCandidate(usize), |
| 866 |
|
| 867 |
TickShown(bool), |
| 868 |
|
| 869 |
AcceptGroup(Scope), |
| 870 |
|
| 871 |
AcceptConfident, |
| 872 |
|
| 873 |
DismissGroup, |
| 874 |
|
| 875 |
Rescan, |
| 876 |
|
| 877 |
CloseReview, |
| 878 |
|
| 879 |
BeginExport, |
| 880 |
|
| 881 |
DismissLooseFiles, |
| 882 |
|
| 883 |
PurgeLooseFiles, |
| 884 |
|
| 885 |
LocateLooseFiles, |
| 886 |
|
| 887 |
EditTrim { |
| 888 |
|
| 889 |
start: f32, |
| 890 |
|
| 891 |
end: f32, |
| 892 |
}, |
| 893 |
|
| 894 |
EditGain(f64), |
| 895 |
|
| 896 |
EditNormalize { |
| 897 |
|
| 898 |
peak: bool, |
| 899 |
|
| 900 |
target: f64, |
| 901 |
}, |
| 902 |
|
| 903 |
EditReverse, |
| 904 |
|
| 905 |
EditFade { |
| 906 |
|
| 907 |
fading_in: bool, |
| 908 |
|
| 909 |
ms: f64, |
| 910 |
|
| 911 |
curve: String, |
| 912 |
}, |
| 913 |
|
| 914 |
EditInsertSilence { |
| 915 |
|
| 916 |
at: f64, |
| 917 |
|
| 918 |
ms: f64, |
| 919 |
}, |
| 920 |
|
| 921 |
EditRemoveRange { |
| 922 |
|
| 923 |
from: f64, |
| 924 |
|
| 925 |
to: f64, |
| 926 |
}, |
| 927 |
|
| 928 |
EditCancel, |
| 929 |
|
| 930 |
EditPlay, |
| 931 |
|
| 932 |
EditRemember(String), |
| 933 |
|
| 934 |
EditChoose { |
| 935 |
|
| 936 |
mode: String, |
| 937 |
|
| 938 |
remember: bool, |
| 939 |
}, |
| 940 |
|
| 941 |
EditDiscard, |
| 942 |
|
| 943 |
EditUndo, |
| 944 |
|
| 945 |
BatchNormalize { |
| 946 |
|
| 947 |
peak: bool, |
| 948 |
|
| 949 |
target: f64, |
| 950 |
}, |
| 951 |
|
| 952 |
BatchGain(f64), |
| 953 |
|
| 954 |
BatchReverse, |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
pub struct FromContents<'a> { |
| 964 |
|
| 965 |
pub state: &'a crate::state::BrowserState, |
| 966 |
|
| 967 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 968 |
} |
| 969 |
|
| 970 |
impl Files for FromContents<'_> { |
| 971 |
fn samples(&self) -> Vec<Sample> { |
| 972 |
self.state |
| 973 |
.nav |
| 974 |
.contents |
| 975 |
.iter() |
| 976 |
.map(|node| Sample { |
| 977 |
id: node.node.id.as_i64(), |
| 978 |
name: node.node.name.clone(), |
| 979 |
duration: node.duration, |
| 980 |
bpm: node.bpm, |
| 981 |
key: node.musical_key.clone(), |
| 982 |
peak_db: node.peak_db, |
| 983 |
tags: node.tags.clone(), |
| 984 |
directory: matches!( |
| 985 |
node.node.node_type, |
| 986 |
audiofiles_core::vfs::NodeType::Directory |
| 987 |
), |
| 988 |
cloud_only: node.cloud_only, |
| 989 |
}) |
| 990 |
.collect() |
| 991 |
} |
| 992 |
|
| 993 |
fn columns(&self) -> ColumnsShown { |
| 994 |
let shown = &self.state.column_config; |
| 995 |
ColumnsShown { |
| 996 |
duration: shown.show_duration, |
| 997 |
bpm: shown.show_bpm, |
| 998 |
key: shown.show_key, |
| 999 |
peak_db: shown.show_peak_db, |
| 1000 |
tags: shown.show_tags, |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
fn sort(&self) -> (String, bool) { |
| 1005 |
let by = match self.state.nav.sort_column { |
| 1006 |
crate::state::SortColumn::Name => "Name", |
| 1007 |
crate::state::SortColumn::Bpm => "BPM", |
| 1008 |
crate::state::SortColumn::Key => "Key", |
| 1009 |
crate::state::SortColumn::Duration => "Duration", |
| 1010 |
}; |
| 1011 |
( |
| 1012 |
by.to_owned(), |
| 1013 |
matches!( |
| 1014 |
self.state.nav.sort_direction, |
| 1015 |
crate::state::SortDirection::Ascending |
| 1016 |
), |
| 1017 |
) |
| 1018 |
} |
| 1019 |
|
| 1020 |
fn current(&self) -> Option<i64> { |
| 1021 |
self.state.selected_node().map(|node| node.node.id.as_i64()) |
| 1022 |
} |
| 1023 |
|
| 1024 |
fn open(&self, id: i64) { |
| 1025 |
self.intents.borrow_mut().push(Intent::Open(id)); |
| 1026 |
} |
| 1027 |
|
| 1028 |
fn play(&self, id: i64) { |
| 1029 |
self.intents.borrow_mut().push(Intent::Play(id)); |
| 1030 |
} |
| 1031 |
|
| 1032 |
fn sort_by(&self, column: &str) { |
| 1033 |
self.intents |
| 1034 |
.borrow_mut() |
| 1035 |
.push(Intent::SortBy(column.to_owned())); |
| 1036 |
} |
| 1037 |
|
| 1038 |
fn enter(&self, id: i64) { |
| 1039 |
self.intents.borrow_mut().push(Intent::Enter(id)); |
| 1040 |
} |
| 1041 |
|
| 1042 |
fn reveal(&self, id: i64) { |
| 1043 |
self.intents.borrow_mut().push(Intent::Reveal(id)); |
| 1044 |
} |
| 1045 |
|
| 1046 |
fn as_instrument(&self, id: i64) { |
| 1047 |
self.intents.borrow_mut().push(Intent::Instrument(id)); |
| 1048 |
} |
| 1049 |
|
| 1050 |
fn reanalyze(&self, id: i64) { |
| 1051 |
self.intents.borrow_mut().push(Intent::Reanalyze(id)); |
| 1052 |
} |
| 1053 |
|
| 1054 |
fn delete(&self, id: i64) { |
| 1055 |
self.intents.borrow_mut().push(Intent::Delete(id)); |
| 1056 |
} |
| 1057 |
|
| 1058 |
fn download(&self, id: i64) { |
| 1059 |
self.intents.borrow_mut().push(Intent::Download(id)); |
| 1060 |
} |
| 1061 |
|
| 1062 |
fn remove_from_collection(&self, id: i64) { |
| 1063 |
self.intents |
| 1064 |
.borrow_mut() |
| 1065 |
.push(Intent::RemoveFromCollection(id)); |
| 1066 |
} |
| 1067 |
|
| 1068 |
fn add_to_collection(&self, id: i64, collection: i64) { |
| 1069 |
self.intents |
| 1070 |
.borrow_mut() |
| 1071 |
.push(Intent::AddToCollection(id, collection)); |
| 1072 |
} |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
#[derive(Debug, Clone, PartialEq)] |
| 1083 |
pub enum Phase { |
| 1084 |
|
| 1085 |
Idle, |
| 1086 |
|
| 1087 |
Configuring { |
| 1088 |
|
| 1089 |
subjects: Vec<Subject>, |
| 1090 |
|
| 1091 |
profiles: Vec<ProfileChoice>, |
| 1092 |
|
| 1093 |
settings: Settings, |
| 1094 |
}, |
| 1095 |
|
| 1096 |
Running { |
| 1097 |
|
| 1098 |
done: usize, |
| 1099 |
|
| 1100 |
|
| 1101 |
total: usize, |
| 1102 |
|
| 1103 |
current: String, |
| 1104 |
}, |
| 1105 |
|
| 1106 |
Finished { |
| 1107 |
|
| 1108 |
total: usize, |
| 1109 |
|
| 1110 |
errors: Vec<(String, String)>, |
| 1111 |
|
| 1112 |
destination: Option<String>, |
| 1113 |
}, |
| 1114 |
|
| 1115 |
Cancelled { |
| 1116 |
|
| 1117 |
done: usize, |
| 1118 |
|
| 1119 |
total: usize, |
| 1120 |
|
| 1121 |
destination: Option<String>, |
| 1122 |
}, |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
#[derive(Debug, Clone, PartialEq)] |
| 1132 |
pub struct Subject { |
| 1133 |
|
| 1134 |
pub name: String, |
| 1135 |
|
| 1136 |
pub ext: String, |
| 1137 |
|
| 1138 |
pub duration: Option<f64>, |
| 1139 |
|
| 1140 |
pub bpm: Option<f64>, |
| 1141 |
|
| 1142 |
pub musical_key: Option<String>, |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1147 |
pub struct ProfileChoice { |
| 1148 |
|
| 1149 |
pub name: String, |
| 1150 |
|
| 1151 |
pub manufacturer: String, |
| 1152 |
|
| 1153 |
pub summary: Option<String>, |
| 1154 |
|
| 1155 |
pub category: Option<String>, |
| 1156 |
|
| 1157 |
pub notes: Option<String>, |
| 1158 |
|
| 1159 |
pub max_file_size_bytes: Option<u64>, |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1164 |
pub struct Settings { |
| 1165 |
|
| 1166 |
pub format: Format, |
| 1167 |
|
| 1168 |
pub sample_rate: Option<u32>, |
| 1169 |
|
| 1170 |
pub bit_depth: Option<u16>, |
| 1171 |
|
| 1172 |
pub channels: Channels, |
| 1173 |
|
| 1174 |
pub flatten: bool, |
| 1175 |
|
| 1176 |
pub sidecar: bool, |
| 1177 |
|
| 1178 |
pub naming_pattern: Option<String>, |
| 1179 |
|
| 1180 |
pub destination: String, |
| 1181 |
|
| 1182 |
pub device_profile: Option<String>, |
| 1183 |
} |
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1190 |
pub enum Format { |
| 1191 |
|
| 1192 |
Original, |
| 1193 |
|
| 1194 |
Wav, |
| 1195 |
|
| 1196 |
Aiff, |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1201 |
pub enum Channels { |
| 1202 |
|
| 1203 |
Original, |
| 1204 |
|
| 1205 |
Mono, |
| 1206 |
|
| 1207 |
Stereo, |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 1216 |
pub enum Setting { |
| 1217 |
|
| 1218 |
Format, |
| 1219 |
|
| 1220 |
SampleRate, |
| 1221 |
|
| 1222 |
BitDepth, |
| 1223 |
|
| 1224 |
Channels, |
| 1225 |
|
| 1226 |
Flatten, |
| 1227 |
|
| 1228 |
Sidecar, |
| 1229 |
|
| 1230 |
NamingPattern, |
| 1231 |
|
| 1232 |
DeviceProfile, |
| 1233 |
} |
| 1234 |
|
| 1235 |
impl Setting { |
| 1236 |
|
| 1237 |
#[must_use] |
| 1238 |
pub const fn as_str(self) -> &'static str { |
| 1239 |
match self { |
| 1240 |
Self::Format => "format", |
| 1241 |
Self::SampleRate => "sample-rate", |
| 1242 |
Self::BitDepth => "bit-depth", |
| 1243 |
Self::Channels => "channels", |
| 1244 |
Self::Flatten => "flatten", |
| 1245 |
Self::Sidecar => "sidecar", |
| 1246 |
Self::NamingPattern => "naming-pattern", |
| 1247 |
Self::DeviceProfile => "device-profile", |
| 1248 |
} |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
#[must_use] |
| 1257 |
pub fn from_key(name: &str) -> Option<Self> { |
| 1258 |
match name { |
| 1259 |
"format" => Some(Self::Format), |
| 1260 |
"sample-rate" => Some(Self::SampleRate), |
| 1261 |
"bit-depth" => Some(Self::BitDepth), |
| 1262 |
"channels" => Some(Self::Channels), |
| 1263 |
"flatten" => Some(Self::Flatten), |
| 1264 |
"sidecar" => Some(Self::Sidecar), |
| 1265 |
"naming-pattern" => Some(Self::NamingPattern), |
| 1266 |
"device-profile" => Some(Self::DeviceProfile), |
| 1267 |
_ => None, |
| 1268 |
} |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
pub trait Export { |
| 1281 |
|
| 1282 |
fn phase(&self) -> Phase; |
| 1283 |
|
| 1284 |
|
| 1285 |
fn open(&self); |
| 1286 |
|
| 1287 |
|
| 1288 |
fn configure(&self, setting: Setting, value: &str); |
| 1289 |
|
| 1290 |
|
| 1291 |
fn start(&self); |
| 1292 |
|
| 1293 |
|
| 1294 |
fn cancel(&self); |
| 1295 |
|
| 1296 |
|
| 1297 |
fn dismiss(&self); |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
pub struct FromExport<'a> { |
| 1302 |
|
| 1303 |
pub state: &'a crate::state::BrowserState, |
| 1304 |
|
| 1305 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 1306 |
} |
| 1307 |
|
| 1308 |
impl Export for FromExport<'_> { |
| 1309 |
fn open(&self) { |
| 1310 |
self.intents.borrow_mut().push(Intent::BeginExport); |
| 1311 |
} |
| 1312 |
|
| 1313 |
fn phase(&self) -> Phase { |
| 1314 |
use crate::state::ImportMode; |
| 1315 |
|
| 1316 |
match &self.state.import_wf.import_mode { |
| 1317 |
ImportMode::ConfigureExport { |
| 1318 |
items, |
| 1319 |
config, |
| 1320 |
available_profiles, |
| 1321 |
} => Phase::Configuring { |
| 1322 |
subjects: items |
| 1323 |
.iter() |
| 1324 |
.map(|item| Subject { |
| 1325 |
name: item.name.clone(), |
| 1326 |
ext: item.ext.clone(), |
| 1327 |
duration: item.duration, |
| 1328 |
bpm: item.bpm, |
| 1329 |
musical_key: item.musical_key.clone(), |
| 1330 |
}) |
| 1331 |
.collect(), |
| 1332 |
profiles: available_profiles |
| 1333 |
.iter() |
| 1334 |
.map(|profile| ProfileChoice { |
| 1335 |
name: profile.name.clone(), |
| 1336 |
manufacturer: profile.manufacturer.clone(), |
| 1337 |
summary: profile.format_summary.clone(), |
| 1338 |
category: profile.category.clone(), |
| 1339 |
notes: profile.notes.clone(), |
| 1340 |
max_file_size_bytes: profile.max_file_size_bytes, |
| 1341 |
}) |
| 1342 |
.collect(), |
| 1343 |
settings: Settings { |
| 1344 |
format: match config.format { |
| 1345 |
audiofiles_core::export::ExportFormat::Original => Format::Original, |
| 1346 |
audiofiles_core::export::ExportFormat::Wav => Format::Wav, |
| 1347 |
audiofiles_core::export::ExportFormat::Aiff => Format::Aiff, |
| 1348 |
}, |
| 1349 |
sample_rate: config.sample_rate, |
| 1350 |
bit_depth: config.bit_depth, |
| 1351 |
channels: match config.channels { |
| 1352 |
audiofiles_core::export::ExportChannels::Original => Channels::Original, |
| 1353 |
audiofiles_core::export::ExportChannels::Mono => Channels::Mono, |
| 1354 |
audiofiles_core::export::ExportChannels::Stereo => Channels::Stereo, |
| 1355 |
}, |
| 1356 |
flatten: config.flatten, |
| 1357 |
sidecar: config.metadata_sidecar, |
| 1358 |
naming_pattern: config.naming_pattern.clone(), |
| 1359 |
destination: config.destination.display().to_string(), |
| 1360 |
device_profile: config.device_profile.clone(), |
| 1361 |
}, |
| 1362 |
}, |
| 1363 |
ImportMode::Exporting { |
| 1364 |
completed, |
| 1365 |
total, |
| 1366 |
current_name, |
| 1367 |
} => Phase::Running { |
| 1368 |
done: *completed, |
| 1369 |
total: *total, |
| 1370 |
current: current_name.clone(), |
| 1371 |
}, |
| 1372 |
ImportMode::ExportComplete { total, errors } => Phase::Finished { |
| 1373 |
total: *total, |
| 1374 |
errors: errors.clone(), |
| 1375 |
destination: self.destination(), |
| 1376 |
}, |
| 1377 |
ImportMode::OperationCancelled { |
| 1378 |
kind: crate::state::CancelKind::Export, |
| 1379 |
completed, |
| 1380 |
total, |
| 1381 |
destination, |
| 1382 |
} => Phase::Cancelled { |
| 1383 |
done: *completed, |
| 1384 |
total: *total, |
| 1385 |
destination: destination.as_ref().map(|path| path.display().to_string()), |
| 1386 |
}, |
| 1387 |
_ => Phase::Idle, |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
fn configure(&self, setting: Setting, value: &str) { |
| 1392 |
self.intents |
| 1393 |
.borrow_mut() |
| 1394 |
.push(Intent::Configure(setting, value.to_owned())); |
| 1395 |
} |
| 1396 |
|
| 1397 |
fn start(&self) { |
| 1398 |
self.intents.borrow_mut().push(Intent::StartExport); |
| 1399 |
} |
| 1400 |
|
| 1401 |
fn cancel(&self) { |
| 1402 |
self.intents.borrow_mut().push(Intent::CancelExport); |
| 1403 |
} |
| 1404 |
|
| 1405 |
fn dismiss(&self) { |
| 1406 |
self.intents.borrow_mut().push(Intent::DismissExport); |
| 1407 |
} |
| 1408 |
} |
| 1409 |
|
| 1410 |
impl FromExport<'_> { |
| 1411 |
|
| 1412 |
fn destination(&self) -> Option<String> { |
| 1413 |
self.state |
| 1414 |
.import_wf |
| 1415 |
.last_export_destination |
| 1416 |
.as_ref() |
| 1417 |
.map(|path| path.display().to_string()) |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
#[derive(Debug, Clone, PartialEq)] |
| 1430 |
pub enum Focus { |
| 1431 |
|
| 1432 |
Nothing, |
| 1433 |
|
| 1434 |
One(Box<Detailed>), |
| 1435 |
|
| 1436 |
Several(Box<Spread>), |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
#[derive(Debug, Clone, PartialEq)] |
| 1446 |
pub struct Detailed { |
| 1447 |
|
| 1448 |
pub id: i64, |
| 1449 |
|
| 1450 |
pub name: String, |
| 1451 |
|
| 1452 |
pub path: Option<String>, |
| 1453 |
|
| 1454 |
pub analysis: Option<Analysis>, |
| 1455 |
|
| 1456 |
pub tags: Vec<Tagged>, |
| 1457 |
|
| 1458 |
pub suggestions: Vec<Suggested>, |
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
pub is_sample: bool, |
| 1463 |
|
| 1464 |
pub has_spectral: bool, |
| 1465 |
|
| 1466 |
pub has_fingerprint: bool, |
| 1467 |
} |
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
#[derive(Debug, Clone, PartialEq)] |
| 1477 |
pub struct Analysis { |
| 1478 |
|
| 1479 |
pub duration: f64, |
| 1480 |
|
| 1481 |
pub sample_rate: u32, |
| 1482 |
|
| 1483 |
pub channels: u16, |
| 1484 |
|
| 1485 |
pub bpm: Option<f64>, |
| 1486 |
|
| 1487 |
pub musical_key: Option<String>, |
| 1488 |
|
| 1489 |
pub peak_db: Option<f64>, |
| 1490 |
|
| 1491 |
pub rms_db: Option<f64>, |
| 1492 |
|
| 1493 |
pub lufs: Option<f64>, |
| 1494 |
|
| 1495 |
pub is_loop: Option<bool>, |
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 1499 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1500 |
pub struct Tagged { |
| 1501 |
|
| 1502 |
pub name: String, |
| 1503 |
|
| 1504 |
pub source: Source, |
| 1505 |
} |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1516 |
pub enum Source { |
| 1517 |
|
| 1518 |
Manual, |
| 1519 |
|
| 1520 |
Rule, |
| 1521 |
|
| 1522 |
Suggested, |
| 1523 |
|
| 1524 |
Cluster, |
| 1525 |
|
| 1526 |
Folder, |
| 1527 |
|
| 1528 |
Other(String), |
| 1529 |
} |
| 1530 |
|
| 1531 |
impl Source { |
| 1532 |
|
| 1533 |
#[must_use] |
| 1534 |
pub fn as_str(&self) -> &str { |
| 1535 |
match self { |
| 1536 |
Self::Manual => "manual", |
| 1537 |
Self::Rule => "rule", |
| 1538 |
Self::Suggested => "suggested", |
| 1539 |
Self::Cluster => "cluster", |
| 1540 |
Self::Folder => "folder", |
| 1541 |
Self::Other(other) => other, |
| 1542 |
} |
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
fn of(name: Option<&str>) -> Self { |
| 1547 |
match name { |
| 1548 |
None => Self::Manual, |
| 1549 |
Some("rule") => Self::Rule, |
| 1550 |
Some("ml") => Self::Suggested, |
| 1551 |
Some("cluster") => Self::Cluster, |
| 1552 |
Some("harvest") => Self::Folder, |
| 1553 |
Some(other) => Self::Other(other.to_owned()), |
| 1554 |
} |
| 1555 |
} |
| 1556 |
} |
| 1557 |
|
| 1558 |
|
| 1559 |
#[derive(Debug, Clone, PartialEq)] |
| 1560 |
pub struct Suggested { |
| 1561 |
|
| 1562 |
pub tag: String, |
| 1563 |
|
| 1564 |
pub score: f64, |
| 1565 |
|
| 1566 |
pub neighbours: usize, |
| 1567 |
} |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1578 |
pub struct Spread { |
| 1579 |
|
| 1580 |
pub samples: usize, |
| 1581 |
|
| 1582 |
pub folders: usize, |
| 1583 |
|
| 1584 |
pub bpm: Shared, |
| 1585 |
|
| 1586 |
pub musical_key: Shared, |
| 1587 |
|
| 1588 |
pub duration: Shared, |
| 1589 |
|
| 1590 |
pub tags: Vec<Coverage>, |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1599 |
pub enum Shared { |
| 1600 |
|
| 1601 |
Same(String), |
| 1602 |
|
| 1603 |
Varies, |
| 1604 |
|
| 1605 |
Absent, |
| 1606 |
} |
| 1607 |
|
| 1608 |
|
| 1609 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1610 |
pub struct Coverage { |
| 1611 |
|
| 1612 |
pub name: String, |
| 1613 |
|
| 1614 |
pub on: usize, |
| 1615 |
} |
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
pub trait Detail { |
| 1638 |
|
| 1639 |
fn focus(&self) -> Focus; |
| 1640 |
|
| 1641 |
|
| 1642 |
fn add_tag(&self, tag: &str); |
| 1643 |
|
| 1644 |
|
| 1645 |
fn remove_tag(&self, tag: &str); |
| 1646 |
|
| 1647 |
|
| 1648 |
fn suggest(&self); |
| 1649 |
|
| 1650 |
|
| 1651 |
fn accept(&self, tag: &str); |
| 1652 |
|
| 1653 |
|
| 1654 |
fn copy_path(&self); |
| 1655 |
|
| 1656 |
|
| 1657 |
fn edit(&self); |
| 1658 |
|
| 1659 |
|
| 1660 |
fn forge(&self); |
| 1661 |
|
| 1662 |
|
| 1663 |
fn find_similar(&self); |
| 1664 |
|
| 1665 |
|
| 1666 |
fn find_duplicates(&self); |
| 1667 |
|
| 1668 |
|
| 1669 |
fn spread_tag(&self, tag: &str); |
| 1670 |
|
| 1671 |
|
| 1672 |
fn strip_tag(&self, tag: &str); |
| 1673 |
} |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
pub struct FromSelection<'a> { |
| 1682 |
|
| 1683 |
pub state: &'a crate::state::BrowserState, |
| 1684 |
|
| 1685 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 1686 |
} |
| 1687 |
|
| 1688 |
impl Detail for FromSelection<'_> { |
| 1689 |
fn focus(&self) -> Focus { |
| 1690 |
if self.state.nav.selection.count() > 1 { |
| 1691 |
return Focus::Several(Box::new(self.spread())); |
| 1692 |
} |
| 1693 |
let Some(node) = self.state.selected_node() else { |
| 1694 |
return Focus::Nothing; |
| 1695 |
}; |
| 1696 |
Focus::One(Box::new(Detailed { |
| 1697 |
id: node.node.id.as_i64(), |
| 1698 |
name: node.node.name.clone(), |
| 1699 |
path: self.state.selected_sample_path(), |
| 1700 |
analysis: self |
| 1701 |
.state |
| 1702 |
.detail |
| 1703 |
.selected_analysis |
| 1704 |
.as_ref() |
| 1705 |
.map(|found| Analysis { |
| 1706 |
duration: found.duration, |
| 1707 |
sample_rate: found.sample_rate, |
| 1708 |
channels: found.channels, |
| 1709 |
bpm: found.bpm, |
| 1710 |
musical_key: found.musical_key.clone(), |
| 1711 |
peak_db: found.peak_db, |
| 1712 |
rms_db: found.rms_db, |
| 1713 |
lufs: found.lufs, |
| 1714 |
is_loop: found.is_loop, |
| 1715 |
}), |
| 1716 |
tags: self |
| 1717 |
.state |
| 1718 |
.detail |
| 1719 |
.selected_tags |
| 1720 |
.iter() |
| 1721 |
.map(|tag| Tagged { |
| 1722 |
name: tag.clone(), |
| 1723 |
source: Source::of( |
| 1724 |
self.state |
| 1725 |
.detail |
| 1726 |
.selected_tag_sources |
| 1727 |
.get(tag) |
| 1728 |
.map(|(source, _)| source.as_str()), |
| 1729 |
), |
| 1730 |
}) |
| 1731 |
.collect(), |
| 1732 |
suggestions: self |
| 1733 |
.state |
| 1734 |
.detail |
| 1735 |
.selected_ml_suggestions |
| 1736 |
.iter() |
| 1737 |
.map(|found| Suggested { |
| 1738 |
tag: found.tag.clone(), |
| 1739 |
score: found.score, |
| 1740 |
neighbours: found.neighbors.len(), |
| 1741 |
}) |
| 1742 |
.collect(), |
| 1743 |
is_sample: node.node.sample_hash.is_some(), |
| 1744 |
has_spectral: self |
| 1745 |
.state |
| 1746 |
.detail |
| 1747 |
.selected_analysis |
| 1748 |
.as_ref() |
| 1749 |
.is_some_and(|found| { |
| 1750 |
found.spectral_centroid.is_some() || found.spectral_bandwidth.is_some() |
| 1751 |
}), |
| 1752 |
has_fingerprint: self |
| 1753 |
.state |
| 1754 |
.detail |
| 1755 |
.selected_analysis |
| 1756 |
.as_ref() |
| 1757 |
.is_some_and(|found| found.fingerprint.is_some()), |
| 1758 |
})) |
| 1759 |
} |
| 1760 |
|
| 1761 |
fn add_tag(&self, tag: &str) { |
| 1762 |
self.push(Intent::AddTag(tag.to_owned())); |
| 1763 |
} |
| 1764 |
|
| 1765 |
fn remove_tag(&self, tag: &str) { |
| 1766 |
self.push(Intent::RemoveTag(tag.to_owned())); |
| 1767 |
} |
| 1768 |
|
| 1769 |
fn suggest(&self) { |
| 1770 |
self.push(Intent::Suggest); |
| 1771 |
} |
| 1772 |
|
| 1773 |
fn accept(&self, tag: &str) { |
| 1774 |
self.push(Intent::AcceptSuggestion(tag.to_owned())); |
| 1775 |
} |
| 1776 |
|
| 1777 |
fn copy_path(&self) { |
| 1778 |
self.push(Intent::CopyPath); |
| 1779 |
} |
| 1780 |
|
| 1781 |
fn edit(&self) { |
| 1782 |
self.push(Intent::Edit); |
| 1783 |
} |
| 1784 |
|
| 1785 |
fn forge(&self) { |
| 1786 |
self.push(Intent::Forge); |
| 1787 |
} |
| 1788 |
|
| 1789 |
fn find_similar(&self) { |
| 1790 |
self.push(Intent::FindSimilar); |
| 1791 |
} |
| 1792 |
|
| 1793 |
fn find_duplicates(&self) { |
| 1794 |
self.push(Intent::FindDuplicates); |
| 1795 |
} |
| 1796 |
|
| 1797 |
fn spread_tag(&self, tag: &str) { |
| 1798 |
self.push(Intent::SpreadTag(tag.to_owned())); |
| 1799 |
} |
| 1800 |
|
| 1801 |
fn strip_tag(&self, tag: &str) { |
| 1802 |
self.push(Intent::StripTag(tag.to_owned())); |
| 1803 |
} |
| 1804 |
} |
| 1805 |
|
| 1806 |
impl FromSelection<'_> { |
| 1807 |
|
| 1808 |
fn push(&self, intent: Intent) { |
| 1809 |
self.intents.borrow_mut().push(intent); |
| 1810 |
} |
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
fn spread(&self) -> Spread { |
| 1819 |
let nodes = self.state.selected_nodes(); |
| 1820 |
let samples: Vec<_> = nodes |
| 1821 |
.iter() |
| 1822 |
.filter(|node| node.node.sample_hash.is_some()) |
| 1823 |
.collect(); |
| 1824 |
let count = samples.len(); |
| 1825 |
|
| 1826 |
let mut counts: std::collections::BTreeMap<String, usize> = |
| 1827 |
std::collections::BTreeMap::new(); |
| 1828 |
for node in &samples { |
| 1829 |
for tag in &node.tags { |
| 1830 |
*counts.entry(tag.clone()).or_insert(0) += 1; |
| 1831 |
} |
| 1832 |
} |
| 1833 |
let mut tags: Vec<Coverage> = counts |
| 1834 |
.into_iter() |
| 1835 |
.map(|(name, on)| Coverage { name, on }) |
| 1836 |
.collect(); |
| 1837 |
|
| 1838 |
|
| 1839 |
tags.sort_by(|left, right| { |
| 1840 |
right |
| 1841 |
.on |
| 1842 |
.cmp(&left.on) |
| 1843 |
.then_with(|| left.name.cmp(&right.name)) |
| 1844 |
}); |
| 1845 |
|
| 1846 |
Spread { |
| 1847 |
samples: count, |
| 1848 |
folders: nodes.len().saturating_sub(count), |
| 1849 |
bpm: shared( |
| 1850 |
crate::quasi::detail::summarize(&samples, |node| node.bpm), |
| 1851 |
|bpm| format!("{bpm:.0}"), |
| 1852 |
), |
| 1853 |
musical_key: shared( |
| 1854 |
crate::quasi::detail::summarize(&samples, |node| node.musical_key.clone()), |
| 1855 |
|key| key, |
| 1856 |
), |
| 1857 |
duration: shared( |
| 1858 |
crate::quasi::detail::summarize(&samples, |node| node.duration), |
| 1859 |
|seconds| format!("{seconds:.1}s"), |
| 1860 |
), |
| 1861 |
tags, |
| 1862 |
} |
| 1863 |
} |
| 1864 |
} |
| 1865 |
|
| 1866 |
|
| 1867 |
fn shared<T>(summary: Option<Result<T, ()>>, write: impl FnOnce(T) -> String) -> Shared { |
| 1868 |
match summary { |
| 1869 |
Some(Ok(value)) => Shared::Same(write(value)), |
| 1870 |
Some(Err(())) => Shared::Varies, |
| 1871 |
None => Shared::Absent, |
| 1872 |
} |
| 1873 |
} |
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1881 |
pub struct Chosen { |
| 1882 |
|
| 1883 |
pub names: Vec<String>, |
| 1884 |
|
| 1885 |
|
| 1886 |
pub samples: usize, |
| 1887 |
} |
| 1888 |
|
| 1889 |
|
| 1890 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 1891 |
pub struct Folder { |
| 1892 |
|
| 1893 |
pub id: i64, |
| 1894 |
|
| 1895 |
pub path: String, |
| 1896 |
} |
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
pub trait Bulk { |
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
fn done(&self); |
| 1944 |
|
| 1945 |
|
| 1946 |
fn chosen(&self) -> Chosen; |
| 1947 |
|
| 1948 |
|
| 1949 |
fn known_tags(&self) -> Vec<String>; |
| 1950 |
|
| 1951 |
|
| 1952 |
fn folders(&self) -> Vec<Folder>; |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
fn previews(&self, pattern: &str) -> Result<Vec<(String, String)>, String>; |
| 1959 |
|
| 1960 |
|
| 1961 |
fn tag(&self, tag: &str, adding: bool); |
| 1962 |
|
| 1963 |
|
| 1964 |
fn move_to(&self, folder: Option<i64>); |
| 1965 |
|
| 1966 |
|
| 1967 |
fn rename(&self, pattern: &str); |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
pub struct FromBulk<'a> { |
| 1972 |
|
| 1973 |
pub state: &'a crate::state::BrowserState, |
| 1974 |
|
| 1975 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 1976 |
} |
| 1977 |
|
| 1978 |
impl Bulk for FromBulk<'_> { |
| 1979 |
fn done(&self) { |
| 1980 |
self.intents.borrow_mut().push(Intent::BulkDone); |
| 1981 |
} |
| 1982 |
|
| 1983 |
fn chosen(&self) -> Chosen { |
| 1984 |
let nodes = self.state.selected_nodes(); |
| 1985 |
Chosen { |
| 1986 |
samples: nodes |
| 1987 |
.iter() |
| 1988 |
.filter(|node| node.node.sample_hash.is_some()) |
| 1989 |
.count(), |
| 1990 |
names: nodes.iter().map(|node| node.node.name.clone()).collect(), |
| 1991 |
} |
| 1992 |
} |
| 1993 |
|
| 1994 |
fn known_tags(&self) -> Vec<String> { |
| 1995 |
self.state.all_tags.iter().cloned().collect() |
| 1996 |
} |
| 1997 |
|
| 1998 |
fn folders(&self) -> Vec<Folder> { |
| 1999 |
let Some(vfs) = self.state.current_vfs_id() else { |
| 2000 |
return Vec::new(); |
| 2001 |
}; |
| 2002 |
self.state |
| 2003 |
.backend |
| 2004 |
.list_all_directories(vfs) |
| 2005 |
.unwrap_or_default() |
| 2006 |
.into_iter() |
| 2007 |
.map(|(id, path)| Folder { |
| 2008 |
id: id.as_i64(), |
| 2009 |
path, |
| 2010 |
}) |
| 2011 |
.collect() |
| 2012 |
} |
| 2013 |
|
| 2014 |
fn previews(&self, pattern: &str) -> Result<Vec<(String, String)>, String> { |
| 2015 |
use audiofiles_core::rename::{RenameContext, RenamePattern}; |
| 2016 |
|
| 2017 |
let parsed = RenamePattern::parse(pattern).map_err(|error| error.to_string())?; |
| 2018 |
let nodes = self.state.selected_nodes(); |
| 2019 |
let contexts: Vec<RenameContext> = nodes |
| 2020 |
.iter() |
| 2021 |
.enumerate() |
| 2022 |
.map(|(index, node)| { |
| 2023 |
let (name, extension) = audiofiles_core::util::split_name_ext(&node.node.name); |
| 2024 |
RenameContext { |
| 2025 |
name, |
| 2026 |
extension, |
| 2027 |
bpm: node.bpm, |
| 2028 |
musical_key: node.musical_key.clone(), |
| 2029 |
duration: node.duration, |
| 2030 |
index, |
| 2031 |
} |
| 2032 |
}) |
| 2033 |
.collect(); |
| 2034 |
Ok(contexts |
| 2035 |
.iter() |
| 2036 |
.zip(parsed.resolve_all(&contexts)) |
| 2037 |
.map(|(context, stem)| { |
| 2038 |
( |
| 2039 |
whole(&context.name, &context.extension), |
| 2040 |
whole(&stem, &context.extension), |
| 2041 |
) |
| 2042 |
}) |
| 2043 |
.collect()) |
| 2044 |
} |
| 2045 |
|
| 2046 |
fn tag(&self, tag: &str, adding: bool) { |
| 2047 |
self.intents |
| 2048 |
.borrow_mut() |
| 2049 |
.push(Intent::BulkTag(tag.to_owned(), adding)); |
| 2050 |
} |
| 2051 |
|
| 2052 |
fn move_to(&self, folder: Option<i64>) { |
| 2053 |
self.intents.borrow_mut().push(Intent::BulkMove(folder)); |
| 2054 |
} |
| 2055 |
|
| 2056 |
fn rename(&self, pattern: &str) { |
| 2057 |
self.intents |
| 2058 |
.borrow_mut() |
| 2059 |
.push(Intent::BulkRename(pattern.to_owned())); |
| 2060 |
} |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
fn whole(stem: &str, extension: &str) -> String { |
| 2065 |
if extension.is_empty() { |
| 2066 |
stem.to_owned() |
| 2067 |
} else { |
| 2068 |
format!("{stem}.{extension}") |
| 2069 |
} |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2080 |
pub struct Playing { |
| 2081 |
|
| 2082 |
pub name: String, |
| 2083 |
|
| 2084 |
pub position: u32, |
| 2085 |
|
| 2086 |
pub total: u32, |
| 2087 |
} |
| 2088 |
|
| 2089 |
|
| 2090 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 2091 |
pub struct Analysed { |
| 2092 |
|
| 2093 |
pub samples: u32, |
| 2094 |
|
| 2095 |
pub analysed: u32, |
| 2096 |
|
| 2097 |
pub untagged: u32, |
| 2098 |
} |
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 2108 |
pub enum Saying { |
| 2109 |
|
| 2110 |
Failed, |
| 2111 |
|
| 2112 |
Ordinary, |
| 2113 |
} |
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
pub trait Shell { |
| 2122 |
|
| 2123 |
fn playing(&self) -> Option<Playing>; |
| 2124 |
|
| 2125 |
|
| 2126 |
fn chosen(&self) -> usize; |
| 2127 |
|
| 2128 |
|
| 2129 |
fn analysed(&self) -> Analysed; |
| 2130 |
|
| 2131 |
|
| 2132 |
fn status(&self) -> Option<(String, Saying)>; |
| 2133 |
|
| 2134 |
|
| 2135 |
fn hinting(&self) -> bool; |
| 2136 |
|
| 2137 |
|
| 2138 |
fn device(&self) -> Option<String>; |
| 2139 |
|
| 2140 |
|
| 2141 |
fn tags(&self) -> Vec<String>; |
| 2142 |
|
| 2143 |
|
| 2144 |
fn migrating(&self) -> Option<Migrating>; |
| 2145 |
|
| 2146 |
|
| 2147 |
fn stop(&self); |
| 2148 |
|
| 2149 |
|
| 2150 |
fn dismiss_hint(&self); |
| 2151 |
|
| 2152 |
|
| 2153 |
fn pause_migration(&self); |
| 2154 |
} |
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 2168 |
pub struct Migrating { |
| 2169 |
|
| 2170 |
pub done: usize, |
| 2171 |
|
| 2172 |
pub total: usize, |
| 2173 |
} |
| 2174 |
|
| 2175 |
|
| 2176 |
pub struct FromWindow<'a> { |
| 2177 |
|
| 2178 |
pub state: &'a crate::state::BrowserState, |
| 2179 |
|
| 2180 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 2181 |
} |
| 2182 |
|
| 2183 |
impl Shell for FromWindow<'_> { |
| 2184 |
fn playing(&self) -> Option<Playing> { |
| 2185 |
let hash = self.state.preview.previewing_hash.as_deref()?; |
| 2186 |
let playback = self.state.shared.preview.lock(); |
| 2187 |
if !playback.playing { |
| 2188 |
return None; |
| 2189 |
} |
| 2190 |
let buffer = playback.buffer.as_ref()?; |
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
let frames = buffer.data.len() / 2; |
| 2195 |
let rate = f64::from(buffer.sample_rate); |
| 2196 |
if frames == 0 || rate <= 0.0 { |
| 2197 |
return None; |
| 2198 |
} |
| 2199 |
let name = self |
| 2200 |
.state |
| 2201 |
.nav |
| 2202 |
.contents |
| 2203 |
.iter() |
| 2204 |
.find(|node| node.node.sample_hash.as_deref() == Some(hash)) |
| 2205 |
.map_or("...", |node| node.node.name.as_str()) |
| 2206 |
.to_owned(); |
| 2207 |
Some(Playing { |
| 2208 |
name, |
| 2209 |
position: seconds(playback.position_frac / rate), |
| 2210 |
total: seconds(frames as f64 / rate), |
| 2211 |
}) |
| 2212 |
} |
| 2213 |
|
| 2214 |
fn chosen(&self) -> usize { |
| 2215 |
self.state.nav.selection.count() |
| 2216 |
} |
| 2217 |
|
| 2218 |
fn analysed(&self) -> Analysed { |
| 2219 |
let samples = self |
| 2220 |
.state |
| 2221 |
.nav |
| 2222 |
.contents |
| 2223 |
.iter() |
| 2224 |
.filter(|node| node.node.sample_hash.is_some()); |
| 2225 |
let mut seen = Analysed::default(); |
| 2226 |
for node in samples { |
| 2227 |
seen.samples += 1; |
| 2228 |
if node.duration.is_some() { |
| 2229 |
seen.analysed += 1; |
| 2230 |
} |
| 2231 |
if node.tags.is_empty() { |
| 2232 |
seen.untagged += 1; |
| 2233 |
} |
| 2234 |
} |
| 2235 |
seen |
| 2236 |
} |
| 2237 |
|
| 2238 |
fn status(&self) -> Option<(String, Saying)> { |
| 2239 |
if self.state.status.is_empty() { |
| 2240 |
return None; |
| 2241 |
} |
| 2242 |
Some(( |
| 2243 |
self.state.status.clone(), |
| 2244 |
if crate::ui::footer::is_error_status(&self.state.status) { |
| 2245 |
Saying::Failed |
| 2246 |
} else { |
| 2247 |
Saying::Ordinary |
| 2248 |
}, |
| 2249 |
)) |
| 2250 |
} |
| 2251 |
|
| 2252 |
fn hinting(&self) -> bool { |
| 2253 |
self.state.onboarding.show_first_launch_hint |
| 2254 |
} |
| 2255 |
|
| 2256 |
fn device(&self) -> Option<String> { |
| 2257 |
self.state.shared.preview_device_name.lock().clone() |
| 2258 |
} |
| 2259 |
|
| 2260 |
fn tags(&self) -> Vec<String> { |
| 2261 |
self.state.detail.selected_tags.as_ref().clone() |
| 2262 |
} |
| 2263 |
|
| 2264 |
fn stop(&self) { |
| 2265 |
self.intents.borrow_mut().push(Intent::StopPlayback); |
| 2266 |
} |
| 2267 |
|
| 2268 |
fn dismiss_hint(&self) { |
| 2269 |
self.intents.borrow_mut().push(Intent::DismissHint); |
| 2270 |
} |
| 2271 |
|
| 2272 |
fn migrating(&self) -> Option<Migrating> { |
| 2273 |
let running = self.state.layout_migration?; |
| 2274 |
Some(Migrating { |
| 2275 |
done: running.completed, |
| 2276 |
total: running.total, |
| 2277 |
}) |
| 2278 |
} |
| 2279 |
|
| 2280 |
fn pause_migration(&self) { |
| 2281 |
self.intents.borrow_mut().push(Intent::PauseMigration); |
| 2282 |
} |
| 2283 |
} |
| 2284 |
|
| 2285 |
|
| 2286 |
fn seconds(value: f64) -> u32 { |
| 2287 |
#[expect( |
| 2288 |
clippy::cast_possible_truncation, |
| 2289 |
clippy::cast_sign_loss, |
| 2290 |
reason = "a sample's length in seconds is small and positive" |
| 2291 |
)] |
| 2292 |
let whole = value.max(0.0) as u32; |
| 2293 |
whole |
| 2294 |
} |
| 2295 |
|
| 2296 |
|
| 2297 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2298 |
pub struct Vault { |
| 2299 |
|
| 2300 |
pub id: i64, |
| 2301 |
|
| 2302 |
pub name: String, |
| 2303 |
|
| 2304 |
pub current: bool, |
| 2305 |
} |
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 2313 |
pub enum Holding { |
| 2314 |
|
| 2315 |
Dynamic, |
| 2316 |
|
| 2317 |
Fixed(usize), |
| 2318 |
} |
| 2319 |
|
| 2320 |
|
| 2321 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2322 |
pub struct Collection { |
| 2323 |
|
| 2324 |
pub id: i64, |
| 2325 |
|
| 2326 |
pub name: String, |
| 2327 |
|
| 2328 |
pub holding: Holding, |
| 2329 |
|
| 2330 |
pub active: bool, |
| 2331 |
} |
| 2332 |
|
| 2333 |
|
| 2334 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2335 |
pub struct Filter { |
| 2336 |
|
| 2337 |
|
| 2338 |
pub path: String, |
| 2339 |
|
| 2340 |
pub on: bool, |
| 2341 |
} |
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
pub trait Library { |
| 2350 |
|
| 2351 |
fn vaults(&self) -> Vec<Vault>; |
| 2352 |
|
| 2353 |
|
| 2354 |
fn collections(&self) -> Vec<Collection>; |
| 2355 |
|
| 2356 |
|
| 2357 |
fn tags(&self) -> Vec<Filter>; |
| 2358 |
|
| 2359 |
|
| 2360 |
fn open_vault(&self, id: i64); |
| 2361 |
|
| 2362 |
|
| 2363 |
fn delete_vault(&self, id: i64); |
| 2364 |
|
| 2365 |
|
| 2366 |
fn toggle_tag(&self, path: &str); |
| 2367 |
|
| 2368 |
|
| 2369 |
fn remove_tag(&self, path: &str); |
| 2370 |
|
| 2371 |
|
| 2372 |
fn open_collection(&self, id: i64); |
| 2373 |
|
| 2374 |
|
| 2375 |
fn close_collection(&self); |
| 2376 |
|
| 2377 |
|
| 2378 |
fn delete_collection(&self, id: i64); |
| 2379 |
} |
| 2380 |
|
| 2381 |
|
| 2382 |
pub struct FromLibrary<'a> { |
| 2383 |
|
| 2384 |
pub state: &'a crate::state::BrowserState, |
| 2385 |
|
| 2386 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 2387 |
} |
| 2388 |
|
| 2389 |
impl Library for FromLibrary<'_> { |
| 2390 |
fn vaults(&self) -> Vec<Vault> { |
| 2391 |
self.state |
| 2392 |
.nav |
| 2393 |
.vfs_list |
| 2394 |
.iter() |
| 2395 |
.enumerate() |
| 2396 |
.map(|(at, vfs)| Vault { |
| 2397 |
id: vfs.id.as_i64(), |
| 2398 |
name: vfs.name.clone(), |
| 2399 |
current: at == self.state.nav.current_vfs_idx, |
| 2400 |
}) |
| 2401 |
.collect() |
| 2402 |
} |
| 2403 |
|
| 2404 |
fn collections(&self) -> Vec<Collection> { |
| 2405 |
let active = self.state.collections_ui.active_collection; |
| 2406 |
self.state |
| 2407 |
.collections_ui |
| 2408 |
.collections |
| 2409 |
.iter() |
| 2410 |
.map(|collection| Collection { |
| 2411 |
id: collection.id.as_i64(), |
| 2412 |
name: collection.name.clone(), |
| 2413 |
holding: if collection.is_dynamic() { |
| 2414 |
Holding::Dynamic |
| 2415 |
} else { |
| 2416 |
Holding::Fixed(collection.member_count) |
| 2417 |
}, |
| 2418 |
active: active == Some(collection.id), |
| 2419 |
}) |
| 2420 |
.collect() |
| 2421 |
} |
| 2422 |
|
| 2423 |
fn tags(&self) -> Vec<Filter> { |
| 2424 |
let on = &self.state.search.search_filter.required_tags; |
| 2425 |
self.state |
| 2426 |
.all_tags |
| 2427 |
.iter() |
| 2428 |
.map(|path| Filter { |
| 2429 |
on: on.contains(path), |
| 2430 |
path: path.clone(), |
| 2431 |
}) |
| 2432 |
.collect() |
| 2433 |
} |
| 2434 |
|
| 2435 |
fn open_vault(&self, id: i64) { |
| 2436 |
self.push(Intent::OpenVault(id)); |
| 2437 |
} |
| 2438 |
|
| 2439 |
fn delete_vault(&self, id: i64) { |
| 2440 |
self.push(Intent::DeleteVault(id)); |
| 2441 |
} |
| 2442 |
|
| 2443 |
fn toggle_tag(&self, path: &str) { |
| 2444 |
self.push(Intent::ToggleTag(path.to_owned())); |
| 2445 |
} |
| 2446 |
|
| 2447 |
fn remove_tag(&self, path: &str) { |
| 2448 |
self.push(Intent::RemoveTagEverywhere(path.to_owned())); |
| 2449 |
} |
| 2450 |
|
| 2451 |
fn open_collection(&self, id: i64) { |
| 2452 |
self.push(Intent::OpenCollection(id)); |
| 2453 |
} |
| 2454 |
|
| 2455 |
fn close_collection(&self) { |
| 2456 |
self.push(Intent::CloseCollection); |
| 2457 |
} |
| 2458 |
|
| 2459 |
fn delete_collection(&self, id: i64) { |
| 2460 |
self.push(Intent::DeleteCollection(id)); |
| 2461 |
} |
| 2462 |
} |
| 2463 |
|
| 2464 |
impl FromLibrary<'_> { |
| 2465 |
|
| 2466 |
fn push(&self, intent: Intent) { |
| 2467 |
self.intents.borrow_mut().push(intent); |
| 2468 |
} |
| 2469 |
} |
| 2470 |
|
| 2471 |
|
| 2472 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2473 |
pub struct Crumb { |
| 2474 |
|
| 2475 |
pub id: i64, |
| 2476 |
|
| 2477 |
pub name: String, |
| 2478 |
} |
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2487 |
pub enum Where { |
| 2488 |
|
| 2489 |
Folder { |
| 2490 |
|
| 2491 |
trail: Vec<Crumb>, |
| 2492 |
}, |
| 2493 |
|
| 2494 |
Collection { |
| 2495 |
|
| 2496 |
name: String, |
| 2497 |
}, |
| 2498 |
|
| 2499 |
Similar { |
| 2500 |
|
| 2501 |
name: String, |
| 2502 |
}, |
| 2503 |
} |
| 2504 |
|
| 2505 |
|
| 2506 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 2507 |
pub struct Searching { |
| 2508 |
|
| 2509 |
pub query: String, |
| 2510 |
|
| 2511 |
pub everywhere: bool, |
| 2512 |
|
| 2513 |
pub filtered: bool, |
| 2514 |
|
| 2515 |
pub results: usize, |
| 2516 |
|
| 2517 |
pub filters: usize, |
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
pub describes: String, |
| 2524 |
} |
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 2531 |
pub enum Panel { |
| 2532 |
|
| 2533 |
Sidebar, |
| 2534 |
|
| 2535 |
Detail, |
| 2536 |
|
| 2537 |
Edit, |
| 2538 |
|
| 2539 |
Instrument, |
| 2540 |
|
| 2541 |
Loop, |
| 2542 |
|
| 2543 |
Filters, |
| 2544 |
} |
| 2545 |
|
| 2546 |
impl Panel { |
| 2547 |
|
| 2548 |
pub const ALL: [Self; 6] = [ |
| 2549 |
Self::Sidebar, |
| 2550 |
Self::Detail, |
| 2551 |
Self::Edit, |
| 2552 |
Self::Instrument, |
| 2553 |
Self::Loop, |
| 2554 |
Self::Filters, |
| 2555 |
]; |
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
#[must_use] |
| 2578 |
pub const fn worth(self) -> quasi_router::layout::Priority { |
| 2579 |
use quasi_router::layout::Priority; |
| 2580 |
match self { |
| 2581 |
Self::Sidebar | Self::Detail => Priority::Essential, |
| 2582 |
Self::Filters => Priority::Secondary, |
| 2583 |
Self::Edit | Self::Instrument | Self::Loop => Priority::Optional, |
| 2584 |
} |
| 2585 |
} |
| 2586 |
|
| 2587 |
|
| 2588 |
#[must_use] |
| 2589 |
pub const fn as_str(self) -> &'static str { |
| 2590 |
match self { |
| 2591 |
Self::Sidebar => "sidebar", |
| 2592 |
Self::Detail => "detail", |
| 2593 |
Self::Edit => "edit", |
| 2594 |
Self::Instrument => "instrument", |
| 2595 |
Self::Loop => "loop", |
| 2596 |
Self::Filters => "filters", |
| 2597 |
} |
| 2598 |
} |
| 2599 |
|
| 2600 |
|
| 2601 |
#[must_use] |
| 2602 |
pub const fn label(self) -> &'static str { |
| 2603 |
match self { |
| 2604 |
Self::Sidebar => "Sidebar", |
| 2605 |
Self::Detail => "Detail", |
| 2606 |
Self::Edit => "Edit", |
| 2607 |
Self::Instrument => "Instrument", |
| 2608 |
Self::Loop => "Loop", |
| 2609 |
Self::Filters => "Filters", |
| 2610 |
} |
| 2611 |
} |
| 2612 |
|
| 2613 |
|
| 2614 |
#[must_use] |
| 2615 |
pub fn from_key(name: &str) -> Option<Self> { |
| 2616 |
Self::ALL.into_iter().find(|panel| panel.as_str() == name) |
| 2617 |
} |
| 2618 |
} |
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
pub trait Bar { |
| 2624 |
|
| 2625 |
fn place(&self) -> Where; |
| 2626 |
|
| 2627 |
|
| 2628 |
fn searching(&self) -> Searching; |
| 2629 |
|
| 2630 |
|
| 2631 |
fn showing(&self) -> Vec<Panel>; |
| 2632 |
|
| 2633 |
|
| 2634 |
fn undoable(&self) -> bool; |
| 2635 |
|
| 2636 |
|
| 2637 |
fn search(&self, query: &str); |
| 2638 |
|
| 2639 |
|
| 2640 |
fn set_scope(&self, everywhere: bool); |
| 2641 |
|
| 2642 |
|
| 2643 |
fn save_collection(&self, name: &str); |
| 2644 |
|
| 2645 |
|
| 2646 |
fn undo(&self); |
| 2647 |
|
| 2648 |
|
| 2649 |
fn toggle(&self, panel: Panel); |
| 2650 |
|
| 2651 |
|
| 2652 |
fn go_root(&self); |
| 2653 |
|
| 2654 |
|
| 2655 |
fn go_to(&self, id: i64, depth: usize); |
| 2656 |
|
| 2657 |
|
| 2658 |
fn leave(&self); |
| 2659 |
} |
| 2660 |
|
| 2661 |
|
| 2662 |
pub struct FromBar<'a> { |
| 2663 |
|
| 2664 |
pub state: &'a crate::state::BrowserState, |
| 2665 |
|
| 2666 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 2667 |
} |
| 2668 |
|
| 2669 |
impl Bar for FromBar<'_> { |
| 2670 |
fn place(&self) -> Where { |
| 2671 |
if self.state.search.similarity_search_hash.is_some() { |
| 2672 |
return Where::Similar { |
| 2673 |
name: self |
| 2674 |
.state |
| 2675 |
.search |
| 2676 |
.similarity_source_name |
| 2677 |
.clone() |
| 2678 |
.unwrap_or_else(|| "sample".to_owned()), |
| 2679 |
}; |
| 2680 |
} |
| 2681 |
if let Some(active) = self.state.collections_ui.active_collection { |
| 2682 |
return Where::Collection { |
| 2683 |
name: self |
| 2684 |
.state |
| 2685 |
.collections_ui |
| 2686 |
.collections |
| 2687 |
.iter() |
| 2688 |
.find(|collection| collection.id == active) |
| 2689 |
.map_or_else(|| "Collection".to_owned(), |found| found.name.clone()), |
| 2690 |
}; |
| 2691 |
} |
| 2692 |
Where::Folder { |
| 2693 |
trail: self |
| 2694 |
.state |
| 2695 |
.nav |
| 2696 |
.breadcrumb |
| 2697 |
.iter() |
| 2698 |
.map(|crumb| Crumb { |
| 2699 |
id: crumb.id.as_i64(), |
| 2700 |
name: crumb.name.clone(), |
| 2701 |
}) |
| 2702 |
.collect(), |
| 2703 |
} |
| 2704 |
} |
| 2705 |
|
| 2706 |
fn searching(&self) -> Searching { |
| 2707 |
let filter = &self.state.search.search_filter; |
| 2708 |
Searching { |
| 2709 |
query: self.state.search.search_query.clone(), |
| 2710 |
everywhere: matches!(filter.scope, audiofiles_core::search::SearchScope::Global), |
| 2711 |
filtered: filter.is_active(), |
| 2712 |
results: self.state.nav.contents.len(), |
| 2713 |
filters: filter.active_count(), |
| 2714 |
describes: filter.describe(), |
| 2715 |
} |
| 2716 |
} |
| 2717 |
|
| 2718 |
fn showing(&self) -> Vec<Panel> { |
| 2719 |
let mut showing = Vec::new(); |
| 2720 |
if self.state.sidebar_visible { |
| 2721 |
showing.push(Panel::Sidebar); |
| 2722 |
} |
| 2723 |
if self.state.detail.detail_visible { |
| 2724 |
showing.push(Panel::Detail); |
| 2725 |
} |
| 2726 |
if self.state.edit.show_window { |
| 2727 |
showing.push(Panel::Edit); |
| 2728 |
} |
| 2729 |
if self.state.preview.show_midi_window { |
| 2730 |
showing.push(Panel::Instrument); |
| 2731 |
} |
| 2732 |
if self.state.preview.loop_enabled { |
| 2733 |
showing.push(Panel::Loop); |
| 2734 |
} |
| 2735 |
if self.state.search.filter_panel_open { |
| 2736 |
showing.push(Panel::Filters); |
| 2737 |
} |
| 2738 |
showing |
| 2739 |
} |
| 2740 |
|
| 2741 |
fn undoable(&self) -> bool { |
| 2742 |
self.state.can_undo() |
| 2743 |
} |
| 2744 |
|
| 2745 |
fn search(&self, query: &str) { |
| 2746 |
self.push(Intent::Search(query.to_owned())); |
| 2747 |
} |
| 2748 |
|
| 2749 |
fn set_scope(&self, everywhere: bool) { |
| 2750 |
self.push(Intent::Scope(everywhere)); |
| 2751 |
} |
| 2752 |
|
| 2753 |
fn save_collection(&self, name: &str) { |
| 2754 |
self.push(Intent::SaveCollection(name.to_owned())); |
| 2755 |
} |
| 2756 |
|
| 2757 |
fn undo(&self) { |
| 2758 |
self.push(Intent::Undo); |
| 2759 |
} |
| 2760 |
|
| 2761 |
fn toggle(&self, panel: Panel) { |
| 2762 |
self.push(Intent::TogglePanel(panel)); |
| 2763 |
} |
| 2764 |
|
| 2765 |
fn go_root(&self) { |
| 2766 |
self.push(Intent::GoRoot); |
| 2767 |
} |
| 2768 |
|
| 2769 |
fn go_to(&self, id: i64, depth: usize) { |
| 2770 |
self.push(Intent::GoTo(id, depth)); |
| 2771 |
} |
| 2772 |
|
| 2773 |
fn leave(&self) { |
| 2774 |
self.push(Intent::Leave); |
| 2775 |
} |
| 2776 |
} |
| 2777 |
|
| 2778 |
impl FromBar<'_> { |
| 2779 |
|
| 2780 |
fn push(&self, intent: Intent) { |
| 2781 |
self.intents.borrow_mut().push(intent); |
| 2782 |
} |
| 2783 |
} |
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
pub trait Naming { |
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
fn done(&self); |
| 2807 |
|
| 2808 |
|
| 2809 |
fn vault(&self, id: i64) -> Option<String>; |
| 2810 |
|
| 2811 |
|
| 2812 |
fn folder(&self, id: i64) -> Option<String>; |
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
fn create_vault(&self, name: &str) -> Result<String, String>; |
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
fn rename_vault(&self, id: i64, name: &str) -> Result<String, String>; |
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
fn create_folder(&self, name: &str) -> Result<String, String>; |
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
fn rename_folder(&self, id: i64, name: &str) -> Result<String, String>; |
| 2837 |
} |
| 2838 |
|
| 2839 |
|
| 2840 |
pub struct FromNaming<'a> { |
| 2841 |
|
| 2842 |
pub state: &'a crate::state::BrowserState, |
| 2843 |
|
| 2844 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 2845 |
} |
| 2846 |
|
| 2847 |
impl FromNaming<'_> { |
| 2848 |
|
| 2849 |
|
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
fn vault_id(&self, id: i64) -> Option<audiofiles_core::id_types::VfsId> { |
| 2854 |
self.state |
| 2855 |
.nav |
| 2856 |
.vfs_list |
| 2857 |
.iter() |
| 2858 |
.find(|vfs| vfs.id.as_i64() == id) |
| 2859 |
.map(|vfs| vfs.id) |
| 2860 |
} |
| 2861 |
|
| 2862 |
|
| 2863 |
fn folder_id(&self, id: i64) -> Option<audiofiles_core::id_types::NodeId> { |
| 2864 |
self.state |
| 2865 |
.nav |
| 2866 |
.contents |
| 2867 |
.iter() |
| 2868 |
.map(|node| &node.node) |
| 2869 |
.find(|node| node.id.as_i64() == id && node.sample_hash.is_none()) |
| 2870 |
.map(|node| node.id) |
| 2871 |
} |
| 2872 |
|
| 2873 |
|
| 2874 |
fn changed(&self, intent: Intent, say: String) -> Result<String, String> { |
| 2875 |
self.intents.borrow_mut().push(intent); |
| 2876 |
Ok(say) |
| 2877 |
} |
| 2878 |
} |
| 2879 |
|
| 2880 |
impl Naming for FromNaming<'_> { |
| 2881 |
fn done(&self) { |
| 2882 |
self.intents.borrow_mut().push(Intent::NamingDone); |
| 2883 |
} |
| 2884 |
|
| 2885 |
fn vault(&self, id: i64) -> Option<String> { |
| 2886 |
self.state |
| 2887 |
.nav |
| 2888 |
.vfs_list |
| 2889 |
.iter() |
| 2890 |
.find(|vfs| vfs.id.as_i64() == id) |
| 2891 |
.map(|vfs| vfs.name.clone()) |
| 2892 |
} |
| 2893 |
|
| 2894 |
fn folder(&self, id: i64) -> Option<String> { |
| 2895 |
self.state |
| 2896 |
.nav |
| 2897 |
.contents |
| 2898 |
.iter() |
| 2899 |
.map(|node| &node.node) |
| 2900 |
.find(|node| node.id.as_i64() == id && node.sample_hash.is_none()) |
| 2901 |
.map(|node| node.name.clone()) |
| 2902 |
} |
| 2903 |
|
| 2904 |
fn create_vault(&self, name: &str) -> Result<String, String> { |
| 2905 |
self.state |
| 2906 |
.backend |
| 2907 |
.create_vfs(name) |
| 2908 |
.map_err(|error| error.to_string())?; |
| 2909 |
let say = format!("Created vault: {name}"); |
| 2910 |
self.changed(Intent::VaultsChanged(say.clone()), say) |
| 2911 |
} |
| 2912 |
|
| 2913 |
fn rename_vault(&self, id: i64, name: &str) -> Result<String, String> { |
| 2914 |
let vault = self |
| 2915 |
.vault_id(id) |
| 2916 |
.ok_or_else(|| "No such vault".to_owned())?; |
| 2917 |
self.state |
| 2918 |
.backend |
| 2919 |
.rename_vfs(vault, name) |
| 2920 |
.map_err(|error| error.to_string())?; |
| 2921 |
let say = format!("Renamed vault to: {name}"); |
| 2922 |
self.changed(Intent::VaultsChanged(say.clone()), say) |
| 2923 |
} |
| 2924 |
|
| 2925 |
fn create_folder(&self, name: &str) -> Result<String, String> { |
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
let vault = self |
| 2930 |
.state |
| 2931 |
.current_vfs_id() |
| 2932 |
.ok_or_else(|| "No vault selected".to_owned())?; |
| 2933 |
self.state |
| 2934 |
.backend |
| 2935 |
.create_directory(vault, self.state.nav.current_dir, name) |
| 2936 |
.map_err(|error| error.to_string())?; |
| 2937 |
let say = format!("Created folder: {name}"); |
| 2938 |
self.changed(Intent::ContentsChanged(say.clone()), say) |
| 2939 |
} |
| 2940 |
|
| 2941 |
fn rename_folder(&self, id: i64, name: &str) -> Result<String, String> { |
| 2942 |
let node = self |
| 2943 |
.folder_id(id) |
| 2944 |
.ok_or_else(|| "No such folder".to_owned())?; |
| 2945 |
self.state |
| 2946 |
.backend |
| 2947 |
.rename_node(node, name) |
| 2948 |
.map_err(|error| error.to_string())?; |
| 2949 |
let say = format!("Renamed to: {name}"); |
| 2950 |
self.changed(Intent::ContentsChanged(say.clone()), say) |
| 2951 |
} |
| 2952 |
} |
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
#[derive(Debug, Clone, PartialEq)] |
| 2970 |
pub enum Stage { |
| 2971 |
|
| 2972 |
Idle, |
| 2973 |
|
| 2974 |
Configuring { |
| 2975 |
|
| 2976 |
source: String, |
| 2977 |
|
| 2978 |
files: usize, |
| 2979 |
|
| 2980 |
strategy: Strategy, |
| 2981 |
|
| 2982 |
vault_name: String, |
| 2983 |
|
| 2984 |
vaults: Vec<VaultChoice>, |
| 2985 |
|
| 2986 |
merging_into: usize, |
| 2987 |
}, |
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
Scanning { |
| 2995 |
|
| 2996 |
|
| 2997 |
found: usize, |
| 2998 |
|
| 2999 |
size: Option<String>, |
| 3000 |
}, |
| 3001 |
|
| 3002 |
Copying { |
| 3003 |
|
| 3004 |
done: usize, |
| 3005 |
|
| 3006 |
total: usize, |
| 3007 |
|
| 3008 |
current: String, |
| 3009 |
|
| 3010 |
size: Option<String>, |
| 3011 |
|
| 3012 |
in_place: bool, |
| 3013 |
|
| 3014 |
failures: Vec<Failure>, |
| 3015 |
}, |
| 3016 |
|
| 3017 |
Tagging { |
| 3018 |
|
| 3019 |
folders: Vec<FolderTags>, |
| 3020 |
}, |
| 3021 |
|
| 3022 |
Choosing { |
| 3023 |
|
| 3024 |
samples: usize, |
| 3025 |
|
| 3026 |
measures: Measures, |
| 3027 |
|
| 3028 |
resumable: bool, |
| 3029 |
}, |
| 3030 |
|
| 3031 |
Analysing { |
| 3032 |
|
| 3033 |
done: usize, |
| 3034 |
|
| 3035 |
total: usize, |
| 3036 |
|
| 3037 |
current: String, |
| 3038 |
|
| 3039 |
failures: Vec<Failure>, |
| 3040 |
}, |
| 3041 |
|
| 3042 |
Reviewing { |
| 3043 |
|
| 3044 |
items: Vec<Reviewed>, |
| 3045 |
|
| 3046 |
at: usize, |
| 3047 |
|
| 3048 |
order: Order, |
| 3049 |
}, |
| 3050 |
|
| 3051 |
Summary { |
| 3052 |
|
| 3053 |
rejected: Vec<Failure>, |
| 3054 |
|
| 3055 |
unanalysed: Vec<Failure>, |
| 3056 |
}, |
| 3057 |
|
| 3058 |
Stopped { |
| 3059 |
|
| 3060 |
what: Halted, |
| 3061 |
|
| 3062 |
done: usize, |
| 3063 |
|
| 3064 |
total: usize, |
| 3065 |
}, |
| 3066 |
} |
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3075 |
pub enum Strategy { |
| 3076 |
|
| 3077 |
Flat, |
| 3078 |
|
| 3079 |
NewVault, |
| 3080 |
|
| 3081 |
Merge, |
| 3082 |
} |
| 3083 |
|
| 3084 |
impl Strategy { |
| 3085 |
|
| 3086 |
#[must_use] |
| 3087 |
pub const fn as_str(self) -> &'static str { |
| 3088 |
match self { |
| 3089 |
Self::Flat => "flat", |
| 3090 |
Self::NewVault => "new", |
| 3091 |
Self::Merge => "merge", |
| 3092 |
} |
| 3093 |
} |
| 3094 |
|
| 3095 |
|
| 3096 |
#[must_use] |
| 3097 |
pub fn from_key(name: &str) -> Option<Self> { |
| 3098 |
match name { |
| 3099 |
"flat" => Some(Self::Flat), |
| 3100 |
"new" => Some(Self::NewVault), |
| 3101 |
"merge" => Some(Self::Merge), |
| 3102 |
_ => None, |
| 3103 |
} |
| 3104 |
} |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 3114 |
pub struct VaultChoice { |
| 3115 |
|
| 3116 |
pub name: String, |
| 3117 |
} |
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
|
| 3123 |
|
| 3124 |
|
| 3125 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 3126 |
pub struct Failure { |
| 3127 |
|
| 3128 |
pub name: String, |
| 3129 |
|
| 3130 |
pub error: String, |
| 3131 |
} |
| 3132 |
|
| 3133 |
|
| 3134 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 3135 |
pub struct FolderTags { |
| 3136 |
|
| 3137 |
pub name: String, |
| 3138 |
|
| 3139 |
pub samples: usize, |
| 3140 |
|
| 3141 |
pub typed: String, |
| 3142 |
|
| 3143 |
|
| 3144 |
|
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
pub invalid: Vec<String>, |
| 3149 |
} |
| 3150 |
|
| 3151 |
|
| 3152 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3153 |
pub struct Measures { |
| 3154 |
|
| 3155 |
pub loudness: bool, |
| 3156 |
|
| 3157 |
pub bpm: bool, |
| 3158 |
|
| 3159 |
pub key: bool, |
| 3160 |
|
| 3161 |
pub spectral: bool, |
| 3162 |
|
| 3163 |
pub loops: bool, |
| 3164 |
|
| 3165 |
pub suggestions: bool, |
| 3166 |
|
| 3167 |
pub fingerprint: bool, |
| 3168 |
|
| 3169 |
pub smart_skip: bool, |
| 3170 |
} |
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3178 |
pub enum Measure { |
| 3179 |
|
| 3180 |
Loudness, |
| 3181 |
|
| 3182 |
Bpm, |
| 3183 |
|
| 3184 |
Key, |
| 3185 |
|
| 3186 |
Spectral, |
| 3187 |
|
| 3188 |
Loops, |
| 3189 |
|
| 3190 |
Suggestions, |
| 3191 |
|
| 3192 |
Fingerprint, |
| 3193 |
|
| 3194 |
SmartSkip, |
| 3195 |
} |
| 3196 |
|
| 3197 |
impl Measure { |
| 3198 |
|
| 3199 |
pub const ALL: [Self; 8] = [ |
| 3200 |
Self::Loudness, |
| 3201 |
Self::Bpm, |
| 3202 |
Self::Key, |
| 3203 |
Self::Spectral, |
| 3204 |
Self::Loops, |
| 3205 |
Self::Suggestions, |
| 3206 |
Self::Fingerprint, |
| 3207 |
Self::SmartSkip, |
| 3208 |
]; |
| 3209 |
|
| 3210 |
|
| 3211 |
#[must_use] |
| 3212 |
pub const fn as_str(self) -> &'static str { |
| 3213 |
match self { |
| 3214 |
Self::Loudness => "loudness", |
| 3215 |
Self::Bpm => "bpm", |
| 3216 |
Self::Key => "key", |
| 3217 |
Self::Spectral => "spectral", |
| 3218 |
Self::Loops => "loops", |
| 3219 |
Self::Suggestions => "suggestions", |
| 3220 |
Self::Fingerprint => "fingerprint", |
| 3221 |
Self::SmartSkip => "smart-skip", |
| 3222 |
} |
| 3223 |
} |
| 3224 |
|
| 3225 |
|
| 3226 |
#[must_use] |
| 3227 |
pub const fn label(self) -> &'static str { |
| 3228 |
match self { |
| 3229 |
Self::Loudness => "Loudness (peak, RMS, LUFS)", |
| 3230 |
Self::Bpm => "BPM detection", |
| 3231 |
Self::Key => "Key detection", |
| 3232 |
Self::Spectral => "Spectral features", |
| 3233 |
Self::Loops => "Loop detection", |
| 3234 |
Self::Suggestions => "Auto-suggest tags", |
| 3235 |
Self::Fingerprint => "Fingerprint (duplicate detection)", |
| 3236 |
Self::SmartSkip => "Smart skip (skip BPM/key where they cannot apply)", |
| 3237 |
} |
| 3238 |
} |
| 3239 |
|
| 3240 |
|
| 3241 |
#[must_use] |
| 3242 |
pub fn from_key(name: &str) -> Option<Self> { |
| 3243 |
Self::ALL.into_iter().find(|held| held.as_str() == name) |
| 3244 |
} |
| 3245 |
|
| 3246 |
|
| 3247 |
#[must_use] |
| 3248 |
pub const fn read(self, measures: &Measures) -> bool { |
| 3249 |
match self { |
| 3250 |
Self::Loudness => measures.loudness, |
| 3251 |
Self::Bpm => measures.bpm, |
| 3252 |
Self::Key => measures.key, |
| 3253 |
Self::Spectral => measures.spectral, |
| 3254 |
Self::Loops => measures.loops, |
| 3255 |
Self::Suggestions => measures.suggestions, |
| 3256 |
Self::Fingerprint => measures.fingerprint, |
| 3257 |
Self::SmartSkip => measures.smart_skip, |
| 3258 |
} |
| 3259 |
} |
| 3260 |
} |
| 3261 |
|
| 3262 |
|
| 3263 |
#[derive(Debug, Clone, PartialEq)] |
| 3264 |
pub struct Reviewed { |
| 3265 |
|
| 3266 |
pub name: String, |
| 3267 |
|
| 3268 |
pub duration: f64, |
| 3269 |
|
| 3270 |
pub sample_rate: u32, |
| 3271 |
|
| 3272 |
pub peak_db: Option<f64>, |
| 3273 |
|
| 3274 |
pub bpm: Option<f64>, |
| 3275 |
|
| 3276 |
pub musical_key: Option<String>, |
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
pub suggestions: Vec<Suggestion>, |
| 3284 |
} |
| 3285 |
|
| 3286 |
|
| 3287 |
#[derive(Debug, Clone, PartialEq)] |
| 3288 |
pub struct Suggestion { |
| 3289 |
|
| 3290 |
pub tag: String, |
| 3291 |
|
| 3292 |
pub confidence: f32, |
| 3293 |
|
| 3294 |
pub reason: String, |
| 3295 |
|
| 3296 |
pub accepted: bool, |
| 3297 |
} |
| 3298 |
|
| 3299 |
|
| 3300 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3301 |
pub enum Order { |
| 3302 |
|
| 3303 |
Arrival, |
| 3304 |
|
| 3305 |
Name, |
| 3306 |
|
| 3307 |
Suggestions, |
| 3308 |
|
| 3309 |
Accepted, |
| 3310 |
} |
| 3311 |
|
| 3312 |
impl Order { |
| 3313 |
|
| 3314 |
pub const ALL: [Self; 4] = [Self::Arrival, Self::Name, Self::Suggestions, Self::Accepted]; |
| 3315 |
|
| 3316 |
|
| 3317 |
#[must_use] |
| 3318 |
pub const fn as_str(self) -> &'static str { |
| 3319 |
match self { |
| 3320 |
Self::Arrival => "arrival", |
| 3321 |
Self::Name => "name", |
| 3322 |
Self::Suggestions => "suggestions", |
| 3323 |
Self::Accepted => "accepted", |
| 3324 |
} |
| 3325 |
} |
| 3326 |
|
| 3327 |
|
| 3328 |
#[must_use] |
| 3329 |
pub const fn label(self) -> &'static str { |
| 3330 |
match self { |
| 3331 |
Self::Arrival => "Import order", |
| 3332 |
Self::Name => "Name", |
| 3333 |
Self::Suggestions => "Suggestions", |
| 3334 |
Self::Accepted => "Accepted", |
| 3335 |
} |
| 3336 |
} |
| 3337 |
|
| 3338 |
|
| 3339 |
#[must_use] |
| 3340 |
pub fn from_key(name: &str) -> Option<Self> { |
| 3341 |
Self::ALL.into_iter().find(|held| held.as_str() == name) |
| 3342 |
} |
| 3343 |
} |
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3352 |
pub enum Decision { |
| 3353 |
|
| 3354 |
Strategy, |
| 3355 |
|
| 3356 |
VaultName, |
| 3357 |
|
| 3358 |
MergeVault, |
| 3359 |
} |
| 3360 |
|
| 3361 |
impl Decision { |
| 3362 |
|
| 3363 |
#[must_use] |
| 3364 |
pub const fn as_str(self) -> &'static str { |
| 3365 |
match self { |
| 3366 |
Self::Strategy => "strategy", |
| 3367 |
Self::VaultName => "vault-name", |
| 3368 |
Self::MergeVault => "merge-vault", |
| 3369 |
} |
| 3370 |
} |
| 3371 |
|
| 3372 |
|
| 3373 |
#[must_use] |
| 3374 |
pub fn from_key(name: &str) -> Option<Self> { |
| 3375 |
match name { |
| 3376 |
"strategy" => Some(Self::Strategy), |
| 3377 |
"vault-name" => Some(Self::VaultName), |
| 3378 |
"merge-vault" => Some(Self::MergeVault), |
| 3379 |
_ => None, |
| 3380 |
} |
| 3381 |
} |
| 3382 |
} |
| 3383 |
|
| 3384 |
|
| 3385 |
|
| 3386 |
|
| 3387 |
|
| 3388 |
|
| 3389 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 3390 |
pub enum Halted { |
| 3391 |
|
| 3392 |
Import, |
| 3393 |
|
| 3394 |
Analysis, |
| 3395 |
} |
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 3407 |
pub struct Sweep { |
| 3408 |
|
| 3409 |
pub done: usize, |
| 3410 |
|
| 3411 |
pub total: usize, |
| 3412 |
|
| 3413 |
pub current: String, |
| 3414 |
} |
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 3423 |
pub struct Preflight { |
| 3424 |
|
| 3425 |
pub source: String, |
| 3426 |
|
| 3427 |
pub files: usize, |
| 3428 |
|
| 3429 |
pub size: String, |
| 3430 |
} |
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
pub trait Importing { |
| 3448 |
|
| 3449 |
fn waiting(&self) -> Option<Preflight>; |
| 3450 |
|
| 3451 |
|
| 3452 |
fn accept(&self, again: bool); |
| 3453 |
|
| 3454 |
|
| 3455 |
fn cancel(&self); |
| 3456 |
|
| 3457 |
|
| 3458 |
fn stage(&self) -> Stage; |
| 3459 |
|
| 3460 |
|
| 3461 |
fn sweeping(&self) -> Option<Sweep>; |
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
fn open_folder(&self); |
| 3469 |
|
| 3470 |
|
| 3471 |
fn open_quickly(&self); |
| 3472 |
|
| 3473 |
|
| 3474 |
fn open_files(&self); |
| 3475 |
|
| 3476 |
|
| 3477 |
fn change_source(&self); |
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
fn decide(&self, decision: Decision, value: &str); |
| 3483 |
|
| 3484 |
|
| 3485 |
fn begin(&self); |
| 3486 |
|
| 3487 |
|
| 3488 |
fn stop(&self); |
| 3489 |
|
| 3490 |
|
| 3491 |
fn retry(&self); |
| 3492 |
|
| 3493 |
|
| 3494 |
fn dismiss(&self); |
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
fn tag_folder(&self, at: usize, typed: &str); |
| 3500 |
|
| 3501 |
|
| 3502 |
fn tag_every_folder(&self, typed: &str); |
| 3503 |
|
| 3504 |
|
| 3505 |
fn apply_folder_tags(&self); |
| 3506 |
|
| 3507 |
|
| 3508 |
fn skip_folder_tags(&self); |
| 3509 |
|
| 3510 |
|
| 3511 |
|
| 3512 |
|
| 3513 |
fn measure(&self, measure: Measure, wanted: bool); |
| 3514 |
|
| 3515 |
|
| 3516 |
fn analyse(&self); |
| 3517 |
|
| 3518 |
|
| 3519 |
fn back_to_tagging(&self); |
| 3520 |
|
| 3521 |
|
| 3522 |
fn skip_analysis(&self); |
| 3523 |
|
| 3524 |
|
| 3525 |
fn stop_analysis(&self); |
| 3526 |
|
| 3527 |
|
| 3528 |
fn retry_analysis(&self); |
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
fn order(&self, order: Order); |
| 3534 |
|
| 3535 |
|
| 3536 |
fn read(&self, at: usize); |
| 3537 |
|
| 3538 |
|
| 3539 |
fn judge(&self, at: usize, tag: &str, accepted: bool); |
| 3540 |
|
| 3541 |
|
| 3542 |
fn judge_all(&self, accepted: bool); |
| 3543 |
|
| 3544 |
|
| 3545 |
fn apply_suggestions(&self); |
| 3546 |
|
| 3547 |
|
| 3548 |
fn discard_suggestions(&self); |
| 3549 |
|
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
fn keep_failed(&self); |
| 3554 |
|
| 3555 |
|
| 3556 |
fn purge_failed(&self, at: Option<usize>); |
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
fn stop_sweep(&self); |
| 3562 |
} |
| 3563 |
|
| 3564 |
|
| 3565 |
pub struct FromImport<'a> { |
| 3566 |
|
| 3567 |
pub state: &'a crate::state::BrowserState, |
| 3568 |
|
| 3569 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 3570 |
} |
| 3571 |
|
| 3572 |
impl Importing for FromImport<'_> { |
| 3573 |
fn waiting(&self) -> Option<Preflight> { |
| 3574 |
let waiting = self.state.import_wf.pending_import_preflight.as_ref()?; |
| 3575 |
Some(Preflight { |
| 3576 |
source: waiting.source.display().to_string(), |
| 3577 |
files: waiting.file_count, |
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
size: crate::ui::widgets::format_bytes(waiting.total_bytes), |
| 3583 |
}) |
| 3584 |
} |
| 3585 |
|
| 3586 |
fn accept(&self, again: bool) { |
| 3587 |
self.push(Intent::AcceptImport { again }); |
| 3588 |
} |
| 3589 |
|
| 3590 |
fn cancel(&self) { |
| 3591 |
self.push(Intent::CancelImport); |
| 3592 |
} |
| 3593 |
|
| 3594 |
fn stage(&self) -> Stage { |
| 3595 |
use crate::state::ImportMode; |
| 3596 |
|
| 3597 |
match &self.state.import_wf.import_mode { |
| 3598 |
ImportMode::ConfigureImport { |
| 3599 |
source, |
| 3600 |
strategy, |
| 3601 |
available_vfs, |
| 3602 |
selected_merge_vfs_idx, |
| 3603 |
new_vfs_name, |
| 3604 |
audio_file_count, |
| 3605 |
.. |
| 3606 |
} => Stage::Configuring { |
| 3607 |
source: source.display().to_string(), |
| 3608 |
files: *audio_file_count, |
| 3609 |
strategy: match strategy { |
| 3610 |
crate::import::ImportStrategy::Flat { .. } => Strategy::Flat, |
| 3611 |
crate::import::ImportStrategy::NewVfs { .. } => Strategy::NewVault, |
| 3612 |
crate::import::ImportStrategy::MergeIntoVfs { .. } => Strategy::Merge, |
| 3613 |
}, |
| 3614 |
vault_name: new_vfs_name.clone(), |
| 3615 |
vaults: available_vfs |
| 3616 |
.iter() |
| 3617 |
.map(|vfs| VaultChoice { |
| 3618 |
name: vfs.name.clone(), |
| 3619 |
}) |
| 3620 |
.collect(), |
| 3621 |
merging_into: *selected_merge_vfs_idx, |
| 3622 |
}, |
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
|
| 3627 |
ImportMode::Importing { |
| 3628 |
walking: true, |
| 3629 |
walking_count, |
| 3630 |
total_bytes, |
| 3631 |
.. |
| 3632 |
} => Stage::Scanning { |
| 3633 |
found: *walking_count, |
| 3634 |
size: Self::size(*total_bytes), |
| 3635 |
}, |
| 3636 |
ImportMode::Importing { |
| 3637 |
total, |
| 3638 |
completed, |
| 3639 |
current_name, |
| 3640 |
total_bytes, |
| 3641 |
loose_files, |
| 3642 |
.. |
| 3643 |
} => Stage::Copying { |
| 3644 |
done: *completed, |
| 3645 |
total: *total, |
| 3646 |
current: current_name.clone(), |
| 3647 |
size: Self::size(*total_bytes), |
| 3648 |
in_place: *loose_files, |
| 3649 |
failures: self.failures(), |
| 3650 |
}, |
| 3651 |
ImportMode::TagFolders { entries, .. } => Stage::Tagging { |
| 3652 |
folders: entries |
| 3653 |
.iter() |
| 3654 |
.map(|entry| FolderTags { |
| 3655 |
name: entry.folder.name.clone(), |
| 3656 |
samples: entry.folder.samples.len(), |
| 3657 |
typed: entry.tag_input.clone(), |
| 3658 |
invalid: invalid_tags(&entry.tag_input), |
| 3659 |
}) |
| 3660 |
.collect(), |
| 3661 |
}, |
| 3662 |
ImportMode::ConfigureAnalysis { |
| 3663 |
sample_hashes, |
| 3664 |
config, |
| 3665 |
} => Stage::Choosing { |
| 3666 |
samples: sample_hashes.len(), |
| 3667 |
measures: Measures { |
| 3668 |
loudness: config.loudness, |
| 3669 |
bpm: config.bpm, |
| 3670 |
key: config.key, |
| 3671 |
spectral: config.spectral, |
| 3672 |
loops: config.loop_detect, |
| 3673 |
suggestions: config.auto_suggest_tags, |
| 3674 |
fingerprint: config.fingerprint, |
| 3675 |
smart_skip: config.smart_skip, |
| 3676 |
}, |
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
resumable: self.state.import_wf.last_folder_tags.is_some(), |
| 3682 |
}, |
| 3683 |
ImportMode::Analyzing { |
| 3684 |
completed, |
| 3685 |
total, |
| 3686 |
current_name, |
| 3687 |
} => Stage::Analysing { |
| 3688 |
done: *completed, |
| 3689 |
total: *total, |
| 3690 |
current: current_name.clone(), |
| 3691 |
failures: self.failures(), |
| 3692 |
}, |
| 3693 |
ImportMode::ReviewSuggestions { |
| 3694 |
items, |
| 3695 |
current_idx, |
| 3696 |
sort, |
| 3697 |
} => Stage::Reviewing { |
| 3698 |
items: items.iter().map(reviewed).collect(), |
| 3699 |
at: *current_idx, |
| 3700 |
order: match sort { |
| 3701 |
crate::state::ReviewSort::ImportOrder => Order::Arrival, |
| 3702 |
crate::state::ReviewSort::Name => Order::Name, |
| 3703 |
crate::state::ReviewSort::Suggestions => Order::Suggestions, |
| 3704 |
crate::state::ReviewSort::Accepted => Order::Accepted, |
| 3705 |
}, |
| 3706 |
}, |
| 3707 |
ImportMode::ReviewErrors => Stage::Summary { |
| 3708 |
rejected: self |
| 3709 |
.state |
| 3710 |
.import_wf |
| 3711 |
.import_file_errors |
| 3712 |
.iter() |
| 3713 |
.map(|failure| Failure { |
| 3714 |
name: failure.path.clone(), |
| 3715 |
error: failure.error.clone(), |
| 3716 |
}) |
| 3717 |
.collect(), |
| 3718 |
unanalysed: self |
| 3719 |
.state |
| 3720 |
.import_wf |
| 3721 |
.analysis_errors |
| 3722 |
.iter() |
| 3723 |
.map(|failure| Failure { |
| 3724 |
name: failure.name.clone(), |
| 3725 |
error: failure.error.clone(), |
| 3726 |
}) |
| 3727 |
.collect(), |
| 3728 |
}, |
| 3729 |
ImportMode::OperationCancelled { |
| 3730 |
kind: kind @ (crate::state::CancelKind::Import | crate::state::CancelKind::Analysis), |
| 3731 |
completed, |
| 3732 |
total, |
| 3733 |
.. |
| 3734 |
} => Stage::Stopped { |
| 3735 |
what: match kind { |
| 3736 |
crate::state::CancelKind::Analysis => Halted::Analysis, |
| 3737 |
_ => Halted::Import, |
| 3738 |
}, |
| 3739 |
done: *completed, |
| 3740 |
total: *total, |
| 3741 |
}, |
| 3742 |
_ => Stage::Idle, |
| 3743 |
} |
| 3744 |
} |
| 3745 |
|
| 3746 |
fn sweeping(&self) -> Option<Sweep> { |
| 3747 |
match &self.state.import_wf.import_mode { |
| 3748 |
crate::state::ImportMode::Cleaning { |
| 3749 |
completed, |
| 3750 |
total, |
| 3751 |
current_name, |
| 3752 |
} => Some(Sweep { |
| 3753 |
done: *completed, |
| 3754 |
total: *total, |
| 3755 |
current: current_name.clone(), |
| 3756 |
}), |
| 3757 |
_ => None, |
| 3758 |
} |
| 3759 |
} |
| 3760 |
|
| 3761 |
fn open_folder(&self) { |
| 3762 |
self.push(Intent::OpenImportFolder); |
| 3763 |
} |
| 3764 |
|
| 3765 |
fn open_quickly(&self) { |
| 3766 |
self.push(Intent::OpenQuickImport); |
| 3767 |
} |
| 3768 |
|
| 3769 |
fn open_files(&self) { |
| 3770 |
self.push(Intent::OpenImportFiles); |
| 3771 |
} |
| 3772 |
|
| 3773 |
fn change_source(&self) { |
| 3774 |
self.push(Intent::ChangeImportSource); |
| 3775 |
} |
| 3776 |
|
| 3777 |
fn decide(&self, decision: Decision, value: &str) { |
| 3778 |
self.push(Intent::Decide(decision, value.to_owned())); |
| 3779 |
} |
| 3780 |
|
| 3781 |
fn begin(&self) { |
| 3782 |
self.push(Intent::BeginImport); |
| 3783 |
} |
| 3784 |
|
| 3785 |
fn stop(&self) { |
| 3786 |
self.push(Intent::StopImport); |
| 3787 |
} |
| 3788 |
|
| 3789 |
fn retry(&self) { |
| 3790 |
self.push(Intent::RetryImport); |
| 3791 |
} |
| 3792 |
|
| 3793 |
fn dismiss(&self) { |
| 3794 |
self.push(Intent::DismissImport); |
| 3795 |
} |
| 3796 |
|
| 3797 |
fn tag_folder(&self, at: usize, typed: &str) { |
| 3798 |
self.push(Intent::TagFolder(at, typed.to_owned())); |
| 3799 |
} |
| 3800 |
|
| 3801 |
fn tag_every_folder(&self, typed: &str) { |
| 3802 |
self.push(Intent::TagEveryFolder(typed.to_owned())); |
| 3803 |
} |
| 3804 |
|
| 3805 |
fn apply_folder_tags(&self) { |
| 3806 |
self.push(Intent::ApplyFolderTags); |
| 3807 |
} |
| 3808 |
|
| 3809 |
fn skip_folder_tags(&self) { |
| 3810 |
self.push(Intent::SkipFolderTags); |
| 3811 |
} |
| 3812 |
|
| 3813 |
fn measure(&self, measure: Measure, wanted: bool) { |
| 3814 |
self.push(Intent::Measure(measure, wanted)); |
| 3815 |
} |
| 3816 |
|
| 3817 |
fn analyse(&self) { |
| 3818 |
self.push(Intent::StartAnalysis); |
| 3819 |
} |
| 3820 |
|
| 3821 |
fn back_to_tagging(&self) { |
| 3822 |
self.push(Intent::BackToTagging); |
| 3823 |
} |
| 3824 |
|
| 3825 |
fn skip_analysis(&self) { |
| 3826 |
self.push(Intent::SkipAnalysis); |
| 3827 |
} |
| 3828 |
|
| 3829 |
fn stop_analysis(&self) { |
| 3830 |
self.push(Intent::StopAnalysis); |
| 3831 |
} |
| 3832 |
|
| 3833 |
fn retry_analysis(&self) { |
| 3834 |
self.push(Intent::RetryAnalysis); |
| 3835 |
} |
| 3836 |
|
| 3837 |
fn order(&self, order: Order) { |
| 3838 |
self.push(Intent::OrderReview(order)); |
| 3839 |
} |
| 3840 |
|
| 3841 |
fn read(&self, at: usize) { |
| 3842 |
self.push(Intent::ReadReviewed(at)); |
| 3843 |
} |
| 3844 |
|
| 3845 |
fn judge(&self, at: usize, tag: &str, accepted: bool) { |
| 3846 |
self.push(Intent::Judge { |
| 3847 |
at, |
| 3848 |
tag: tag.to_owned(), |
| 3849 |
accepted, |
| 3850 |
}); |
| 3851 |
} |
| 3852 |
|
| 3853 |
fn judge_all(&self, accepted: bool) { |
| 3854 |
self.push(Intent::JudgeAll(accepted)); |
| 3855 |
} |
| 3856 |
|
| 3857 |
fn apply_suggestions(&self) { |
| 3858 |
self.push(Intent::ApplySuggestions); |
| 3859 |
} |
| 3860 |
|
| 3861 |
fn discard_suggestions(&self) { |
| 3862 |
self.push(Intent::DiscardSuggestions); |
| 3863 |
} |
| 3864 |
|
| 3865 |
fn keep_failed(&self) { |
| 3866 |
self.push(Intent::KeepFailed); |
| 3867 |
} |
| 3868 |
|
| 3869 |
fn purge_failed(&self, at: Option<usize>) { |
| 3870 |
self.push(Intent::PurgeFailed(at)); |
| 3871 |
} |
| 3872 |
|
| 3873 |
fn stop_sweep(&self) { |
| 3874 |
self.push(Intent::StopSweep); |
| 3875 |
} |
| 3876 |
} |
| 3877 |
|
| 3878 |
impl FromImport<'_> { |
| 3879 |
|
| 3880 |
fn push(&self, intent: Intent) { |
| 3881 |
self.intents.borrow_mut().push(intent); |
| 3882 |
} |
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
fn size(bytes: u64) -> Option<String> { |
| 3890 |
(bytes > 0).then(|| crate::ui::widgets::format_bytes(bytes)) |
| 3891 |
} |
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
fn failures(&self) -> Vec<Failure> { |
| 3900 |
self.state |
| 3901 |
.import_wf |
| 3902 |
.import_file_errors |
| 3903 |
.iter() |
| 3904 |
.map(|failure| Failure { |
| 3905 |
name: failure.path.clone(), |
| 3906 |
error: failure.error.clone(), |
| 3907 |
}) |
| 3908 |
.chain( |
| 3909 |
self.state |
| 3910 |
.import_wf |
| 3911 |
.analysis_errors |
| 3912 |
.iter() |
| 3913 |
.map(|failure| Failure { |
| 3914 |
name: failure.name.clone(), |
| 3915 |
error: failure.error.clone(), |
| 3916 |
}), |
| 3917 |
) |
| 3918 |
.collect() |
| 3919 |
} |
| 3920 |
} |
| 3921 |
|
| 3922 |
|
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
|
| 3927 |
fn invalid_tags(typed: &str) -> Vec<String> { |
| 3928 |
typed |
| 3929 |
.split(',') |
| 3930 |
.map(str::trim) |
| 3931 |
.filter(|tag| !tag.is_empty() && audiofiles_core::tags::validate_tag(tag).is_err()) |
| 3932 |
.map(ToOwned::to_owned) |
| 3933 |
.collect() |
| 3934 |
} |
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
fn reviewed(item: &crate::state::ReviewItem) -> Reviewed { |
| 3944 |
let mut suggestions: Vec<Suggestion> = item |
| 3945 |
.suggestions |
| 3946 |
.iter() |
| 3947 |
.map(|held| Suggestion { |
| 3948 |
tag: held.suggestion.tag.clone(), |
| 3949 |
confidence: held.suggestion.confidence, |
| 3950 |
reason: held.suggestion.reason.clone(), |
| 3951 |
accepted: held.accepted, |
| 3952 |
}) |
| 3953 |
.collect(); |
| 3954 |
suggestions.sort_by(|a, b| { |
| 3955 |
b.confidence |
| 3956 |
.partial_cmp(&a.confidence) |
| 3957 |
.unwrap_or(std::cmp::Ordering::Equal) |
| 3958 |
}); |
| 3959 |
|
| 3960 |
Reviewed { |
| 3961 |
name: item.name.clone(), |
| 3962 |
duration: item.result.duration, |
| 3963 |
sample_rate: item.result.sample_rate, |
| 3964 |
peak_db: item.result.peak_db, |
| 3965 |
bpm: item.result.bpm, |
| 3966 |
musical_key: item.result.musical_key.clone(), |
| 3967 |
suggestions, |
| 3968 |
} |
| 3969 |
} |
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
|
| 3977 |
pub trait Integrity { |
| 3978 |
|
| 3979 |
fn missing(&self) -> usize; |
| 3980 |
|
| 3981 |
|
| 3982 |
fn dismiss(&self); |
| 3983 |
|
| 3984 |
|
| 3985 |
fn locate(&self); |
| 3986 |
|
| 3987 |
|
| 3988 |
fn purge(&self); |
| 3989 |
} |
| 3990 |
|
| 3991 |
|
| 3992 |
pub struct FromIntegrity<'a> { |
| 3993 |
|
| 3994 |
pub state: &'a crate::state::BrowserState, |
| 3995 |
|
| 3996 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 3997 |
} |
| 3998 |
|
| 3999 |
impl Integrity for FromIntegrity<'_> { |
| 4000 |
fn missing(&self) -> usize { |
| 4001 |
self.state.loose_files.loose_files_missing_count |
| 4002 |
} |
| 4003 |
|
| 4004 |
fn dismiss(&self) { |
| 4005 |
self.push(Intent::DismissLooseFiles); |
| 4006 |
} |
| 4007 |
|
| 4008 |
fn locate(&self) { |
| 4009 |
self.push(Intent::LocateLooseFiles); |
| 4010 |
} |
| 4011 |
|
| 4012 |
fn purge(&self) { |
| 4013 |
self.push(Intent::PurgeLooseFiles); |
| 4014 |
} |
| 4015 |
} |
| 4016 |
|
| 4017 |
impl FromIntegrity<'_> { |
| 4018 |
|
| 4019 |
fn push(&self, intent: Intent) { |
| 4020 |
self.intents.borrow_mut().push(intent); |
| 4021 |
} |
| 4022 |
} |
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
#[derive(Debug, Clone, PartialEq)] |
| 4031 |
pub struct Queued { |
| 4032 |
|
| 4033 |
pub groups: Vec<Group>, |
| 4034 |
|
| 4035 |
pub at: usize, |
| 4036 |
|
| 4037 |
pub considered: usize, |
| 4038 |
|
| 4039 |
pub suggested: usize, |
| 4040 |
|
| 4041 |
pub confident: usize, |
| 4042 |
|
| 4043 |
pub rescanning: bool, |
| 4044 |
|
| 4045 |
pub said: Option<String>, |
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
pub shown: Vec<Candidate>, |
| 4050 |
} |
| 4051 |
|
| 4052 |
|
| 4053 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 4054 |
pub struct Group { |
| 4055 |
|
| 4056 |
pub tag: String, |
| 4057 |
|
| 4058 |
pub candidates: usize, |
| 4059 |
|
| 4060 |
pub confident: usize, |
| 4061 |
|
| 4062 |
pub checked: usize, |
| 4063 |
} |
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
#[derive(Debug, Clone, PartialEq)] |
| 4077 |
pub struct Candidate { |
| 4078 |
|
| 4079 |
pub name: String, |
| 4080 |
|
| 4081 |
pub score: f64, |
| 4082 |
|
| 4083 |
pub confident: bool, |
| 4084 |
|
| 4085 |
pub accepted: bool, |
| 4086 |
} |
| 4087 |
|
| 4088 |
|
| 4089 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 4090 |
pub enum Scope { |
| 4091 |
|
| 4092 |
All, |
| 4093 |
|
| 4094 |
Confident, |
| 4095 |
|
| 4096 |
Checked, |
| 4097 |
} |
| 4098 |
|
| 4099 |
impl Scope { |
| 4100 |
|
| 4101 |
#[must_use] |
| 4102 |
pub const fn as_str(self) -> &'static str { |
| 4103 |
match self { |
| 4104 |
Self::All => "all", |
| 4105 |
Self::Confident => "confident", |
| 4106 |
Self::Checked => "checked", |
| 4107 |
} |
| 4108 |
} |
| 4109 |
|
| 4110 |
|
| 4111 |
#[must_use] |
| 4112 |
pub fn from_key(name: &str) -> Option<Self> { |
| 4113 |
match name { |
| 4114 |
"all" => Some(Self::All), |
| 4115 |
"confident" => Some(Self::Confident), |
| 4116 |
"checked" => Some(Self::Checked), |
| 4117 |
_ => None, |
| 4118 |
} |
| 4119 |
} |
| 4120 |
} |
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
|
| 4127 |
|
| 4128 |
pub trait Queue { |
| 4129 |
|
| 4130 |
fn queued(&self) -> Option<Queued>; |
| 4131 |
|
| 4132 |
|
| 4133 |
fn read(&self, at: usize); |
| 4134 |
|
| 4135 |
|
| 4136 |
fn tick(&self, at: usize); |
| 4137 |
|
| 4138 |
|
| 4139 |
fn tick_shown(&self, ticked: bool); |
| 4140 |
|
| 4141 |
|
| 4142 |
fn accept(&self, scope: Scope); |
| 4143 |
|
| 4144 |
|
| 4145 |
fn accept_confident(&self); |
| 4146 |
|
| 4147 |
|
| 4148 |
fn dismiss(&self); |
| 4149 |
|
| 4150 |
|
| 4151 |
fn rescan(&self); |
| 4152 |
|
| 4153 |
|
| 4154 |
fn close(&self); |
| 4155 |
} |
| 4156 |
|
| 4157 |
|
| 4158 |
pub struct FromQueue<'a> { |
| 4159 |
|
| 4160 |
pub state: &'a crate::state::BrowserState, |
| 4161 |
|
| 4162 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 4163 |
} |
| 4164 |
|
| 4165 |
impl Queue for FromQueue<'_> { |
| 4166 |
fn queued(&self) -> Option<Queued> { |
| 4167 |
let queue = self.state.classifier.review.as_ref()?; |
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
if queue.groups.is_empty() { |
| 4173 |
return None; |
| 4174 |
} |
| 4175 |
|
| 4176 |
let at = self.state.review_selected(); |
| 4177 |
Some(Queued { |
| 4178 |
groups: queue |
| 4179 |
.groups |
| 4180 |
.iter() |
| 4181 |
.map(|group| Group { |
| 4182 |
tag: group.tag.clone(), |
| 4183 |
candidates: group.candidates.len(), |
| 4184 |
confident: group.confident(), |
| 4185 |
checked: group.checked(), |
| 4186 |
}) |
| 4187 |
.collect(), |
| 4188 |
at, |
| 4189 |
considered: queue.samples_considered, |
| 4190 |
suggested: queue.samples_with_suggestions, |
| 4191 |
confident: self.state.review_confident_total(), |
| 4192 |
rescanning: self.state.classifier.busy.is_some(), |
| 4193 |
said: self.state.classifier.last_review_accept.clone(), |
| 4194 |
shown: queue.groups.get(at).map_or_else(Vec::new, |group| { |
| 4195 |
group |
| 4196 |
.candidates |
| 4197 |
.iter() |
| 4198 |
.take(crate::quasi::queue::RENDER_ROWS) |
| 4199 |
.map(|candidate| Candidate { |
| 4200 |
|
| 4201 |
|
| 4202 |
name: candidate |
| 4203 |
.name |
| 4204 |
.clone() |
| 4205 |
.unwrap_or_else(|| candidate.hash.clone()), |
| 4206 |
score: candidate.score, |
| 4207 |
confident: candidate.confident, |
| 4208 |
accepted: candidate.accepted, |
| 4209 |
}) |
| 4210 |
.collect() |
| 4211 |
}), |
| 4212 |
}) |
| 4213 |
} |
| 4214 |
|
| 4215 |
fn read(&self, at: usize) { |
| 4216 |
self.push(Intent::ReadGroup(at)); |
| 4217 |
} |
| 4218 |
|
| 4219 |
fn tick(&self, at: usize) { |
| 4220 |
self.push(Intent::TickCandidate(at)); |
| 4221 |
} |
| 4222 |
|
| 4223 |
fn tick_shown(&self, ticked: bool) { |
| 4224 |
self.push(Intent::TickShown(ticked)); |
| 4225 |
} |
| 4226 |
|
| 4227 |
fn accept(&self, scope: Scope) { |
| 4228 |
self.push(Intent::AcceptGroup(scope)); |
| 4229 |
} |
| 4230 |
|
| 4231 |
fn accept_confident(&self) { |
| 4232 |
self.push(Intent::AcceptConfident); |
| 4233 |
} |
| 4234 |
|
| 4235 |
fn dismiss(&self) { |
| 4236 |
self.push(Intent::DismissGroup); |
| 4237 |
} |
| 4238 |
|
| 4239 |
fn rescan(&self) { |
| 4240 |
self.push(Intent::Rescan); |
| 4241 |
} |
| 4242 |
|
| 4243 |
fn close(&self) { |
| 4244 |
self.push(Intent::CloseReview); |
| 4245 |
} |
| 4246 |
} |
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
#[derive(Debug, Clone, PartialEq)] |
| 4260 |
pub struct Narrowing { |
| 4261 |
|
| 4262 |
|
| 4263 |
pub key: &'static str, |
| 4264 |
|
| 4265 |
pub axis: &'static crate::quasi::filters::RangeAxis, |
| 4266 |
|
| 4267 |
pub lower: Option<f64>, |
| 4268 |
|
| 4269 |
pub upper: Option<f64>, |
| 4270 |
} |
| 4271 |
|
| 4272 |
|
| 4273 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 4274 |
pub struct Keys { |
| 4275 |
|
| 4276 |
pub wanted: Vec<String>, |
| 4277 |
|
| 4278 |
pub compatible: bool, |
| 4279 |
} |
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
|
| 4286 |
|
| 4287 |
|
| 4288 |
pub trait Filters { |
| 4289 |
|
| 4290 |
fn axes(&self) -> Vec<Narrowing>; |
| 4291 |
|
| 4292 |
|
| 4293 |
fn keys(&self) -> Keys; |
| 4294 |
|
| 4295 |
|
| 4296 |
fn tags(&self) -> Vec<String>; |
| 4297 |
|
| 4298 |
|
| 4299 |
fn typing(&self) -> String; |
| 4300 |
|
| 4301 |
|
| 4302 |
fn matched(&self) -> usize; |
| 4303 |
|
| 4304 |
|
| 4305 |
fn active(&self) -> bool; |
| 4306 |
|
| 4307 |
|
| 4308 |
fn describes(&self) -> String; |
| 4309 |
|
| 4310 |
|
| 4311 |
fn narrow(&self, key: &'static str, lower: Option<f64>, upper: Option<f64>); |
| 4312 |
|
| 4313 |
|
| 4314 |
fn set_key_mode(&self, compatible: bool); |
| 4315 |
|
| 4316 |
|
| 4317 |
fn toggle_key(&self, key: &str); |
| 4318 |
|
| 4319 |
|
| 4320 |
fn clear_keys(&self); |
| 4321 |
|
| 4322 |
|
| 4323 |
fn typed(&self, text: &str); |
| 4324 |
|
| 4325 |
|
| 4326 |
fn require(&self, tag: &str); |
| 4327 |
|
| 4328 |
|
| 4329 |
fn unrequire(&self, tag: &str); |
| 4330 |
|
| 4331 |
|
| 4332 |
fn clear_tags(&self); |
| 4333 |
|
| 4334 |
|
| 4335 |
fn clear_all(&self); |
| 4336 |
|
| 4337 |
|
| 4338 |
fn save_collection(&self, name: &str); |
| 4339 |
} |
| 4340 |
|
| 4341 |
|
| 4342 |
pub struct FromFilters<'a> { |
| 4343 |
|
| 4344 |
pub state: &'a crate::state::BrowserState, |
| 4345 |
|
| 4346 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 4347 |
} |
| 4348 |
|
| 4349 |
impl FromFilters<'_> { |
| 4350 |
|
| 4351 |
|
| 4352 |
|
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
fn table(&self) -> [Narrowing; 6] { |
| 4357 |
use crate::quasi::filters as axes; |
| 4358 |
let f = &self.state.search.search_filter; |
| 4359 |
[ |
| 4360 |
Narrowing { |
| 4361 |
key: "bpm", |
| 4362 |
axis: &axes::BPM, |
| 4363 |
lower: f.bpm_min, |
| 4364 |
upper: f.bpm_max, |
| 4365 |
}, |
| 4366 |
Narrowing { |
| 4367 |
key: "duration", |
| 4368 |
axis: &axes::DURATION, |
| 4369 |
lower: f.duration_min, |
| 4370 |
upper: f.duration_max, |
| 4371 |
}, |
| 4372 |
Narrowing { |
| 4373 |
key: "loudness", |
| 4374 |
axis: &axes::LOUDNESS, |
| 4375 |
lower: f.peak_db_min, |
| 4376 |
upper: f.peak_db_max, |
| 4377 |
}, |
| 4378 |
Narrowing { |
| 4379 |
key: "brightness", |
| 4380 |
axis: &axes::BRIGHTNESS, |
| 4381 |
lower: f.centroid_min, |
| 4382 |
upper: f.centroid_max, |
| 4383 |
}, |
| 4384 |
Narrowing { |
| 4385 |
key: "noisiness", |
| 4386 |
axis: &axes::NOISINESS, |
| 4387 |
lower: f.flatness_min, |
| 4388 |
upper: f.flatness_max, |
| 4389 |
}, |
| 4390 |
Narrowing { |
| 4391 |
key: "attack", |
| 4392 |
axis: &axes::ATTACK, |
| 4393 |
lower: f.attack_min, |
| 4394 |
upper: f.attack_max, |
| 4395 |
}, |
| 4396 |
] |
| 4397 |
} |
| 4398 |
|
| 4399 |
|
| 4400 |
fn push(&self, intent: Intent) { |
| 4401 |
self.intents.borrow_mut().push(intent); |
| 4402 |
} |
| 4403 |
} |
| 4404 |
|
| 4405 |
impl Filters for FromFilters<'_> { |
| 4406 |
fn axes(&self) -> Vec<Narrowing> { |
| 4407 |
self.table().to_vec() |
| 4408 |
} |
| 4409 |
|
| 4410 |
fn keys(&self) -> Keys { |
| 4411 |
use audiofiles_core::search::KeyFilterMode; |
| 4412 |
Keys { |
| 4413 |
wanted: self.state.search.search_filter.keys.clone(), |
| 4414 |
compatible: matches!( |
| 4415 |
self.state.search.search_filter.key_mode, |
| 4416 |
KeyFilterMode::Compatible |
| 4417 |
), |
| 4418 |
} |
| 4419 |
} |
| 4420 |
|
| 4421 |
fn tags(&self) -> Vec<String> { |
| 4422 |
self.state.search.search_filter.required_tags.clone() |
| 4423 |
} |
| 4424 |
|
| 4425 |
fn typing(&self) -> String { |
| 4426 |
self.state.search.filter_tag_input.clone() |
| 4427 |
} |
| 4428 |
|
| 4429 |
fn matched(&self) -> usize { |
| 4430 |
|
| 4431 |
|
| 4432 |
self.state |
| 4433 |
.nav |
| 4434 |
.contents |
| 4435 |
.iter() |
| 4436 |
.filter(|entry| entry.node.node_type != audiofiles_core::vfs::NodeType::Directory) |
| 4437 |
.count() |
| 4438 |
} |
| 4439 |
|
| 4440 |
fn active(&self) -> bool { |
| 4441 |
self.state.search.search_filter.is_active() |
| 4442 |
} |
| 4443 |
|
| 4444 |
fn describes(&self) -> String { |
| 4445 |
self.state.search.search_filter.describe() |
| 4446 |
} |
| 4447 |
|
| 4448 |
fn narrow(&self, key: &'static str, lower: Option<f64>, upper: Option<f64>) { |
| 4449 |
self.push(Intent::Narrow(key, lower, upper)); |
| 4450 |
} |
| 4451 |
|
| 4452 |
fn set_key_mode(&self, compatible: bool) { |
| 4453 |
self.push(Intent::KeyMode(compatible)); |
| 4454 |
} |
| 4455 |
|
| 4456 |
fn toggle_key(&self, key: &str) { |
| 4457 |
self.push(Intent::ToggleKey(key.to_owned())); |
| 4458 |
} |
| 4459 |
|
| 4460 |
fn clear_keys(&self) { |
| 4461 |
self.push(Intent::ClearKeys); |
| 4462 |
} |
| 4463 |
|
| 4464 |
fn typed(&self, text: &str) { |
| 4465 |
self.push(Intent::TypingTag(text.to_owned())); |
| 4466 |
} |
| 4467 |
|
| 4468 |
fn require(&self, tag: &str) { |
| 4469 |
self.push(Intent::RequireTag(tag.to_owned())); |
| 4470 |
} |
| 4471 |
|
| 4472 |
fn unrequire(&self, tag: &str) { |
| 4473 |
self.push(Intent::UnrequireTag(tag.to_owned())); |
| 4474 |
} |
| 4475 |
|
| 4476 |
fn clear_tags(&self) { |
| 4477 |
self.push(Intent::ClearTags); |
| 4478 |
} |
| 4479 |
|
| 4480 |
fn clear_all(&self) { |
| 4481 |
self.push(Intent::ClearFilters); |
| 4482 |
} |
| 4483 |
|
| 4484 |
fn save_collection(&self, name: &str) { |
| 4485 |
self.push(Intent::SaveCollection(name.to_owned())); |
| 4486 |
} |
| 4487 |
} |
| 4488 |
|
| 4489 |
impl FromQueue<'_> { |
| 4490 |
|
| 4491 |
fn push(&self, intent: Intent) { |
| 4492 |
self.intents.borrow_mut().push(intent); |
| 4493 |
} |
| 4494 |
} |
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
|
| 4503 |
#[derive(Debug, Clone, PartialEq)] |
| 4504 |
pub struct Forging { |
| 4505 |
|
| 4506 |
pub name: String, |
| 4507 |
|
| 4508 |
pub rate: u32, |
| 4509 |
|
| 4510 |
pub busy: bool, |
| 4511 |
|
| 4512 |
pub how: Chop, |
| 4513 |
|
| 4514 |
pub sensitivity: f32, |
| 4515 |
|
| 4516 |
pub divisions: usize, |
| 4517 |
|
| 4518 |
pub bpm: f64, |
| 4519 |
|
| 4520 |
pub subdivisions: u32, |
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
pub slices: usize, |
| 4528 |
|
| 4529 |
pub devices: Vec<DeviceChoice>, |
| 4530 |
|
| 4531 |
pub device: Option<String>, |
| 4532 |
|
| 4533 |
pub chosen: usize, |
| 4534 |
|
| 4535 |
pub threshold_db: f64, |
| 4536 |
} |
| 4537 |
|
| 4538 |
|
| 4539 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 4540 |
pub enum Chop { |
| 4541 |
|
| 4542 |
Transient, |
| 4543 |
|
| 4544 |
Equal, |
| 4545 |
|
| 4546 |
Bpm, |
| 4547 |
} |
| 4548 |
|
| 4549 |
impl Chop { |
| 4550 |
|
| 4551 |
pub const ALL: [Self; 3] = [Self::Transient, Self::Equal, Self::Bpm]; |
| 4552 |
|
| 4553 |
|
| 4554 |
#[must_use] |
| 4555 |
pub const fn as_str(self) -> &'static str { |
| 4556 |
match self { |
| 4557 |
Self::Transient => "transient", |
| 4558 |
Self::Equal => "divisions", |
| 4559 |
Self::Bpm => "bpm", |
| 4560 |
} |
| 4561 |
} |
| 4562 |
|
| 4563 |
|
| 4564 |
#[must_use] |
| 4565 |
pub const fn label(self) -> &'static str { |
| 4566 |
match self { |
| 4567 |
Self::Transient => "Transient", |
| 4568 |
Self::Equal => "Divisions", |
| 4569 |
Self::Bpm => "BPM grid", |
| 4570 |
} |
| 4571 |
} |
| 4572 |
|
| 4573 |
|
| 4574 |
#[must_use] |
| 4575 |
pub fn from_key(name: &str) -> Option<Self> { |
| 4576 |
Self::ALL.into_iter().find(|held| held.as_str() == name) |
| 4577 |
} |
| 4578 |
} |
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 4586 |
pub struct DeviceChoice { |
| 4587 |
|
| 4588 |
pub name: String, |
| 4589 |
|
| 4590 |
pub summary: String, |
| 4591 |
} |
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 4599 |
pub enum Knob { |
| 4600 |
|
| 4601 |
Sensitivity, |
| 4602 |
|
| 4603 |
Divisions, |
| 4604 |
|
| 4605 |
Bpm, |
| 4606 |
|
| 4607 |
Subdivisions, |
| 4608 |
|
| 4609 |
Threshold, |
| 4610 |
} |
| 4611 |
|
| 4612 |
impl Knob { |
| 4613 |
|
| 4614 |
#[must_use] |
| 4615 |
pub const fn as_str(self) -> &'static str { |
| 4616 |
match self { |
| 4617 |
Self::Sensitivity => "sensitivity", |
| 4618 |
Self::Divisions => "divisions", |
| 4619 |
Self::Bpm => "bpm", |
| 4620 |
Self::Subdivisions => "subdivisions", |
| 4621 |
Self::Threshold => "threshold", |
| 4622 |
} |
| 4623 |
} |
| 4624 |
|
| 4625 |
|
| 4626 |
#[must_use] |
| 4627 |
pub fn from_key(name: &str) -> Option<Self> { |
| 4628 |
match name { |
| 4629 |
"sensitivity" => Some(Self::Sensitivity), |
| 4630 |
"divisions" => Some(Self::Divisions), |
| 4631 |
"bpm" => Some(Self::Bpm), |
| 4632 |
"subdivisions" => Some(Self::Subdivisions), |
| 4633 |
"threshold" => Some(Self::Threshold), |
| 4634 |
_ => None, |
| 4635 |
} |
| 4636 |
} |
| 4637 |
} |
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
|
| 4643 |
|
| 4644 |
pub trait Forge { |
| 4645 |
|
| 4646 |
fn forging(&self) -> Option<Forging>; |
| 4647 |
|
| 4648 |
|
| 4649 |
fn slice_by(&self, how: Chop); |
| 4650 |
|
| 4651 |
|
| 4652 |
fn turn(&self, knob: Knob, value: &str); |
| 4653 |
|
| 4654 |
|
| 4655 |
fn preview(&self); |
| 4656 |
|
| 4657 |
|
| 4658 |
fn chop(&self); |
| 4659 |
|
| 4660 |
|
| 4661 |
fn choose_device(&self, name: &str); |
| 4662 |
|
| 4663 |
|
| 4664 |
fn conform(&self); |
| 4665 |
|
| 4666 |
|
| 4667 |
fn trim_silence(&self); |
| 4668 |
} |
| 4669 |
|
| 4670 |
|
| 4671 |
pub struct FromForge<'a> { |
| 4672 |
|
| 4673 |
pub state: &'a crate::state::BrowserState, |
| 4674 |
|
| 4675 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 4676 |
} |
| 4677 |
|
| 4678 |
impl Forge for FromForge<'_> { |
| 4679 |
fn forging(&self) -> Option<Forging> { |
| 4680 |
let forge = &self.state.forge; |
| 4681 |
forge.hash.as_ref()?; |
| 4682 |
Some(Forging { |
| 4683 |
name: forge.name.clone(), |
| 4684 |
rate: forge.source_rate, |
| 4685 |
busy: forge.busy, |
| 4686 |
how: match forge.chop_mode { |
| 4687 |
crate::state::ChopMode::Transient => Chop::Transient, |
| 4688 |
crate::state::ChopMode::Equal => Chop::Equal, |
| 4689 |
crate::state::ChopMode::Bpm => Chop::Bpm, |
| 4690 |
}, |
| 4691 |
sensitivity: forge.sensitivity, |
| 4692 |
divisions: forge.divisions, |
| 4693 |
bpm: forge.bpm, |
| 4694 |
subdivisions: forge.subdivisions, |
| 4695 |
|
| 4696 |
|
| 4697 |
slices: forge.slice_marks.len().saturating_sub(1), |
| 4698 |
devices: forge |
| 4699 |
.devices |
| 4700 |
.iter() |
| 4701 |
.map(|(name, summary)| DeviceChoice { |
| 4702 |
name: name.clone(), |
| 4703 |
summary: summary.clone(), |
| 4704 |
}) |
| 4705 |
.collect(), |
| 4706 |
device: forge.conform_device.clone(), |
| 4707 |
chosen: self.state.selected_sample_hashes().len(), |
| 4708 |
threshold_db: forge.trim_threshold_db, |
| 4709 |
}) |
| 4710 |
} |
| 4711 |
|
| 4712 |
fn slice_by(&self, how: Chop) { |
| 4713 |
self.push(Intent::SliceBy(how)); |
| 4714 |
} |
| 4715 |
|
| 4716 |
fn turn(&self, knob: Knob, value: &str) { |
| 4717 |
self.push(Intent::Turn(knob, value.to_owned())); |
| 4718 |
} |
| 4719 |
|
| 4720 |
fn preview(&self) { |
| 4721 |
self.push(Intent::PreviewSlices); |
| 4722 |
} |
| 4723 |
|
| 4724 |
fn chop(&self) { |
| 4725 |
self.push(Intent::Chop); |
| 4726 |
} |
| 4727 |
|
| 4728 |
fn choose_device(&self, name: &str) { |
| 4729 |
self.push(Intent::ChooseDevice(name.to_owned())); |
| 4730 |
} |
| 4731 |
|
| 4732 |
fn conform(&self) { |
| 4733 |
self.push(Intent::Conform); |
| 4734 |
} |
| 4735 |
|
| 4736 |
fn trim_silence(&self) { |
| 4737 |
self.push(Intent::TrimSilence); |
| 4738 |
} |
| 4739 |
} |
| 4740 |
|
| 4741 |
impl FromForge<'_> { |
| 4742 |
|
| 4743 |
fn push(&self, intent: Intent) { |
| 4744 |
self.intents.borrow_mut().push(intent); |
| 4745 |
} |
| 4746 |
} |
| 4747 |
|
| 4748 |
|
| 4749 |
|
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
#[derive(Debug, Clone, PartialEq)] |
| 4756 |
pub struct Editing { |
| 4757 |
|
| 4758 |
pub name: String, |
| 4759 |
|
| 4760 |
pub sample_rate: u32, |
| 4761 |
|
| 4762 |
pub duration: Option<f64>, |
| 4763 |
|
| 4764 |
pub peak_db: Option<f64>, |
| 4765 |
|
| 4766 |
pub playing: bool, |
| 4767 |
|
| 4768 |
pub working: bool, |
| 4769 |
|
| 4770 |
pub asking: bool, |
| 4771 |
|
| 4772 |
|
| 4773 |
|
| 4774 |
|
| 4775 |
pub result: Option<String>, |
| 4776 |
|
| 4777 |
|
| 4778 |
pub chosen: usize, |
| 4779 |
|
| 4780 |
pub undoing: Option<String>, |
| 4781 |
} |
| 4782 |
|
| 4783 |
|
| 4784 |
|
| 4785 |
|
| 4786 |
|
| 4787 |
|
| 4788 |
|
| 4789 |
pub trait Edit { |
| 4790 |
|
| 4791 |
fn subject(&self) -> Option<Editing>; |
| 4792 |
|
| 4793 |
|
| 4794 |
fn trim(&self, start: f32, end: f32); |
| 4795 |
|
| 4796 |
|
| 4797 |
fn gain(&self, db: f64); |
| 4798 |
|
| 4799 |
|
| 4800 |
fn normalize(&self, peak: bool, target: f64); |
| 4801 |
|
| 4802 |
|
| 4803 |
fn reverse(&self); |
| 4804 |
|
| 4805 |
|
| 4806 |
fn fade(&self, fading_in: bool, ms: f64, curve: &str); |
| 4807 |
|
| 4808 |
|
| 4809 |
fn insert_silence(&self, at: f64, ms: f64); |
| 4810 |
|
| 4811 |
|
| 4812 |
fn remove_range(&self, from: f64, to: f64); |
| 4813 |
|
| 4814 |
|
| 4815 |
fn cancel(&self); |
| 4816 |
|
| 4817 |
|
| 4818 |
fn play(&self); |
| 4819 |
|
| 4820 |
|
| 4821 |
fn stop(&self); |
| 4822 |
|
| 4823 |
|
| 4824 |
fn remember(&self, mode: &str); |
| 4825 |
|
| 4826 |
|
| 4827 |
fn choose(&self, mode: &str, remember: bool); |
| 4828 |
|
| 4829 |
|
| 4830 |
fn discard(&self); |
| 4831 |
|
| 4832 |
|
| 4833 |
fn undo(&self); |
| 4834 |
|
| 4835 |
|
| 4836 |
fn batch_normalize(&self, peak: bool, target: f64); |
| 4837 |
|
| 4838 |
|
| 4839 |
fn batch_gain(&self, db: f64); |
| 4840 |
|
| 4841 |
|
| 4842 |
fn batch_reverse(&self); |
| 4843 |
} |
| 4844 |
|
| 4845 |
|
| 4846 |
pub struct FromEditor<'a> { |
| 4847 |
|
| 4848 |
pub state: &'a crate::state::BrowserState, |
| 4849 |
|
| 4850 |
pub intents: &'a std::cell::RefCell<Vec<Intent>>, |
| 4851 |
} |
| 4852 |
|
| 4853 |
impl Edit for FromEditor<'_> { |
| 4854 |
fn subject(&self) -> Option<Editing> { |
| 4855 |
let hash = self.state.edit.hash.as_deref()?; |
| 4856 |
let analysis = self.state.detail.selected_analysis.as_ref(); |
| 4857 |
Some(Editing { |
| 4858 |
name: self |
| 4859 |
.state |
| 4860 |
.selected_node() |
| 4861 |
.map(|node| node.node.name.clone()) |
| 4862 |
.unwrap_or_default(), |
| 4863 |
sample_rate: analysis.map_or(44_100, |analysis| analysis.sample_rate), |
| 4864 |
duration: analysis.map(|analysis| analysis.duration), |
| 4865 |
peak_db: analysis.and_then(|analysis| analysis.peak_db), |
| 4866 |
playing: self.state.preview.previewing_hash.as_deref() == Some(hash) |
| 4867 |
&& self.state.shared.preview.lock().playing, |
| 4868 |
working: self.state.edit.in_progress, |
| 4869 |
asking: self.state.edit.result_prompt, |
| 4870 |
result: self |
| 4871 |
.state |
| 4872 |
.edit |
| 4873 |
.result_mode |
| 4874 |
.map(|mode| mode.as_value().to_owned()), |
| 4875 |
chosen: self.state.selected_sample_hashes().len(), |
| 4876 |
undoing: self |
| 4877 |
.state |
| 4878 |
.edit |
| 4879 |
.last_undo |
| 4880 |
.as_ref() |
| 4881 |
.map(|entry| entry.op_name.clone()), |
| 4882 |
}) |
| 4883 |
} |
| 4884 |
|
| 4885 |
fn trim(&self, start: f32, end: f32) { |
| 4886 |
self.push(Intent::EditTrim { start, end }); |
| 4887 |
} |
| 4888 |
|
| 4889 |
fn gain(&self, db: f64) { |
| 4890 |
self.push(Intent::EditGain(db)); |
| 4891 |
} |
| 4892 |
|
| 4893 |
fn normalize(&self, peak: bool, target: f64) { |
| 4894 |
self.push(Intent::EditNormalize { peak, target }); |
| 4895 |
} |
| 4896 |
|
| 4897 |
fn reverse(&self) { |
| 4898 |
self.push(Intent::EditReverse); |
| 4899 |
} |
| 4900 |
|
| 4901 |
fn fade(&self, fading_in: bool, ms: f64, curve: &str) { |
| 4902 |
self.push(Intent::EditFade { |
| 4903 |
fading_in, |
| 4904 |
ms, |
| 4905 |
curve: curve.to_owned(), |
| 4906 |
}); |
| 4907 |
} |
| 4908 |
|
| 4909 |
fn insert_silence(&self, at: f64, ms: f64) { |
| 4910 |
self.push(Intent::EditInsertSilence { at, ms }); |
| 4911 |
} |
| 4912 |
|
| 4913 |
fn remove_range(&self, from: f64, to: f64) { |
| 4914 |
self.push(Intent::EditRemoveRange { from, to }); |
| 4915 |
} |
| 4916 |
|
| 4917 |
fn cancel(&self) { |
| 4918 |
self.push(Intent::EditCancel); |
| 4919 |
} |
| 4920 |
|
| 4921 |
fn play(&self) { |
| 4922 |
self.push(Intent::EditPlay); |
| 4923 |
} |
| 4924 |
|
| 4925 |
fn stop(&self) { |
| 4926 |
self.push(Intent::StopPlayback); |
| 4927 |
} |
| 4928 |
|
| 4929 |
fn remember(&self, mode: &str) { |
| 4930 |
self.push(Intent::EditRemember(mode.to_owned())); |
| 4931 |
} |
| 4932 |
|
| 4933 |
fn choose(&self, mode: &str, remember: bool) { |
| 4934 |
self.push(Intent::EditChoose { |
| 4935 |
mode: mode.to_owned(), |
| 4936 |
remember, |
| 4937 |
}); |
| 4938 |
} |
| 4939 |
|
| 4940 |
fn discard(&self) { |
| 4941 |
self.push(Intent::EditDiscard); |
| 4942 |
} |
| 4943 |
|
| 4944 |
fn undo(&self) { |
| 4945 |
self.push(Intent::EditUndo); |
| 4946 |
} |
| 4947 |
|
| 4948 |
fn batch_normalize(&self, peak: bool, target: f64) { |
| 4949 |
self.push(Intent::BatchNormalize { peak, target }); |
| 4950 |
} |
| 4951 |
|
| 4952 |
fn batch_gain(&self, db: f64) { |
| 4953 |
self.push(Intent::BatchGain(db)); |
| 4954 |
} |
| 4955 |
|
| 4956 |
fn batch_reverse(&self) { |
| 4957 |
self.push(Intent::BatchReverse); |
| 4958 |
} |
| 4959 |
} |
| 4960 |
|
| 4961 |
impl FromEditor<'_> { |
| 4962 |
|
| 4963 |
fn push(&self, intent: Intent) { |
| 4964 |
self.intents.borrow_mut().push(intent); |
| 4965 |
} |
| 4966 |
} |
| 4967 |
|
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 4975 |
pub struct ThemeChoice { |
| 4976 |
|
| 4977 |
pub id: String, |
| 4978 |
|
| 4979 |
pub name: String, |
| 4980 |
|
| 4981 |
pub variant: String, |
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
|
| 4992 |
|
| 4993 |
pub source: Option<String>, |
| 4994 |
} |
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
|
| 4999 |
|
| 5000 |
|
| 5001 |
|
| 5002 |
pub struct Panels<'a> { |
| 5003 |
|
| 5004 |
pub config: &'a dyn Config, |
| 5005 |
|
| 5006 |
pub sync: &'a dyn Sync, |
| 5007 |
|
| 5008 |
pub files: &'a dyn Files, |
| 5009 |
|
| 5010 |
pub export: &'a dyn Export, |
| 5011 |
|
| 5012 |
pub detail: &'a dyn Detail, |
| 5013 |
|
| 5014 |
pub shell: &'a dyn Shell, |
| 5015 |
|
| 5016 |
pub library: &'a dyn Library, |
| 5017 |
|
| 5018 |
pub bar: &'a dyn Bar, |
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
pub bulk: &'a dyn Bulk, |
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
pub naming: &'a dyn Naming, |
| 5029 |
|
| 5030 |
pub importing: &'a dyn Importing, |
| 5031 |
|
| 5032 |
pub integrity: &'a dyn Integrity, |
| 5033 |
|
| 5034 |
pub editor: &'a dyn Edit, |
| 5035 |
|
| 5036 |
pub forge: &'a dyn Forge, |
| 5037 |
|
| 5038 |
pub queue: &'a dyn Queue, |
| 5039 |
|
| 5040 |
pub filters: &'a dyn Filters, |
| 5041 |
|
| 5042 |
pub themes: &'a [ThemeChoice], |
| 5043 |
} |
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
|
| 5048 |
|
| 5049 |
#[must_use] |
| 5050 |
pub fn router<'a>() -> Router<Panels<'a>> { |
| 5051 |
filters::routes(queue::routes(forge::routes(edit::routes( |
| 5052 |
integrity::routes(importing::routes(naming::routes(toolbar::routes( |
| 5053 |
library::routes(shell::routes(help::routes(bulk::routes(detail::routes( |
| 5054 |
export::routes(files::routes(sync::routes(settings::routes(Router::new())))), |
| 5055 |
))))), |
| 5056 |
)))), |
| 5057 |
)))) |
| 5058 |
} |
| 5059 |
|
| 5060 |
#[cfg(test)] |
| 5061 |
mod parity; |
| 5062 |
#[cfg(test)] |
| 5063 |
mod tests; |
| 5064 |
|