Binding Reference
Type
Base type of all object types. The following accessors are defined for objects off all derived types:
Operators | |
---|---|
| Returns a string representation describing the object |
Properties | |
---|---|
| Returns type information as a string in the form Type‘Tag |
| Returns the parent object or nil |
Functions | |
---|---|
| Returns true if object value is equal to the value of other |
| Returns true if object is an instance of type i.e. |
| Returns true if object is an instance of a type named name i.e. |
| Returns true if object is a direct child of other i.e. |
| Returns true if object is a direct child of an object of type i.e. |
| Returns true if object is a direct child of an object of a type named name i.e. |
Scalars
Basic types which contain a single value:
Bool | Boolean, true or false |
Int | 64 bit signed integer (can be negative) |
Real | 64 bit floating point number |
String | Text |
For a scalar object of these types the following accessors are defined:
Properties | |
---|---|
| Returns the value type |
| Returns true if the value is in the initial state |
| Returns the value |
Functions | |
---|---|
| Resets the value to its initial state |
| Assigns a copy of the other value object |
Vector
Type-safe, dynamically sized, zero-indexed, random access container.
For a vector object the following accessors are defined:
Constructors | |
---|---|
| Returns new vector |
| Returns a copy of the other vector |
| Returns a new vector with size elements |
| Returns a new vector initialized with variadic args |
Operators | |
---|---|
| Returns the number of elements i.e. the size of the vector |
| Returns an iterator function for iterating over all elements |
| Returns the value if vector type is scalar, otherwise returns the object |
| Sets value at index |
| Assigns object to index |
Properties | |
---|---|
| Returns the vector type |
| Returns true if the vector has no elements |
| Returns true if the vector is in its initial state |
Functions | |
---|---|
| Sets element at index to object |
| Returns object at index |
| Resets the vector to initial |
| Resizes the vector to size elements |
| Returns the object at path or nil |
| Assigns a copy of the other vector |
| Inserts object at the end |
| Inserts value at the end |
| Inserts object before index |
| Inserts value before index |
| Removes element at index |
Struct
Type-safe record with named fields.
For a struct object the following accessors are defined:
Constructors | |
---|---|
| Returns a new struct |
| Returns a copy of the other struct |
Operators | |
---|---|
| Returns the number of used fields |
| Returns an iterator function for iterating over used fields |
| Returns the value if field contains a scalar, otherwise returns the object |
| Sets element value of field |
| Assigns object to field |
Properties | |
---|---|
| Returns the struct type |
| Returns true if the struct has no used fields40 |
| Returns true if the struct is in its initial state |
Functions | |
---|---|
| Assigns object at index |
| Returns object at index |
| Resets the struct to its initial state |
| Resets the field at index |
| Resets the field |
| Returns true if the field is used |
| Returns the object at path |
| Assigns a copy of the other struct |
Algorithms
The following are free functions operating on any Type.
| Returns the path to object |
| Returns the object at path or nil |
| Recursively traverses object and calls function where key is the index or field name of the object in parent |
| Converts objects to a json string and returns it |
| Converts the string to an object of type and returns it |
File system
The Lua binding is based on the C++ library boost filesystem. In contrary to the original C++ design, the Lua binding does not define an abstraction for path. Instead, path always refers to a Lua string.
The following chapter lists functions from the aforementioned library and the associated data type they return. For a detailed description of each function, please refer to the reference documentation.
Examples
for _,p in filesystem.directory(path) do print(p) end
Lists paths in directory
for _,p in filesystem.directoryRecursive(path) do print(p) end
Lists paths in directory and all sub-directories
Functions
Note that all functions live in the global filesystem.
Iterators | |
---|---|
Function | Returned data type |
|
|
|
|
Path | |
---|---|
These functions return a string which contains the modified path. | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Query | |
---|---|
These functions query a given path. | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Operational | |
---|---|
These functions allow queries on the underlying filesystem. | |
Path | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Test | |
|
|
|
|
|
|
|
|
|
|
Last Write Time | |
---|---|
|
|
Links | |
---|---|
|
|
|
|
For convenience users can declare fs = filesystem
and call all filesystem functions using the fs prefix, demonstrated in the following example.
fs = filesystem iterator fs.directory(path) iterator fs.directoryRecursive(path)
PosixTime
Date and time related utility functions.
Functions | |
---|---|
| Converts the posix-time to an ISO string |
Note
Note that all functions live in the global table posixTime.
Example
print(posixTime.toString(filesystem.lastWriteTime(...)))
Converts filesystem lastWriteTime to a string.
MIR functions
Music Information Retrieval (MIR) is the science of retrieving information from music. Among others, it allows the extraction of meaningful features from audio files, such as the pitch or the velocity of a sample. Creator Tools come with a collection of MIR functions, to assist or automate parts of the instrument creation process.
Single functions retrieve information from single files and take as argument an absolute filename (the full path to the sample file). Batch processing functions retrieve information from folders and take as argument an absolute folder name (the full path to the sample folder).
Note
Note that all functions live in the global MIR table.
Pitch detection
The pitch detection tries to detect the fundamental frequency of a monophonic/single note sample. It corresponds to the MIDI scale (69 = 440 Hz) and ranges from semitone 15 (~20Hz) to semitone 120 (~8.4 kHz).
Functions | |
---|---|
| Returns a floating point number corresponding to the MIDI pitch value of the audio sample specified in the 'fullPathToSample' absolute file path. If detection fails it will return |
| Returns a Lua table with samplePath as the table key and a floating point number corresponding to the detected pitch as the value. If detection fails it will return |
Examples
pitchVal = mir.detectPitch('fullPathToSample')
Sets pitchVal
to the pitch of the sample at the 'fullPathToSample' filepath.
pitchBatchData = mir.detectPitchBatch('fullPathToFolder') pitchValue = pitchBatchData['fullPathToSample']
Detects pitch of the samples in the 'fullPathToFolder' directory and stores them in the Lua table pitchBatchData
. It then accesses pitchBatchData
via the key 'fullPathToSample' and stores the resulting value in pitchValue
Peak, RMS & Loudness detection
Loudness, Peak, and RMS functions return a value in dB, with a maximum at 0dB.
The RMS and Loudness functions are calculated over small blocks of audio. The duration of those blocks is called frame size and is expressed in seconds. The process is repeated in intervals equal to the hop size (also expressed in seconds), until it reaches the end of the sample. The functions return the overall loudest/highest value of the different blocks.
If frame size and hop size are not indicated, the default values 0.4 (frame size in seconds) and 0.1 (hop size in seconds) are applied respectively.
In the case that Loudness, Peak, or RMS detection fails, they will return constants kDetectLoudnessInvalid
, kDetectPeakInvalid
, kDetectRMSInvalid
, which all resolve to 1000000.0f
. When logging Peak, RMS, or Loudness values, invalid detections will be logged in numerical form.
Note
It is advised to compare against respective <k-type-invald>
constants in your scripts, since there is no guarantee that the numerical value will not change.
Functions | |
---|---|
Peak detection | |
| Returns a floating point number corresponding to the Peak value in dB of an audio sample at the 'fullPathToSample' absolute file path. If detection fails the constant |
| Returns a Lua table with samplePath as the table key and a floating point number corresponding to the peak value in dB as the value for all samples in the 'fullPathToFolder' directory. If detection fails the constant |
RMS detection | |
| Returns a floating point number corresponding to the RMS value in dB of an audio sample at the 'fullPathToSample' absolute file path. Frame size and hop size are optional arguments and default to 0.4 and 0.1 respectively if not specified. If detection fails the constant |
| Returns a Lua table with samplePath as the table key and a floating point number corresponding to the RMS value in dB as the value for all samples in the 'fullPathToFolder' directory. Frame size and hop size are optional arguments and default to 0.4 and 0.1 respectively if not specified. If detection fails the constant |
Loudness detection | |
| Returns a floating point number corresponding to the Loudness value in dB of an audio sample at the 'fullPathToSample' absolute file path. Frame size and hop size are optional arguments and default to 0.4 and 0.1 respectively if not specified. If detection fails the constant |
| Returns a Lua table with samplePath as the table key and a floating point number corresponding to the Loudness value in dB as the value for all samples in the 'fullPathToFolder' directory. Frame size and hop size are optional arguments and default to 0.4 and 0.1 respectively if not specified. If detection fails the constant |
Examples
peakVal = mir.detectPeak('fullPathToSample')
Analyses an audio sample at the 'fullPathToSample' absolute file path and stores the resulting Peak value in peakVal
.
rmsBatchData = mir.detectRMSBatch(‘fullPathToFolder', 0.02, 0.01)
Analyses all audio samples in the 'fullPathToFolder' directory and stores the resulting RMS values in the Lua table rmsBatchData
. For the calculation, Frame and Hop size have been specified to 0.02 and 0.01 respectively.
Type detection
Type detection is a means to determine which category a given audio sample belongs to. Currently, Creator Tools supports detection of three distinct types: Sample Type, Drum Type, and Instrument Type. Sample Type is used to determine if a sample is either a drum, or an instrument. Drum Type and Instrument Type both determine which drum or instrument category a sample belongs to. For each type, an INVALID
category is defined as helper for default initialisation.
Furthermore, in the case that Sample Type, Drum Type, or Instrument Type detection fails, they will return their respective INVALID type, which all resolve to -1
. When logging Sample Type, Drum Type, or Instrument Type values, invalid detections will be logged in numerical form. However, it is advised to compare against respective <type.INVALID>
constants in your scripts - since there is no guarantee that the numerical value will not change.
Note
Note that these type detection functions are designed to process one-shot audio samples.
Functions | |
---|---|
Sample type detection | |
| Returns the sample type of an audio sample at the 'fullPathToSample' absolute file path. Can return one of the following types:
|
| Processes a batch of audio samples in the folder specified by the 'fullPathToFolder' absolute path. Returns a Lua table with samplePath as the key and the respective sample type as the value. The returned types are the same as in the single function call above. |
Drum type detection | |
| Returns the drum type of an audio sample at the 'fullPathToSample' absolute file path. Can return one of the following types:
|
| Processes a batch of audio samples in the folder specified by the 'fullPathToFolder' absolute path. Returns a Lua table with samplePath as the key and the respective drum type as the value. The returned types are the same as in the single function call above. |
Instrument type detection | |
| Returns the instrument type of an audio sample at the 'fullPathToSample' absolute file path. Can return one of the following types:
|
| Processes a batch of audio samples in the folder specified by the 'fullPathToFolder' absolute path. Returns a Lua table with samplePath as the key and the respective instrument type as the value. The returned types are the same as in the single function call above. |
Examples
sampleType = mir.detectSampleType('fullPathToSample')
Analyses an audio sample at the 'fullPathToSample' absolute file path and stores the resulting sample type category in sampleType
.
drumType = mir.detectDrumType('fullPathToSample')
Analyses an audio sample at the 'fullPathToSample' absolute file path and stores the resulting drum type category in drumType
.
instType = mir.detectInstrumentType('fullPathToSample')
Analyses an audio sample at the 'fullPathToSample' absolute file path and stores the resulting instrument type category in instType
.
sampleTypeBatchData = mir.detectSampleTypeBatch(‘fullPathToFolder’)
Analyses audio samples in the 'fullPathToFolder' directory and stores the resulting sample types in the Lua table sampleTypeBatchData
.
Loop detection
The new findLoop()
MIR function, analyzes and suggests loop points for samples. The function returns two variables for the loop start and the loop end, which can then be used to set the loop points for the respective zone.
The full syntax for the function is findLoop(filePath, minStart, maxEnd, minLength)
. Apart from the path, all other arguments are optional. If only the path is supplied then the rest of the arguments are calculated by the algorithm.
Tip
You can use the existing MIR functions of Creator Tools, to determine different findLoop()
behaviours depending on the various sample features.
Example
local loop_start, loop_end = mir.findLoop(file) local loop_length = loop_end - loop_start z.loops[0].start = loop_start z.loops[0].length = loop_length