2022-07-01 22:33:37 +01:00
/// Standard help string containing usage information for Muss.
2022-01-04 02:22:22 +00:00
pub const HELP_STRING : & str =
2022-01-04 02:15:28 +00:00
" This language is all about iteration. Almost everything is an iterator or operates on iterators. By default, any operation which is not an assignment will cause the script runner to handle (play/save) the items which that statement contains.
2022-07-09 02:24:46 +01:00
To view Muss syntax , try ? functions , ? filters , ? procedures , or ? sorters
To view REPL commands , try ? commands " ;
2022-01-04 02:15:28 +00:00
2022-01-04 02:22:22 +00:00
pub const FUNCTIONS : & str =
2022-01-04 02:15:28 +00:00
" FUNCTIONS (?functions)
Similar to most other languages : function_name ( param1 , param2 , etc . )
2022-01-18 14:20:26 +00:00
These always return an iterable which can be manipulated .
2022-01-04 02:15:28 +00:00
sql_init ( generate = true | false , folder = ` path / to / music ` )
2022-03-27 16:50:59 +01:00
Initialize the SQLite database connection using the provided parameters . This must be performed before any other database operation ( otherwise the database will already be connected with default settings ) . Returns an empty iterable .
2022-01-04 02:15:28 +00:00
sql ( ` SQL query here ` )
2022-07-01 22:33:37 +01:00
Perform a raw SQLite query on the database which Muss auto - generates . An iterator of the results is returned .
2022-01-04 02:15:28 +00:00
song ( ` something ` )
Retrieve all songs in the database with a title like something .
album ( ` something ` )
Retrieve all songs in the database with an album title like something .
artist ( ` something ` )
Retrieve all songs in the database with an artist name like something .
genre ( ` something ` )
Retrieve all songs in the database with a genre title like something .
repeat ( iterable , count )
Repeat the iterable count times , or infinite times if count is omitted .
files ( folder = ` path / to / music ` , recursive = true | false , regex = ` pattern ` )
2022-01-27 21:06:32 +00:00
Retrieve all files from a folder , matching a regex pattern .
2022-05-14 19:24:18 +01:00
mpd ( address , term = value , term2 = value2 , .. . ) ;
Retrieve songs from a music player daemon at address . If compiled without the music_library feature , this is equivalent to the empty ( ) function .
2022-01-31 02:13:19 +00:00
reset ( iterable )
Explicitly reset an iterable . This useful for reusing an iterable variable .
2022-02-01 22:15:25 +00:00
interlace ( iterable1 , iterable2 , .. . )
2022-03-27 16:50:59 +01:00
Combine multiple iterables in an interleaved pattern . This is a variant of union ( .. . ) where the first item in iterable1 , then iterable2 , .. . is returned , then the second item , etc . until all iterables are depleted . There is no limit to the amount of iterables which can be provided as parameters .
2022-02-01 22:15:25 +00:00
union ( iterable1 , iterable2 , .. . )
2022-03-27 16:50:59 +01:00
Combine multiple iterables in a sequential pattern . All items in iterable1 are returned , then all items in iterable2 , .. . until all provided iterables are depleted . There is no limit to the amount of iterables which can be provided as parameters .
2022-02-01 22:15:25 +00:00
2022-02-02 20:53:57 +00:00
intersection ( iterable1 , iterable2 , .. . ) ;
2022-03-27 16:50:59 +01:00
Combine multiple iterables such that only items that exist in iterable1 and iterable2 and .. . are returned . The order of items from iterable1 is maintained . There is no limit to the amount of iterables which can be provided as parameters .
2022-02-02 20:53:57 +00:00
2022-01-27 21:06:32 +00:00
empty ( )
2022-03-02 01:44:46 +00:00
Empty iterator . Useful for deleting items using replacement filters .
empties ( count ) ;
Iterate over count empty items . The items in this iterator have no fields ( i . e . are empty ) . " ;
2022-01-04 02:15:28 +00:00
2022-01-04 02:22:22 +00:00
pub const FILTERS : & str =
2022-01-04 02:15:28 +00:00
" FILTERS (?filters)
Operations to reduce the items in an iterable : iterable . ( filter )
field = = something
2022-01-26 20:57:48 +00:00
field like something
2022-06-19 02:46:33 +01:00
field unlike something
2022-02-02 18:12:56 +00:00
field matches some_regex
2022-01-17 02:00:00 +00:00
field ! = something
2022-01-04 02:15:28 +00:00
field > = something
field > something
field < = something
2022-01-17 02:00:00 +00:00
field < something - - e . g . iterable . ( title = = ` Romantic Traffic ` )
2022-07-01 22:33:37 +01:00
Compare all items , keeping only those that match the condition . Valid field names change depending on what information is available when the Item is populated , but usually title , artist , album , genre , track , filename are valid fields . Optionally , a ? or ! can be added to the end of the field name to skip items whose field is missing / incomparable , or keep all items whose field is missing / incomparable ( respectively ) .
2022-01-04 02:15:28 +00:00
2022-01-17 02:00:00 +00:00
start .. end - - e . g . iterable . ( 0 .. 42 )
Keep only the items that are at the start index up to the end index . Start and / or end may be omitted to start / stop at the iterable ' s existing start / end ( respectively ) . This stops once the end condition is met , leaving the rest of the iterator unconsumed .
start ..= end - - e . g . iterable . ( 0 ..= 42 )
Keep only the items that are at the start index up to and including the end index . Start may be omitted to start at the iterable ' s existing start . This stops once the end condition is met , leaving the rest of the iterator unconsumed .
index - - e . g . iterable . ( 4 )
Keep only the item at the given index . This stops once the index is reached , leaving the rest of the iterator unconsumed .
2022-01-17 02:48:32 +00:00
filter1 | | filter2 - - e . g . iterable . ( 4 | | 5 )
Keep only the items that meet the criteria of filter1 or filter2 . This will always consume the full iterator .
2022-01-17 02:00:00 +00:00
[ empty ] - - e . g . iterable . ( )
2022-01-18 14:14:05 +00:00
Matches all items
if filter : operation1 else operation2 - - e . g . iterable . ( if title = = ` Romantic Traffic ` : repeat ( item , 2 ) else item . ( ) )
2022-02-28 22:49:08 +00:00
Replace items matching the filter with operation1 and replace items not matching the filter with operation2 . The ` else operation2 ` part may be omitted to preserve items not matching the filter . To perform operations with the current item , use the special variable ` item ` . The replacement filter may not contain | | - - instead , use multiple filters chained together .
unique
unique field - - e . g . iterable . ( unique title )
2022-05-14 16:10:03 +01:00
Keep only items which are do not duplicate another item , or keep only items whoes specified field does not duplicate another item ' s same field . The first non - duplicated instance of an item is always the one that is kept .
? ?
Keep only the items that contain at least one field ( not including the filename field ) . " ;
2022-01-25 15:03:27 +00:00
pub const SORTERS : & str =
" SORTERS (?sorters)
Operations to sort the items in an iterable : iterable ~ ( sorter ) OR iterable . sort ( sorter )
field - - e . g . iterable ~ ( filename )
2022-07-02 21:09:58 +01:00
Sort by an Item field . Valid field names change depending on what information is available when the Item is populated , but usually title , artist , album , genre , track , filename are valid fields . Items with a missing / incomparable fields will be sorted to the end .
2022-01-25 15:03:27 +00:00
2022-01-31 02:13:19 +00:00
shuffle
random shuffle - - e . g . iterable ~ ( shuffle )
Shuffle the songs in the iterator . This is random for up to 2 ^ 16 items , and then the randomness degrades ( but at that point you won ' t notice ) .
2022-01-28 00:55:43 +00:00
advanced bliss_first - - e . g . iterable ~ ( advanced bliss_first )
2022-07-01 22:33:37 +01:00
Sort by the distance ( similarity ) from the first song in the iterator . Songs which are more similar ( lower distance ) to the first song in the iterator will be placed closer to the first song , while less similar songs will be sorted to the end . This uses the bliss music analyser , which is a very slow operation and can cause music playback interruptions for large iterators . Requires ` advanced ` interpreter feature .
2022-01-28 00:55:43 +00:00
advanced bliss_next - - e . g . iterable ~ ( advanced bliss_next )
2022-07-01 22:33:37 +01:00
Sort by the distance ( similarity ) between the last played song in the iterator . Similar to bliss_first . Songs which are more similar ( lower distance ) to the first song in the iterator will be placed closer to the first song , while less similar songs will be sorted to the end . This uses the bliss music analyser , which is a very slow operation and can cause music playback interruptions for large iterators . Requires ` advanced ` interpreter feature . " ;
2022-02-23 16:33:45 +00:00
pub const PROCEDURES : & str =
" PROCEDURES (?procedures)
Operations to apply to each item in an iterable : iterable . { step1 , step2 , .. . }
Comma - separated procedure steps will be executed sequentially ( like a for loop in regular programming languages ) . The variable item contains the current item of the iterable .
let variable = something - - e . g . let my_var = 42
Declare the variable and ( optionally ) set the initial value to something . The assignment will only be performed when the variable has not yet been declared . When the initial value ( and equals sign ) is omitted , the variable is initialized as empty ( ) .
variable = something - - e . g . my_var = 42
Assign something to the variable . The variable must have already been declared .
empty ( ) - - e . g . empty ( )
The empty or null constant .
if condition { something } else { something_else } - - e . g .
if item . title = = ` Romantic Traffic ` {
} else {
remove item
}
Branch based on a boolean condition . Multiple comma - separated procedure steps may be supplied in the if and else branches . This does not currently support if else chains , but they can be nested to accomplish similar behaviour .
something1 = = something2
something1 ! = something2
something1 > = something2
something1 > something2
something1 < = something2
something1 < something2 - - e . g . item . filename ! = item . title
Compare something1 to something2 . The result is a boolean which is useful for branch conditions .
op iterable_operation - - e . g . op files ( ) . ( 0 ..= 42 ) ~ ( shuffle )
An iterable operation inside of the procedure . When assigned to item , this can be used to replace item with multiple others . Note that iterable operations are never executed inside the procedure ; when item is iterable , it will be executed immediately after the end of the procedure for the current item .
( something1 )
- something1
something1 - something2
something1 + something2
something1 | | something2
something1 & & something2 - - e . g . 42 + ( 128 - 64 )
Various algebraic operations : brackets ( order of operations ) , negation , subtraction , addition , logical OR , logical AND ; respectively .
Item ( field1 = something1 , field2 = something2 , .. . ) - e . g . item = Item ( title = item . title , filename = ` / dev / null ` )
Constructor for a new item . Each function parameter defines a new field and it ' s value .
~ ` string_format ` something - - e . g . ~ ` { filename } ` item
2022-03-01 01:25:29 +00:00
Format a value into a string . This behaves differently depending on the value ' s type : When the value is an Item , the item ' s corresponding field will replace all ` { field } ` instances in the format string . When the value is a primitive type ( String , Int , Bool , etc . ) , the value ' s text equivalent will replace all ` { } ` instances in the format string . When the value is an iterable operation ( Op ) , the operation ' s script equivalent will replace all ` { } ` instances in the format string .
file ( filepath ) - - e . g . file ( ` ~ / Music / Romantic Traffic . flac ` )
2022-07-02 21:09:58 +01:00
Load an item from file , populating the item with the song ' s tags . " ;
2022-07-09 02:24:46 +01:00
pub const REPL_COMMANDS : & str =
" COMMANDS (?commands)
REPL - specific operations to help with writing Muss scripts : ? command
help
filters
functions
procedures
sorters
Show various help strings for the Muss language and syntax .
list
List remaining items to be played instead of playing them . If no items are about to be played , list all items in the next statement . In playlist mode , only the latter functionality applies .
skip
Skip remaining items to be played . If no items are about to be played , skip all items in the next statement . This is a no - output version of ? list .
normal
Cancel any active ? skip or ? list operation .
verbose
Toggle verbose messages , like extra information on items in ? list and other goodies . " ;