Skip to main content

PluginContext

Struct PluginContext 

Source
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

Source

pub fn new(plugin: *mut VdjPlugin, callbacks: &VdjCallbacks) -> Self

Create a new plugin context

§Arguments
  • plugin - Pointer to the VdjPlugin struct
  • callbacks - Reference to the VdjCallbacks struct
§Safety

The plugin pointer must be valid and the callbacks must remain valid for the lifetime of this context.

Source

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    }
Source

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    }
Source

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§

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.