Skip to content

Commit

Permalink
Bind audio data to table columns
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Aug 11, 2023
1 parent 1ad72f6 commit 1f3c2f1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ impl Model for AppData {
AppEvent::SetBrowserWidth(width) => self.browser_width = *width,
AppEvent::SetTableHeight(height) => self.table_height = *height,
AppEvent::ViewCollection(id) => {
println!("selected: {}", id);
if let Ok(db) = self.database.lock() {
if let Ok(audio_files) = db.get_all_audio_files() {
println!("ALL {}", audio_files.len());
if let Ok(audio_files) = db.get_child_audio_files(*id) {
self.table_rows = audio_files;
}
}
println!("num rows: {}", self.table_rows.len());
}
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/database/audio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct AudioFile {
pub id: AudioFileID,
pub name: String,
pub collection: CollectionID,
duration: f32,
sample_rate: f32,
bit_depth: f32,
bpm: Option<f32>,
key: Option<f32>,
size: f32,
pub duration: f32,
pub sample_rate: f32,
pub bit_depth: f32,
pub bpm: Option<f32>,
pub key: Option<f32>,
pub size: f32,
}

impl AudioFile {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ fn main() {
// })
// .collect::<Vec<_>>();

let mut db = Database::from_directory(Path::new("test_files/").to_path_buf()).unwrap();
let mut db =
Database::from_directory(Path::new("the-libre-sample-pack/").to_path_buf()).unwrap();

let collections = db.get_all_collections().unwrap();
let audio_files = db.get_all_audio_files().unwrap();
Expand Down
58 changes: 50 additions & 8 deletions src/panels/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,56 @@ impl SamplesPanel {
.height(Auto)
.class("header");

SmartTable::new(cx, AppData::table_headers, AppData::table_rows, |cx, row, index| {
Label::new(cx, row.then(AudioFile::name))
.width(Stretch(1.0))
.border_color(Color::bisque())
// .border_width(Pixels(1.0))
.child_space(Stretch(1.0))
.child_left(if index == 0 { Pixels(4.0) } else { Stretch(1.0) });
});
SmartTable::new(
cx,
AppData::table_headers,
AppData::table_rows,
|cx, row, col_index| {
match col_index {
// Name
0 => {
Label::new(cx, row.then(AudioFile::name))
.width(Stretch(1.0))
.border_color(Color::bisque())
// .border_width(Pixels(1.0))
.child_space(Stretch(1.0))
.child_left(if col_index == 0 {
Pixels(4.0)
} else {
Stretch(1.0)
});
}
// Tags
1 => {}
// Duration
2 => {
Label::new(cx, row.then(AudioFile::duration)).width(Stretch(1.0));
}
// Sample Rate
3 => {
Label::new(cx, row.then(AudioFile::sample_rate)).width(Stretch(1.0));
}
// Bit Depth
4 => {
Label::new(cx, row.then(AudioFile::bit_depth)).width(Stretch(1.0));
}
// BPM
5 => {
Label::new(cx, row.then(AudioFile::bpm).map(|k| format!("{:?}", k)))
.width(Stretch(1.0));
}
// Key
6 => {
Label::new(cx, row.then(AudioFile::key).map(|k| format!("{:?}", k)))
.width(Stretch(1.0));
}
// Size
_ => {
Label::new(cx, row.then(AudioFile::size)).width(Stretch(1.0));
}
}
},
);
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/smart_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ impl SmartTable {
.height(Auto);
//
List::new(cx, rows, move |cx, row_index, row| {
println!("rebuild virtual list");
//
List::new(cx, headers, move |cx, col_index, _| {
HStack::new(cx, move |cx| {
(content)(cx, row, col_index);
})
.overflow(Overflow::Hidden)
.width(Self::widths.index(col_index))
.height(Auto);
})
Expand Down

0 comments on commit 1f3c2f1

Please sign in to comment.