Skip to main content

Resolve

Struct Resolve 

Source
pub struct Resolve { /* private fields */ }
Expand description

A connection to DaVinci Resolve.

Used to run lua code with it’s Scripting API available.

§Globals

resolve will always point to the value returned from Resolve(), which is the root of the Scripting API in DaVinci Resolve.
This is so you don’t have to call it yourself everytime.

Depending on the context that a Script was executed from, self will be the current active instance.
When executing from Resolve, self is the root, so resolve.
When executing from ItemRef, self is the stored value, which can be anything.

§Single-Threaded

The script server that this spins up can only accept requests one at a time.
If you wish to send multiple scripts to execute at the same time, start a new Resolve instance and use that.

Or you can use PooledResolve to start multiple instances at the same time and use any available on when executing. Look at it’s doc for more info.

§Clone

The internal connection to DaVinci Resolve is the same if you were to run .clone() on Resolve.
So Resolve can be cheaply cloned and passed around.

Implementations§

Source§

impl Resolve

Source

pub async fn new() -> Result<Self, Error>

Creates a new Resolve connection instance.

This creates a temporary directory with relevant script and dlls files.
Launches fuscript and starts a local script server that Resolve can use.

§Errors

If the internal lua module fails to reach DaVinci Resolve or the creation of this instance fails

Source

pub async fn new_with_config(config: &ResolveConfig) -> Result<Self, Error>

Creates a new Resolve instance with the specified ResolveConfig.

§Errors
  • If it fails to create a temporary directory
  • The setup server communication fails
  • The module startup fails
Source

pub fn id(&self) -> u32

Returns a unique id to this specific Resolve instance, can be used to check if two instances are the same or not.

Source

pub fn dir(&self) -> PathBuf

Returns the directory which this instance will place it’s temporary files.
Including log files generated by the module when enabling tracing in ResolveConfig

Source

pub async fn execute<T>( &self, script: impl Into<Script<'_>>, ) -> Result<T, Error>

Execute some lua code, the returned value in the code will be returned here.

Using Script (or it’s script! macro) you can pass in arguments to your code.\

§Globals

Instead of calling Resolve() every time to reach for the Scripting API, you can use resolve. resolve is always available in the global context no matter which .execute you run.

self on the other hand is special to your active instance. If you run execute from Resolve, self will also be the value of the resolve global. But if you run execute from an ItemRef, that stored value will be self.

sleep(ms) is also an available function.

§Examples
§Simple
let resolve = Resolve::new().await?;
let version = resolve.execute::<String>(r#"return self:GetVersionString()"#).await?;
assert!(!version.is_empty());
§Arguments
let resolve = Resolve::new().await?;
let script = Script::new("return my_var + secret")
    .named_arg("my_var", 5)?
    .named_arg("secret", u8::MAX)?;
let result = resolve.execute::<i32>(script).await?;
assert_eq!(260, result);
§On Reference

Look more at ItemRef and store for more info on this.

let resolve = Resolve::new().await?;
let pm = resolve.store("return self:GetProjectManager()").await?;
pm.execute::<()>("self:SaveProject()").await?;
§Errors

If the module executing the code fails or if the script can’t be sent

Source

pub async fn store( &self, script: impl Into<Script<'_>>, ) -> Result<ItemRef, Error>

Store a reference to Lua value in Rust

Instead of returning some value, you get an ItemRef. This is just an id that resolves to the stored value when executing.

You can store any value as an ItemRef, a number, a function, or even an instance of a timeline!
Except for nil, in that scenario this returns Error::NilItemRef.

And you can also can execute and .store on the ItemRef itself. in that case, the global variable self becomes the value of that ItemRef

§Example
let resolve = Resolve::new().await?;
let page: ItemRef = resolve.store("return self:GetCurrentPage()").await?;

resolve.execute::<()>(Script::new("self:OpenPage(arg[1])").arg_ref(&page)?).await?;
§Errors

If the module executing the code fails, if the script can’t be sent or if the returned value is nil

Source

pub async fn store_option( &self, script: impl Into<Script<'_>>, ) -> Result<Option<ItemRef>, Error>

Maybe stores a reference to Lua value in Rust

If the returned value is nil, this will return None.

Look at store for more info.

§Errors

If the module executing the code fails or if the script can’t be sent

Source

pub async fn store_list( &self, script: impl Into<Script<'_>>, ) -> Result<ItemRefList, Error>

Store multiple references to Lua values in Rust

Instead of returning some value, you get an ItemRefList. This is a list of ids that resolves into the stored value when executing on them.

The returned value in the Lua code but must be of type Table.

You can use .list() on the ItemRefList to iterate over all ItemRef’s inside.

§Example
let resolve = Resolve::new().await?;
let timeline = resolve.store(r#"
    local pm = self:GetProjectManager()
    local p = pm:GetCurrentProject()
    return p:GetCurrentTimeline()
"#).await?;

// Once we have our timeline, we can get a list of references to *all* clips on video track 1
let clips = timeline.store_list(r#"self:GetItemListInTrack("video", 1)"#).await?;
for clip in &clips.list() {
    let name: String = clip.execute("self:GetName()").await?;
    println!("{name}");
}
§Errors

If the module executing the code fails or if the script can’t be sent.
Or if the returned value from lua was not a table

Source

pub async fn table_keys<T>(&self, item: &ItemRef) -> Result<Vec<T>, Error>

Get all keys from a referenced table

If you want all values from a table, see store_list.

The value stored in the ItemRef must be of type Table in lua.

§Example

The following table:

return { a = 1, b = 2, c = 3 }

would return ["a", "b", "c"] and T would be of type String here.

§Errors

If the module executing the code fails or if the script can’t be sent, or if the referenced ItemRef is not a table

Source

pub async unsafe fn shutdown(&self) -> Result<(), Error>

Shutdowns the connected module.

Any other calls to this Resolve client and it’s references will always return an Error::ModuleNotRunning.

§Errors

If the shutdown packet fails to send to the module

§Safety

All functions become null and void and does nothing other than return errors.

Trait Implementations§

Source§

impl Clone for Resolve

Source§

fn clone(&self) -> Resolve

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Resolve

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Resolve

Source§

impl Hash for Resolve

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Resolve

Source§

fn eq(&self, other: &Resolve) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ResolveExecute for Resolve

Source§

fn execute<'c, T: DeserializeOwned + Send>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<T, Error>> + Send

Source§

impl ResolveStore for Resolve

Source§

fn store<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<ItemRef, Error>> + Send

Source§

fn store_option<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<Option<ItemRef>, Error>> + Send

Source§

fn store_list<'c>( &'c self, script: impl Into<Script<'c>> + Send, ) -> impl Future<Output = Result<ItemRefList, Error>> + Send

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V