pub struct Track { /* private fields */ }
Expand description
The Track
Type. This is a collection of Key
s with a name.
Implementations§
Source§impl Track
impl Track
Sourcepub fn delete_key(&mut self, row: u32)
pub fn delete_key(&mut self, row: u32)
Delete a key from a track.
If a key does not exist this will do nothing.
Sourcepub fn get_value(&self, row: f32) -> f32
pub fn get_value(&self, row: f32) -> f32
Get a value based on a row.
The row can be between two integers. This will perform the required interpolation.
Examples found in repository?
examples/play.rs (line 28)
8fn main() -> Result<(), Box<dyn Error>> {
9 let rocket = {
10 // Open previously saved file (see examples/edit.rs)
11 let mut file = File::open(TRACKS_FILE)?;
12 // Deserialize from the file into Vec<Track> using bincode
13 let bincode_conf = bincode::config::standard();
14 let tracks = bincode::decode_from_std_read(&mut file, bincode_conf)?;
15 // Construct a new read-only, offline RocketPlayer
16 RocketPlayer::new(tracks)
17 };
18 println!("Tracks loaded from {}", TRACKS_FILE);
19
20 let mut current_row = 0;
21
22 loop {
23 println!(
24 "value: {:?} (row: {:?})",
25 rocket
26 .get_track("test")
27 .unwrap()
28 .get_value(current_row as f32),
29 current_row
30 );
31
32 current_row += 1;
33 std::thread::sleep(Duration::from_millis(32));
34 }
35}
More examples
examples/edit.rs (line 30)
8fn main() -> Result<(), Box<dyn Error>> {
9 let mut rocket = RocketClient::new()?;
10 rocket.get_track_mut("test")?;
11 rocket.get_track_mut("test2")?;
12 rocket.get_track_mut("a:test2")?;
13
14 let mut current_row = 0;
15 let mut paused = true;
16
17 loop {
18 if let Some(event) = rocket.poll_events()? {
19 match event {
20 Event::SetRow(row) => {
21 println!("SetRow (row: {:?})", row);
22 current_row = row;
23 }
24 Event::Pause(state) => {
25 paused = state;
26
27 let track1 = rocket.get_track("test").unwrap();
28 println!(
29 "Pause (value: {:?}) (row: {:?})",
30 track1.get_value(current_row as f32),
31 current_row
32 );
33 }
34 Event::SaveTracks => {
35 // Obtain a clone of current track state
36 let tracks = rocket.save_tracks();
37
38 // Open a file for writing, create if not present,
39 // truncate (overwrite) in case it has previous contents.
40 let mut file = OpenOptions::new()
41 .write(true)
42 .create(true)
43 .truncate(true)
44 .open(TRACKS_FILE)?;
45
46 // Serialize tracks into the file using bincode
47 let bincode_conf = bincode::config::standard();
48 bincode::encode_into_std_write(tracks, &mut file, bincode_conf)?;
49 // See examples/play.rs for deserializing and playback
50 println!("Tracks saved to {}", TRACKS_FILE);
51 }
52 }
53 println!("{:?}", event);
54 }
55
56 if !paused {
57 current_row += 1;
58 rocket.set_row(current_row)?;
59 }
60
61 std::thread::sleep(Duration::from_millis(32));
62 }
63}
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Track
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Track
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Attempt to decode this type with the given BorrowDecode.
Source§impl<'de> Deserialize<'de> for Track
impl<'de> Deserialize<'de> for Track
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Track
impl RefUnwindSafe for Track
impl Send for Track
impl Sync for Track
impl Unpin for Track
impl UnwindSafe for Track
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more