pub struct PluginContext { /* private fields */ }Expand description
Plugin context that provides access to VirtualDJ API functions
This struct holds the plugin pointer and callbacks, allowing safe access to VirtualDJ state information like track metadata, position, BPM, etc.
§Example
ⓘ
let context = PluginContext::new(plugin_ptr, &callbacks);
let title = context.get_info_string("deck 1 get_title")?;
let position = context.get_info_double("deck 1 get_position")?;Implementations§
Source§impl PluginContext
impl PluginContext
Sourcepub fn new(plugin: *mut VdjPlugin, callbacks: &VdjCallbacks) -> Self
pub fn new(plugin: *mut VdjPlugin, callbacks: &VdjCallbacks) -> Self
Sourcepub fn get_info_double(&self, command: &str) -> Result<f64>
pub fn get_info_double(&self, command: &str) -> Result<f64>
Query VirtualDJ for a double/numeric value
§Arguments
command- The VDJ script command (e.g., “deck 1 get_position”)
§Returns
A Result containing the numeric value, or an error if the command fails
Examples found in repository?
examples/query_vdj_state.rs (line 28)
22 pub fn query_deck_info(&self, context: &PluginContext, deck: i32) -> Result<()> {
23 // Get track title (like GetInfoText("deck 1 get_title") in C++)
24 let title = context.get_info_string(&format!("deck {} get_title", deck))?;
25 println!("Deck {} title: {}", deck, title);
26
27 // Get position as a double (like GetInfoDouble("deck 1 get_position") in C++)
28 let position = context.get_info_double(&format!("deck {} get_position", deck))?;
29 println!("Deck {} position: {}", deck, position);
30
31 // Check if deck is audible
32 let audible = context.get_info_string(&format!("deck {} is_audible", deck))?;
33 println!("Deck {} is audible: {}", deck, audible);
34
35 Ok(())
36 }
37
38 /// Example showing how to iterate through cues and query their properties
39 pub fn query_deck_cues(&self, context: &PluginContext, deck: i32) -> Result<()> {
40 // Get track title
41 let title = context.get_info_string(&format!("deck {} get_title", deck))?;
42
43 // Get current position
44 let cursor_percent = context.get_info_double(&format!("deck {} get_position", deck))?;
45
46 println!("\nQuerying cues for deck {} ({})", deck, title);
47 println!("Current position: {:.2}%", cursor_percent * 100.0);
48
49 // Check cues 1-8 (you can extend to 128 like in the C++ version)
50 for cue in 1..=8 {
51 // Check if cue exists
52 let has_cue = context.get_info_string(&format!("deck {} has_cue {}", deck, cue))?;
53
54 if has_cue.to_lowercase() != "on" {
55 continue;
56 }
57
58 // Get cue name
59 let cue_name = context.get_info_string(&format!("deck {} cue_name {}", deck, cue))?;
60
61 // Get cue position
62 let cue_pos = context.get_info_double(&format!("deck {} cue_pos {}", deck, cue))?;
63
64 if cue_pos >= 0.0 {
65 println!(" Cue {}: {} (position: {:.2}%)", cue, cue_name, cue_pos * 100.0);
66 }
67 }
68
69 Ok(())
70 }Sourcepub fn get_info_string(&self, command: &str) -> Result<String>
pub fn get_info_string(&self, command: &str) -> Result<String>
Query VirtualDJ for a string value
§Arguments
command- The VDJ script command (e.g., “deck 1 get_title”)
§Returns
A Result containing the string value, or an error if the command fails
Examples found in repository?
examples/query_vdj_state.rs (line 24)
22 pub fn query_deck_info(&self, context: &PluginContext, deck: i32) -> Result<()> {
23 // Get track title (like GetInfoText("deck 1 get_title") in C++)
24 let title = context.get_info_string(&format!("deck {} get_title", deck))?;
25 println!("Deck {} title: {}", deck, title);
26
27 // Get position as a double (like GetInfoDouble("deck 1 get_position") in C++)
28 let position = context.get_info_double(&format!("deck {} get_position", deck))?;
29 println!("Deck {} position: {}", deck, position);
30
31 // Check if deck is audible
32 let audible = context.get_info_string(&format!("deck {} is_audible", deck))?;
33 println!("Deck {} is audible: {}", deck, audible);
34
35 Ok(())
36 }
37
38 /// Example showing how to iterate through cues and query their properties
39 pub fn query_deck_cues(&self, context: &PluginContext, deck: i32) -> Result<()> {
40 // Get track title
41 let title = context.get_info_string(&format!("deck {} get_title", deck))?;
42
43 // Get current position
44 let cursor_percent = context.get_info_double(&format!("deck {} get_position", deck))?;
45
46 println!("\nQuerying cues for deck {} ({})", deck, title);
47 println!("Current position: {:.2}%", cursor_percent * 100.0);
48
49 // Check cues 1-8 (you can extend to 128 like in the C++ version)
50 for cue in 1..=8 {
51 // Check if cue exists
52 let has_cue = context.get_info_string(&format!("deck {} has_cue {}", deck, cue))?;
53
54 if has_cue.to_lowercase() != "on" {
55 continue;
56 }
57
58 // Get cue name
59 let cue_name = context.get_info_string(&format!("deck {} cue_name {}", deck, cue))?;
60
61 // Get cue position
62 let cue_pos = context.get_info_double(&format!("deck {} cue_pos {}", deck, cue))?;
63
64 if cue_pos >= 0.0 {
65 println!(" Cue {}: {} (position: {:.2}%)", cue, cue_name, cue_pos * 100.0);
66 }
67 }
68
69 Ok(())
70 }
71
72 /// Example showing how to send commands (like SendCommand in C++)
73 pub fn send_example_command(&self, context: &PluginContext) -> Result<()> {
74 // Play deck 1
75 context.send_command("deck 1 play")?;
76 println!("Sent: deck 1 play");
77
78 // You can also use the parsed information to make decisions
79 let active_deck_str = context.get_info_string("get_activedeck")?;
80 let active_deck: i32 = active_deck_str.parse().unwrap_or(1);
81 println!("Active deck: {}", active_deck);
82
83 Ok(())
84 }Sourcepub fn send_command(&self, command: &str) -> Result<()>
pub fn send_command(&self, command: &str) -> Result<()>
Send a command to VirtualDJ
§Arguments
command- The VDJ script command (e.g., “deck 1 play”)
§Returns
Ok(()) if successful, or an error if the command fails
Examples found in repository?
examples/query_vdj_state.rs (line 75)
73 pub fn send_example_command(&self, context: &PluginContext) -> Result<()> {
74 // Play deck 1
75 context.send_command("deck 1 play")?;
76 println!("Sent: deck 1 play");
77
78 // You can also use the parsed information to make decisions
79 let active_deck_str = context.get_info_string("get_activedeck")?;
80 let active_deck: i32 = active_deck_str.parse().unwrap_or(1);
81 println!("Active deck: {}", active_deck);
82
83 Ok(())
84 }Auto Trait Implementations§
impl Freeze for PluginContext
impl RefUnwindSafe for PluginContext
impl !Send for PluginContext
impl !Sync for PluginContext
impl Unpin for PluginContext
impl UnsafeUnpin for PluginContext
impl UnwindSafe for PluginContext
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