| 1 |
|
| 2 |
|
| 3 |
use std::collections::HashSet; |
| 4 |
use std::path::PathBuf; |
| 5 |
use std::time::Instant; |
| 6 |
|
| 7 |
use audiofiles_core::edit::{EditOperation, FadeCurve}; |
| 8 |
use audiofiles_core::vfs::VfsNode; |
| 9 |
use audiofiles_core::{NodeId, VfsId}; |
| 10 |
|
| 11 |
use crate::import::ImportedFolder; |
| 12 |
|
| 13 |
|
| 14 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 15 |
pub enum EditResultMode { |
| 16 |
|
| 17 |
Replace, |
| 18 |
|
| 19 |
Sibling, |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
pub struct PendingEditResult { |
| 24 |
pub source_hash: String, |
| 25 |
pub result_path: PathBuf, |
| 26 |
pub operation: EditOperation, |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
pub struct EditUndoEntry { |
| 37 |
|
| 38 |
pub op_name: String, |
| 39 |
pub source_hash: String, |
| 40 |
pub result_hash: String, |
| 41 |
pub mode: EditResultMode, |
| 42 |
|
| 43 |
pub vfs_id: VfsId, |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
pub replace_targets: Vec<(Option<NodeId>, String)>, |
| 48 |
|
| 49 |
pub sibling_node_id: Option<NodeId>, |
| 50 |
|
| 51 |
pub created_at: Instant, |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
pub enum ConfirmAction { |
| 56 |
DeleteNode { node_id: NodeId, node_name: String }, |
| 57 |
DeleteVfs { vfs_id: VfsId, vfs_name: String }, |
| 58 |
DeleteMultiple { node_ids: Vec<NodeId>, count: usize }, |
| 59 |
DeleteCollection { coll_id: audiofiles_core::CollectionId, coll_name: String }, |
| 60 |
|
| 61 |
RemoveTagGlobally { tag: String }, |
| 62 |
|
| 63 |
|
| 64 |
SwitchLibrary { path: PathBuf, library_name: String }, |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ReanalyzeOverwrite { |
| 69 |
sample_hashes: Vec<(String, String)>, |
| 70 |
overwrite_count: usize, |
| 71 |
}, |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
DisconnectSync { pending_changes: i64 }, |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
RemoveFailedSamples { |
| 84 |
single_index: Option<usize>, |
| 85 |
count: usize, |
| 86 |
name: Option<String>, |
| 87 |
}, |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ReverseSamples { count: usize }, |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
pub enum UndoOp { |
| 97 |
BulkDelete { |
| 98 |
nodes: Vec<VfsNode>, |
| 99 |
tags: Vec<(String, Vec<String>)>, |
| 100 |
}, |
| 101 |
BulkMove { |
| 102 |
moves: Vec<(NodeId, Option<NodeId>)>, |
| 103 |
}, |
| 104 |
BulkRename { |
| 105 |
renames: Vec<(NodeId, String)>, |
| 106 |
}, |
| 107 |
BulkTagAdd { |
| 108 |
tag: String, |
| 109 |
hashes: Vec<String>, |
| 110 |
}, |
| 111 |
BulkTagRemove { |
| 112 |
tag: String, |
| 113 |
hashes: Vec<String>, |
| 114 |
}, |
| 115 |
|
| 116 |
|
| 117 |
TagRemove { |
| 118 |
hash: String, |
| 119 |
tag: String, |
| 120 |
}, |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
pub enum BulkModal { |
| 125 |
|
| 126 |
Tag { |
| 127 |
|
| 128 |
tag_input: String, |
| 129 |
|
| 130 |
adding: bool, |
| 131 |
|
| 132 |
hashes: Vec<String>, |
| 133 |
|
| 134 |
names: Vec<String>, |
| 135 |
}, |
| 136 |
|
| 137 |
Move { |
| 138 |
|
| 139 |
node_ids: Vec<NodeId>, |
| 140 |
|
| 141 |
names: Vec<String>, |
| 142 |
|
| 143 |
directories: Vec<(NodeId, String)>, |
| 144 |
|
| 145 |
selected_idx: Option<usize>, |
| 146 |
}, |
| 147 |
|
| 148 |
Rename { |
| 149 |
|
| 150 |
pattern_input: String, |
| 151 |
|
| 152 |
targets: Vec<RenameTarget>, |
| 153 |
|
| 154 |
previews: Vec<(String, String)>, |
| 155 |
|
| 156 |
error: Option<String>, |
| 157 |
}, |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
pub struct RenameTarget { |
| 162 |
pub node_id: NodeId, |
| 163 |
pub context: audiofiles_core::rename::RenameContext, |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
#[derive(serde::Serialize, serde::Deserialize)] |
| 168 |
pub struct ColumnConfig { |
| 169 |
pub show_classification: bool, |
| 170 |
pub show_bpm: bool, |
| 171 |
pub show_key: bool, |
| 172 |
pub show_duration: bool, |
| 173 |
pub show_peak_db: bool, |
| 174 |
pub show_tags: bool, |
| 175 |
} |
| 176 |
|
| 177 |
impl Default for ColumnConfig { |
| 178 |
fn default() -> Self { |
| 179 |
Self { |
| 180 |
show_classification: true, |
| 181 |
show_bpm: true, |
| 182 |
show_key: true, |
| 183 |
show_duration: true, |
| 184 |
show_peak_db: false, |
| 185 |
show_tags: false, |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
pub struct ImportFileError { |
| 192 |
pub path: String, |
| 193 |
pub error: String, |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
pub struct AnalysisFileError { |
| 198 |
pub hash: String, |
| 199 |
pub name: String, |
| 200 |
pub error: String, |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
pub enum SyncSetupStatus { |
| 205 |
|
| 206 |
Idle, |
| 207 |
|
| 208 |
Testing, |
| 209 |
|
| 210 |
Valid { app_name: String }, |
| 211 |
|
| 212 |
Failed { error: String }, |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
pub enum SyncSetupAction { |
| 217 |
|
| 218 |
TestKey(String), |
| 219 |
|
| 220 |
SaveKey(String), |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
pub enum VaultAction { |
| 225 |
|
| 226 |
SwitchVault(PathBuf), |
| 227 |
|
| 228 |
CreateVault { name: String, path: PathBuf, loose_files: bool }, |
| 229 |
|
| 230 |
AddExistingVault { name: String, path: PathBuf }, |
| 231 |
|
| 232 |
RemoveVault(PathBuf), |
| 233 |
|
| 234 |
RenameVault { path: PathBuf, new_name: String }, |
| 235 |
|
| 236 |
RelocateVault { old_path: PathBuf, new_path: PathBuf }, |
| 237 |
|
| 238 |
ScanStorage, |
| 239 |
|
| 240 |
DeactivateLicense, |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
#[derive(Default)] |
| 245 |
pub struct SettingsUiState { |
| 246 |
|
| 247 |
pub name: String, |
| 248 |
|
| 249 |
pub list: Vec<(String, PathBuf, bool)>, |
| 250 |
|
| 251 |
pub pending_action: Option<VaultAction>, |
| 252 |
|
| 253 |
pub show_manager: bool, |
| 254 |
|
| 255 |
pub create_name: String, |
| 256 |
|
| 257 |
pub create_path: Option<PathBuf>, |
| 258 |
|
| 259 |
pub rename_target: Option<(PathBuf, String)>, |
| 260 |
|
| 261 |
|
| 262 |
pub create_loose_files: bool, |
| 263 |
|
| 264 |
|
| 265 |
pub is_loose_files: bool, |
| 266 |
|
| 267 |
|
| 268 |
pub storage_cache: Option<crate::backend::StorageStats>, |
| 269 |
|
| 270 |
|
| 271 |
pub storage_cache_at: Option<i64>, |
| 272 |
|
| 273 |
pub storage_scanning: bool, |
| 274 |
|
| 275 |
pub license_key_masked: Option<String>, |
| 276 |
|
| 277 |
pub machine_id: Option<String>, |
| 278 |
|
| 279 |
pub trial_days_remaining: Option<i64>, |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
pub struct SyncUiState { |
| 284 |
|
| 285 |
pub show_panel: bool, |
| 286 |
pub encryption_input: String, |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
pub encryption_confirm_input: String, |
| 292 |
pub auth_code_input: String, |
| 293 |
|
| 294 |
pub api_key_input: String, |
| 295 |
|
| 296 |
pub setup_status: SyncSetupStatus, |
| 297 |
|
| 298 |
pub pending_action: Option<SyncSetupAction>, |
| 299 |
|
| 300 |
pub subscription_loading: bool, |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
pub subscription_loading_at: Option<std::time::Instant>, |
| 305 |
|
| 306 |
pub checkout_loading: bool, |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
pub checkout_loading_at: Option<std::time::Instant>, |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
pub pending_disconnect: bool, |
| 316 |
|
| 317 |
|
| 318 |
pub auth_url: Option<String>, |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
pub vfs_storage_cache: std::collections::HashMap<i64, (u64, u64)>, |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
pub vfs_storage_fetched: bool, |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
pub cap_picker_gib: i64, |
| 332 |
} |
| 333 |
|
| 334 |
impl Default for SyncUiState { |
| 335 |
fn default() -> Self { |
| 336 |
Self { |
| 337 |
show_panel: false, |
| 338 |
encryption_input: String::new(), |
| 339 |
encryption_confirm_input: String::new(), |
| 340 |
auth_code_input: String::new(), |
| 341 |
api_key_input: String::new(), |
| 342 |
setup_status: SyncSetupStatus::Idle, |
| 343 |
pending_action: None, |
| 344 |
subscription_loading: false, |
| 345 |
subscription_loading_at: None, |
| 346 |
checkout_loading: false, |
| 347 |
checkout_loading_at: None, |
| 348 |
pending_disconnect: false, |
| 349 |
auth_url: None, |
| 350 |
vfs_storage_cache: std::collections::HashMap::new(), |
| 351 |
vfs_storage_fetched: false, |
| 352 |
cap_picker_gib: 100, |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
pub struct EditUiState { |
| 359 |
pub show_window: bool, |
| 360 |
pub hash: Option<String>, |
| 361 |
pub in_progress: bool, |
| 362 |
pub result_prompt: bool, |
| 363 |
pub pending_result: Option<PendingEditResult>, |
| 364 |
pub trim_start: f32, |
| 365 |
pub trim_end: f32, |
| 366 |
pub total_frames: usize, |
| 367 |
pub gain_db: f64, |
| 368 |
pub norm_peak: bool, |
| 369 |
pub norm_target: f64, |
| 370 |
pub fade_in: bool, |
| 371 |
pub fade_duration_ms: f64, |
| 372 |
pub fade_curve: FadeCurve, |
| 373 |
pub result_mode: Option<EditResultMode>, |
| 374 |
pub silence_position_ms: f64, |
| 375 |
pub silence_duration_ms: f64, |
| 376 |
pub remove_start_ms: f64, |
| 377 |
pub remove_end_ms: f64, |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
pub last_undo: Option<EditUndoEntry>, |
| 382 |
} |
| 383 |
|
| 384 |
impl Default for EditUiState { |
| 385 |
fn default() -> Self { |
| 386 |
Self { |
| 387 |
show_window: false, |
| 388 |
hash: None, |
| 389 |
in_progress: false, |
| 390 |
result_prompt: false, |
| 391 |
pending_result: None, |
| 392 |
trim_start: 0.0, |
| 393 |
trim_end: 1.0, |
| 394 |
total_frames: 0, |
| 395 |
gain_db: 0.0, |
| 396 |
norm_peak: true, |
| 397 |
norm_target: -0.1, |
| 398 |
fade_in: true, |
| 399 |
fade_duration_ms: 100.0, |
| 400 |
fade_curve: FadeCurve::Linear, |
| 401 |
result_mode: None, |
| 402 |
silence_position_ms: 0.0, |
| 403 |
silence_duration_ms: 100.0, |
| 404 |
remove_start_ms: 0.0, |
| 405 |
remove_end_ms: 100.0, |
| 406 |
last_undo: None, |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 413 |
pub enum ChopMode { |
| 414 |
|
| 415 |
Transient, |
| 416 |
|
| 417 |
Equal, |
| 418 |
|
| 419 |
Bpm, |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
pub struct ForgeUiState { |
| 424 |
pub show_window: bool, |
| 425 |
|
| 426 |
pub hash: Option<String>, |
| 427 |
|
| 428 |
pub ext: String, |
| 429 |
|
| 430 |
pub name: String, |
| 431 |
|
| 432 |
pub source_rate: u32, |
| 433 |
|
| 434 |
pub chop_mode: ChopMode, |
| 435 |
|
| 436 |
pub sensitivity: f32, |
| 437 |
|
| 438 |
pub divisions: usize, |
| 439 |
|
| 440 |
pub bpm: f64, |
| 441 |
|
| 442 |
pub subdivisions: u32, |
| 443 |
|
| 444 |
|
| 445 |
pub waveform: Option<audiofiles_core::analysis::waveform::WaveformData>, |
| 446 |
|
| 447 |
|
| 448 |
pub slice_marks: Vec<f32>, |
| 449 |
|
| 450 |
pub busy: bool, |
| 451 |
|
| 452 |
pub conform_device: Option<String>, |
| 453 |
|
| 454 |
|
| 455 |
pub devices: Vec<(String, String)>, |
| 456 |
|
| 457 |
pub trim_threshold_db: f64, |
| 458 |
} |
| 459 |
|
| 460 |
impl Default for ForgeUiState { |
| 461 |
fn default() -> Self { |
| 462 |
Self { |
| 463 |
show_window: false, |
| 464 |
hash: None, |
| 465 |
ext: "wav".to_string(), |
| 466 |
name: String::new(), |
| 467 |
source_rate: 44100, |
| 468 |
chop_mode: ChopMode::Equal, |
| 469 |
sensitivity: 0.5, |
| 470 |
divisions: 8, |
| 471 |
bpm: 120.0, |
| 472 |
subdivisions: 1, |
| 473 |
waveform: None, |
| 474 |
slice_marks: Vec::new(), |
| 475 |
busy: false, |
| 476 |
conform_device: None, |
| 477 |
devices: Vec::new(), |
| 478 |
trim_threshold_db: -60.0, |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
pub enum MidiAction { |
| 485 |
|
| 486 |
Connect(usize), |
| 487 |
|
| 488 |
Disconnect, |
| 489 |
|
| 490 |
RefreshPorts, |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
pub struct MidiNoteEvent { |
| 495 |
pub note: u8, |
| 496 |
pub velocity: u8, |
| 497 |
pub note_name: String, |
| 498 |
pub timestamp: Instant, |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
#[derive(Default)] |
| 503 |
pub struct MidiUiState { |
| 504 |
pub available_ports: Vec<String>, |
| 505 |
pub connected_port: Option<usize>, |
| 506 |
pub connected_port_name: Option<String>, |
| 507 |
pub recent_notes: Vec<MidiNoteEvent>, |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
#[derive(Clone)] |
| 512 |
pub struct FolderTagEntry { |
| 513 |
pub folder: ImportedFolder, |
| 514 |
pub tag_input: String, |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
#[derive(Clone, Copy, PartialEq, Eq)] |
| 520 |
pub enum CancelKind { |
| 521 |
Import, |
| 522 |
Analysis, |
| 523 |
Export, |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
pub struct OperationProgress { |
| 531 |
pub started_at: std::time::Instant, |
| 532 |
samples: Vec<(std::time::Instant, usize)>, |
| 533 |
} |
| 534 |
|
| 535 |
impl OperationProgress { |
| 536 |
pub fn new() -> Self { |
| 537 |
Self { |
| 538 |
started_at: std::time::Instant::now(), |
| 539 |
samples: Vec::new(), |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
pub fn record(&mut self, completed: usize) { |
| 545 |
let now = std::time::Instant::now(); |
| 546 |
let should_push = self |
| 547 |
.samples |
| 548 |
.last() |
| 549 |
.map(|(_, c)| *c != completed) |
| 550 |
.unwrap_or(true); |
| 551 |
if should_push { |
| 552 |
self.samples.push((now, completed)); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
self.samples |
| 557 |
.retain(|(t, _)| now.duration_since(*t).as_secs_f64() < 10.0); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
pub fn rate(&self) -> Option<f64> { |
| 563 |
if self.samples.len() < 2 { |
| 564 |
return None; |
| 565 |
} |
| 566 |
let (t0, c0) = *self.samples.first()?; |
| 567 |
let (t1, c1) = *self.samples.last()?; |
| 568 |
let dt = t1.duration_since(t0).as_secs_f64(); |
| 569 |
if dt < 0.5 { |
| 570 |
return None; |
| 571 |
} |
| 572 |
let dc = c1.saturating_sub(c0) as f64; |
| 573 |
if dc <= 0.0 { |
| 574 |
return None; |
| 575 |
} |
| 576 |
Some(dc / dt) |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
pub fn eta(&self, completed: usize, total: usize) -> Option<String> { |
| 583 |
let rate = self.rate()?; |
| 584 |
if total <= completed { |
| 585 |
return None; |
| 586 |
} |
| 587 |
let remaining = (total - completed) as f64; |
| 588 |
let secs = (remaining / rate) as u64; |
| 589 |
if secs < 5 { |
| 590 |
return None; |
| 591 |
} |
| 592 |
let mins = secs / 60; |
| 593 |
let s = secs % 60; |
| 594 |
Some(if mins > 0 { |
| 595 |
format!("{mins}m {s}s remaining") |
| 596 |
} else { |
| 597 |
format!("{s}s remaining") |
| 598 |
}) |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
impl Default for OperationProgress { |
| 603 |
fn default() -> Self { |
| 604 |
Self::new() |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 610 |
pub enum ReviewSort { |
| 611 |
|
| 612 |
ImportOrder, |
| 613 |
|
| 614 |
Name, |
| 615 |
|
| 616 |
Suggestions, |
| 617 |
|
| 618 |
Accepted, |
| 619 |
} |
| 620 |
|
| 621 |
impl ReviewSort { |
| 622 |
pub const ALL: &'static [ReviewSort] = &[ |
| 623 |
ReviewSort::ImportOrder, |
| 624 |
ReviewSort::Name, |
| 625 |
ReviewSort::Suggestions, |
| 626 |
ReviewSort::Accepted, |
| 627 |
]; |
| 628 |
|
| 629 |
pub fn label(self) -> &'static str { |
| 630 |
match self { |
| 631 |
ReviewSort::ImportOrder => "Import order", |
| 632 |
ReviewSort::Name => "Name", |
| 633 |
ReviewSort::Suggestions => "Suggestions", |
| 634 |
ReviewSort::Accepted => "Accepted", |
| 635 |
} |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
pub enum ImportMode { |
| 641 |
None, |
| 642 |
ConfigureImport { |
| 643 |
source: PathBuf, |
| 644 |
source_name: String, |
| 645 |
strategy: crate::import::ImportStrategy, |
| 646 |
available_vfs: Vec<audiofiles_core::vfs::Vfs>, |
| 647 |
selected_merge_vfs_idx: usize, |
| 648 |
new_vfs_name: String, |
| 649 |
|
| 650 |
audio_file_count: usize, |
| 651 |
}, |
| 652 |
Importing { |
| 653 |
total: usize, |
| 654 |
completed: usize, |
| 655 |
current_name: String, |
| 656 |
walking: bool, |
| 657 |
|
| 658 |
|
| 659 |
walking_count: usize, |
| 660 |
total_bytes: u64, |
| 661 |
loose_files: bool, |
| 662 |
}, |
| 663 |
TagFolders { |
| 664 |
entries: Vec<FolderTagEntry>, |
| 665 |
sample_hashes: Vec<(String, String)>, |
| 666 |
}, |
| 667 |
ConfigureAnalysis { |
| 668 |
sample_hashes: Vec<(String, String)>, |
| 669 |
config: audiofiles_core::analysis::config::AnalysisConfig, |
| 670 |
}, |
| 671 |
Analyzing { |
| 672 |
completed: usize, |
| 673 |
total: usize, |
| 674 |
current_name: String, |
| 675 |
}, |
| 676 |
ReviewSuggestions { |
| 677 |
items: Vec<ReviewItem>, |
| 678 |
current_idx: usize, |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
sort: ReviewSort, |
| 683 |
}, |
| 684 |
ConfigureExport { |
| 685 |
items: Vec<audiofiles_core::export::ExportItem>, |
| 686 |
config: audiofiles_core::export::ExportConfig, |
| 687 |
|
| 688 |
available_profiles: Vec<audiofiles_core::export::profile::DeviceProfileSummary>, |
| 689 |
}, |
| 690 |
Exporting { |
| 691 |
completed: usize, |
| 692 |
total: usize, |
| 693 |
current_name: String, |
| 694 |
}, |
| 695 |
Cleaning { |
| 696 |
completed: usize, |
| 697 |
total: usize, |
| 698 |
current_name: String, |
| 699 |
}, |
| 700 |
ExportComplete { |
| 701 |
total: usize, |
| 702 |
errors: Vec<(String, String)>, |
| 703 |
}, |
| 704 |
ReviewErrors, |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
OperationCancelled { |
| 710 |
kind: CancelKind, |
| 711 |
completed: usize, |
| 712 |
total: usize, |
| 713 |
destination: Option<PathBuf>, |
| 714 |
}, |
| 715 |
} |
| 716 |
|
| 717 |
|
| 718 |
pub struct ReviewItem { |
| 719 |
pub hash: audiofiles_core::SampleHash, |
| 720 |
pub name: String, |
| 721 |
pub result: audiofiles_core::analysis::AnalysisResult, |
| 722 |
pub suggestions: Vec<SuggestionState>, |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
pub struct SuggestionState { |
| 727 |
pub suggestion: audiofiles_core::analysis::suggest::TagSuggestion, |
| 728 |
pub accepted: bool, |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 734 |
pub enum SortColumn { |
| 735 |
Name, |
| 736 |
Bpm, |
| 737 |
Key, |
| 738 |
Duration, |
| 739 |
Classification, |
| 740 |
} |
| 741 |
|
| 742 |
#[derive(Debug, Clone, PartialEq, Eq)] |
| 743 |
pub enum SortDirection { |
| 744 |
Ascending, |
| 745 |
Descending, |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
#[derive(Debug, Clone, Default)] |
| 758 |
pub struct Selection { |
| 759 |
|
| 760 |
pub anchor: usize, |
| 761 |
|
| 762 |
pub focus: usize, |
| 763 |
|
| 764 |
pub selected: HashSet<usize>, |
| 765 |
} |
| 766 |
|
| 767 |
impl Selection { |
| 768 |
|
| 769 |
pub fn new() -> Self { |
| 770 |
Self::default() |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
pub fn clear(&mut self) { |
| 775 |
self.selected.clear(); |
| 776 |
self.anchor = 0; |
| 777 |
self.focus = 0; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
pub fn set_single(&mut self, idx: usize) { |
| 782 |
self.selected.clear(); |
| 783 |
self.selected.insert(idx); |
| 784 |
self.anchor = idx; |
| 785 |
self.focus = idx; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
pub fn toggle(&mut self, idx: usize) { |
| 790 |
if self.selected.contains(&idx) { |
| 791 |
self.selected.remove(&idx); |
| 792 |
} else { |
| 793 |
self.selected.insert(idx); |
| 794 |
} |
| 795 |
self.anchor = idx; |
| 796 |
self.focus = idx; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
pub fn extend_to(&mut self, target: usize, _max_len: usize) { |
| 803 |
let start = self.anchor.min(target); |
| 804 |
let end = self.anchor.max(target); |
| 805 |
for i in start..=end { |
| 806 |
self.selected.insert(i); |
| 807 |
} |
| 808 |
self.focus = target; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
pub fn extend_down(&mut self, max_len: usize) { |
| 813 |
if max_len > 0 && self.focus < max_len - 1 { |
| 814 |
self.focus += 1; |
| 815 |
self.selected.insert(self.focus); |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
pub fn extend_up(&mut self) { |
| 821 |
if self.focus > 0 { |
| 822 |
self.focus -= 1; |
| 823 |
self.selected.insert(self.focus); |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
pub fn select_all(&mut self, len: usize) { |
| 829 |
self.select_all_from(0, len); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
pub fn select_all_from(&mut self, start: usize, len: usize) { |
| 836 |
self.selected.clear(); |
| 837 |
for i in start..len { |
| 838 |
self.selected.insert(i); |
| 839 |
} |
| 840 |
if len > start { |
| 841 |
self.anchor = start; |
| 842 |
self.focus = len - 1; |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
pub fn invert(&mut self, len: usize) { |
| 849 |
let new_selected: std::collections::HashSet<usize> = |
| 850 |
(0..len).filter(|i| !self.selected.contains(i)).collect(); |
| 851 |
if let Some(&first) = new_selected.iter().min() { |
| 852 |
self.anchor = first; |
| 853 |
self.focus = first; |
| 854 |
} |
| 855 |
self.selected = new_selected; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
pub fn contains(&self, idx: usize) -> bool { |
| 860 |
self.selected.contains(&idx) |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
pub fn count(&self) -> usize { |
| 865 |
self.selected.len() |
| 866 |
} |
| 867 |
} |
| 868 |
|