Struct SyncClient

Source
pub struct SyncClient { /* private fields */ }

Implementations§

Source§

impl SyncClient

Source

pub fn new(address: &str) -> Result<SyncClient, Box<dyn Error>>

Connects to the Rocket Editor server and shakes hand with it

Examples found in repository?
examples/basic_example.rs (line 21)
16fn main() {
17    env_logger::init().unwrap();
18    info!("main: started");
19
20    // Connect to the Rocket Editor (server process)
21    let mut rocket: SyncClient = match SyncClient::new("localhost:1338") {
22        Ok(x) => { info!("Connected to Rocket"); x },
23        Err(_) => { println!("Couldn't connect to Rocket"); exit(2); },
24    };
25
26    let track_names = vec![
27        "group0#track0".to_owned(),
28        "group0#track1".to_owned(),
29        "group0#track2".to_owned(),
30        "group1#track0".to_owned(),
31        "group1#track1".to_owned(),
32        "group1#track2".to_owned(),
33    ];
34
35    rocket.send_track_names(&track_names).unwrap();
36
37    let mut sync_device: SyncDevice = SyncDevice::new(125.0, 8);
38    sync_device.is_paused = true;
39
40    // add empty tracks
41    for _ in track_names.iter() {
42        sync_device.tracks.push(SyncTrack::new());
43    }
44
45    loop {
46        // talk to Rocket
47        match rocket.update(&mut sync_device) {
48            Ok(_) => {},
49            Err(err) => {
50                // It's a Box<Error>, so we can't restore the original type.
51                // Let's parse the debug string for now.
52                let msg: &str = &format!("{:?}", err);
53                if msg.contains("kind: UnexpectedEof") {
54                    println!("Rocket disconnected. Exiting.");
55                    exit(2);
56                } else {
57                    error!("{}", msg);
58                }
59            },
60        }
61
62        if !sync_device.is_paused {
63            match rocket.send_row(&mut sync_device) {
64                Ok(_) => {},
65                Err(e) => warn!("{:?}", e),
66            }
67        }
68
69        // calculate track values and print
70        println!("Row: {}, Time: {}", sync_device.row, sync_device.time);
71
72        for (idx, track) in sync_device.tracks.iter().enumerate() {
73            println!("Track {} : {:>10.5}", track_names[idx], track.value_at(sync_device.row));
74        }
75
76        // update time
77        if !sync_device.is_paused {
78            sync_device.time += 16;// 1s / 60 frames
79            sync_device.set_row_from_time();
80        }
81
82        // sleep a bit
83        sleep(Duration::from_millis(16));
84
85    }
86
87}
Source

pub fn update( &mut self, device: &mut SyncDevice, ) -> Result<bool, Box<dyn Error>>

Read from the stream and process commands until the server runs out of things to send.

Returns an Ok(true) if there should be a redraw.

Examples found in repository?
examples/basic_example.rs (line 47)
16fn main() {
17    env_logger::init().unwrap();
18    info!("main: started");
19
20    // Connect to the Rocket Editor (server process)
21    let mut rocket: SyncClient = match SyncClient::new("localhost:1338") {
22        Ok(x) => { info!("Connected to Rocket"); x },
23        Err(_) => { println!("Couldn't connect to Rocket"); exit(2); },
24    };
25
26    let track_names = vec![
27        "group0#track0".to_owned(),
28        "group0#track1".to_owned(),
29        "group0#track2".to_owned(),
30        "group1#track0".to_owned(),
31        "group1#track1".to_owned(),
32        "group1#track2".to_owned(),
33    ];
34
35    rocket.send_track_names(&track_names).unwrap();
36
37    let mut sync_device: SyncDevice = SyncDevice::new(125.0, 8);
38    sync_device.is_paused = true;
39
40    // add empty tracks
41    for _ in track_names.iter() {
42        sync_device.tracks.push(SyncTrack::new());
43    }
44
45    loop {
46        // talk to Rocket
47        match rocket.update(&mut sync_device) {
48            Ok(_) => {},
49            Err(err) => {
50                // It's a Box<Error>, so we can't restore the original type.
51                // Let's parse the debug string for now.
52                let msg: &str = &format!("{:?}", err);
53                if msg.contains("kind: UnexpectedEof") {
54                    println!("Rocket disconnected. Exiting.");
55                    exit(2);
56                } else {
57                    error!("{}", msg);
58                }
59            },
60        }
61
62        if !sync_device.is_paused {
63            match rocket.send_row(&mut sync_device) {
64                Ok(_) => {},
65                Err(e) => warn!("{:?}", e),
66            }
67        }
68
69        // calculate track values and print
70        println!("Row: {}, Time: {}", sync_device.row, sync_device.time);
71
72        for (idx, track) in sync_device.tracks.iter().enumerate() {
73            println!("Track {} : {:>10.5}", track_names[idx], track.value_at(sync_device.row));
74        }
75
76        // update time
77        if !sync_device.is_paused {
78            sync_device.time += 16;// 1s / 60 frames
79            sync_device.set_row_from_time();
80        }
81
82        // sleep a bit
83        sleep(Duration::from_millis(16));
84
85    }
86
87}
Source

pub fn send_row(&mut self, device: &SyncDevice) -> Result<(), Box<dyn Error>>

Examples found in repository?
examples/basic_example.rs (line 63)
16fn main() {
17    env_logger::init().unwrap();
18    info!("main: started");
19
20    // Connect to the Rocket Editor (server process)
21    let mut rocket: SyncClient = match SyncClient::new("localhost:1338") {
22        Ok(x) => { info!("Connected to Rocket"); x },
23        Err(_) => { println!("Couldn't connect to Rocket"); exit(2); },
24    };
25
26    let track_names = vec![
27        "group0#track0".to_owned(),
28        "group0#track1".to_owned(),
29        "group0#track2".to_owned(),
30        "group1#track0".to_owned(),
31        "group1#track1".to_owned(),
32        "group1#track2".to_owned(),
33    ];
34
35    rocket.send_track_names(&track_names).unwrap();
36
37    let mut sync_device: SyncDevice = SyncDevice::new(125.0, 8);
38    sync_device.is_paused = true;
39
40    // add empty tracks
41    for _ in track_names.iter() {
42        sync_device.tracks.push(SyncTrack::new());
43    }
44
45    loop {
46        // talk to Rocket
47        match rocket.update(&mut sync_device) {
48            Ok(_) => {},
49            Err(err) => {
50                // It's a Box<Error>, so we can't restore the original type.
51                // Let's parse the debug string for now.
52                let msg: &str = &format!("{:?}", err);
53                if msg.contains("kind: UnexpectedEof") {
54                    println!("Rocket disconnected. Exiting.");
55                    exit(2);
56                } else {
57                    error!("{}", msg);
58                }
59            },
60        }
61
62        if !sync_device.is_paused {
63            match rocket.send_row(&mut sync_device) {
64                Ok(_) => {},
65                Err(e) => warn!("{:?}", e),
66            }
67        }
68
69        // calculate track values and print
70        println!("Row: {}, Time: {}", sync_device.row, sync_device.time);
71
72        for (idx, track) in sync_device.tracks.iter().enumerate() {
73            println!("Track {} : {:>10.5}", track_names[idx], track.value_at(sync_device.row));
74        }
75
76        // update time
77        if !sync_device.is_paused {
78            sync_device.time += 16;// 1s / 60 frames
79            sync_device.set_row_from_time();
80        }
81
82        // sleep a bit
83        sleep(Duration::from_millis(16));
84
85    }
86
87}
Source

pub fn send_track_names( &mut self, track_names: &Vec<String>, ) -> Result<(), Box<dyn Error>>

Send track names to Rocket, including group prefix

Examples found in repository?
examples/basic_example.rs (line 35)
16fn main() {
17    env_logger::init().unwrap();
18    info!("main: started");
19
20    // Connect to the Rocket Editor (server process)
21    let mut rocket: SyncClient = match SyncClient::new("localhost:1338") {
22        Ok(x) => { info!("Connected to Rocket"); x },
23        Err(_) => { println!("Couldn't connect to Rocket"); exit(2); },
24    };
25
26    let track_names = vec![
27        "group0#track0".to_owned(),
28        "group0#track1".to_owned(),
29        "group0#track2".to_owned(),
30        "group1#track0".to_owned(),
31        "group1#track1".to_owned(),
32        "group1#track2".to_owned(),
33    ];
34
35    rocket.send_track_names(&track_names).unwrap();
36
37    let mut sync_device: SyncDevice = SyncDevice::new(125.0, 8);
38    sync_device.is_paused = true;
39
40    // add empty tracks
41    for _ in track_names.iter() {
42        sync_device.tracks.push(SyncTrack::new());
43    }
44
45    loop {
46        // talk to Rocket
47        match rocket.update(&mut sync_device) {
48            Ok(_) => {},
49            Err(err) => {
50                // It's a Box<Error>, so we can't restore the original type.
51                // Let's parse the debug string for now.
52                let msg: &str = &format!("{:?}", err);
53                if msg.contains("kind: UnexpectedEof") {
54                    println!("Rocket disconnected. Exiting.");
55                    exit(2);
56                } else {
57                    error!("{}", msg);
58                }
59            },
60        }
61
62        if !sync_device.is_paused {
63            match rocket.send_row(&mut sync_device) {
64                Ok(_) => {},
65                Err(e) => warn!("{:?}", e),
66            }
67        }
68
69        // calculate track values and print
70        println!("Row: {}, Time: {}", sync_device.row, sync_device.time);
71
72        for (idx, track) in sync_device.tracks.iter().enumerate() {
73            println!("Track {} : {:>10.5}", track_names[idx], track.value_at(sync_device.row));
74        }
75
76        // update time
77        if !sync_device.is_paused {
78            sync_device.time += 16;// 1s / 60 frames
79            sync_device.set_row_from_time();
80        }
81
82        // sleep a bit
83        sleep(Duration::from_millis(16));
84
85    }
86
87}
Source

pub fn handle_set_key_cmd( &mut self, device: &mut SyncDevice, ) -> Result<(), Box<dyn Error>>

Adds a key frame to a track

Source

pub fn handle_del_key_cmd( &mut self, device: &mut SyncDevice, ) -> Result<(), Box<dyn Error>>

Deletes a key from a track

Source

pub fn handle_set_row_cmd( &mut self, device: &mut SyncDevice, ) -> Result<(), Box<dyn Error>>

Sets the current row from server. Sets the current time based on the row and rps.

Source

pub fn handle_pause_cmd( &mut self, device: &mut SyncDevice, ) -> Result<(), Box<dyn Error>>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.