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
impl Resolve
Sourcepub async fn new_with_config(config: &ResolveConfig) -> Result<Self, Error>
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
Sourcepub fn id(&self) -> u32
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.
Sourcepub fn dir(&self) -> PathBuf
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
Sourcepub async fn execute<T>(
&self,
script: impl Into<Script<'_>>,
) -> Result<T, Error>where
T: DeserializeOwned,
pub async fn execute<T>(
&self,
script: impl Into<Script<'_>>,
) -> Result<T, Error>where
T: DeserializeOwned,
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
Sourcepub async fn store(
&self,
script: impl Into<Script<'_>>,
) -> Result<ItemRef, Error>
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
Sourcepub async fn store_option(
&self,
script: impl Into<Script<'_>>,
) -> Result<Option<ItemRef>, Error>
pub async fn store_option( &self, script: impl Into<Script<'_>>, ) -> Result<Option<ItemRef>, Error>
Sourcepub async fn store_list(
&self,
script: impl Into<Script<'_>>,
) -> Result<ItemRefList, Error>
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
Sourcepub async fn table_keys<T>(&self, item: &ItemRef) -> Result<Vec<T>, Error>where
T: DeserializeOwned,
pub async fn table_keys<T>(&self, item: &ItemRef) -> Result<Vec<T>, Error>where
T: DeserializeOwned,
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
Sourcepub async unsafe fn shutdown(&self) -> Result<(), Error>
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.