Checking unregistered Cues using the CSV

In the Creating a Cue Sheet using CSV tutorial, we introduced how to register waveform file from the CSV information, and how to create a Cue Sheet and Cue.
In this tutorial, we will write a Script by using the same CSV file we used in the Creating a Cue Sheet using CSV tutorial, to check whether the Cue Sheet contents are correct.

This tutorial uses the project executed by Creating a Cue Sheet using CSV tutorial.
Before starting this tutorial, if this project is not open, please open the project or execute the Script created in the Creating a Cue Sheet using CSV tutorial.

Preparing a Script file

Select "Script list..." in the Script menu to display the Script list window.
Click the New button in the Script list window to create a Script file with the name below:

Save location of Script Script file name
tutorials [CRI] tutorial07-2_check_cuesheet_from_csv.py

Script Description

Double-click the created Script to open by Run the Script from the Script Editor .
In order to get an overview of the Script in the Script list window, write the Script description as follows:

# --Description:[Tutorial] Checking unregister Cues using the CSV

Importing Module

After writing the Script description, import the following module to work with CRI Atom Craft in the Script:

import sys
import os
import csv
import cri.atomcraft.debug as acdebug
import cri.atomcraft.project as acproject

Import "csv" module of the Python standard library for using the CSV file that is the same as Creating a Cue Sheet using CSV tutorial.
Import the Project Module to work with the project and import the Debug Module for log output.

Setting the path of the CSV file

Set the path variable of the CSV file to use for checking.
Write a Script to set the path variable of the CSV file as follows:

# Path of the CSV file to check
csv_path = os.path.dirname(os.path.dirname(__file__)) + '/tutorial_data/tutorial_data03/tutorial_data3.csv'
# Check if the CSV file exists
if os.path.isfile(csv_path) == False:
acdebug.warning("CSV file not found: " + csv_path)
sys.exit()

If the file does not exist, the Script can be interrupted by the os.path.isfile function to check if the file exists.

Cue list to check and list of Cue name

Use the following function to read the CSV file and get the information for checking.

Function name Description
get_workunit Gets the Work Unit
get_cuesheet_rootfolder Gets the Cue Sheet root folder of Work Unit
get_child_object Gets the child object by specifying the parent object
find_objects Performs recursive search to get the matched object in list format
get_value Gets the parameter of the specified object

In order to check if there is a matching Cue name, get the Cue list registered in the Cue Sheet to get the Cue name information.
Write a Script for these processes as follows:

# ----- List the registered Cue names -----
registered_cue_name_list = []
# Get a Work Unit
workunit = acproject.get_workunit("WorkUnit_Tutorial")["data"]
# Get a Cue Sheet root folder
cuesheet_rootfolder = acproject.get_cuesheet_rootfolder(workunit)["data"]
# Get a Cue Sheet by getting the Cue Sheet name from the CSV file name (without the extension)
cuesheet_name = os.path.splitext(os.path.basename(csv_path))[0]
cuesheet = acproject.get_child_object(cuesheet_rootfolder, "CueSheet", cuesheet_name)["data"]
# Get a Cue list that is registered in the Cue Sheet
cues = acproject.find_objects(cuesheet, "Cue")["data"]
# ----- Create a list of registered Cue names -----
acdebug.log("Collecting the Cue information from tutorial_data3.csv ...")
for cue in cues:
# Get a Cue name
cue_name = acproject.get_value(cue, "Name")["data"]
# Add the Cue name to the registered Cue name list
registered_cue_name_list.append(cue_name)

Compare the Cue names in the Cue Sheets with those in the CSV

Retrieve the "Cue name" information for checking from the CSV.
Check if the Cue name list created in "<b> Cue list to check and enumeration of Cue names </b>" contains the Cue name information obtained from the CSV.
If there is a Cue that is not created in the Cue Sheet, the Cue name will be displayed in the Script log.

Write a Script for these processes as follows:

# Open the CSV to check the Cue in the Cue Sheet
acdebug.log("Use tutorial_data3.csv to check the Cue...")
unregistered_cue_name_list = []
with open(csv_path) as f:
reader = csv.reader(f)
for row in reader:
# Get the Cue name row in the CSV
cue_name = row[1]
# Check if the Cue in the CSV is registered
if not cue_name in registered_cue_name_list:
# Not yet register
unregistered_cue_name_list.append(cue_name)
# Check
if len(unregistered_cue_name_list) > 0:
acdebug.warning(cuesheet_name + "contains a Cue that is not registered.")
for cue_name in unregistered_cue_name_list:
acdebug.warning("Cue " + cue_name + " not found.")
else:
acdebug.log("No difference from the check sheet.")
acdebug.log("[Tutorial]Use the CSV to check unregistered Cue is completed.")

Saving and running the Script

This concludes the scripting portion of this tutorial.
Save and run the Script.
If the Script runs successfully and finds a Cue name without the CSV information, a list of Cue names that do not exist will be output to the log.
By directly using CRI Atom Craft to add/remove the Cue and change the Cue name, the log contents of the mismatched Cues will be displayed.