Expand description
music21’s user environment: preferences, the settings file and
temporary files.
music21’s user environment: the preferences kept in .music21rc, where
that file lives, and where temporary files go.
music21 keeps a fixed set of preferences: where MuseScore, Lilypond and
the viewers are, which format show() and write() use, whether the
corpus may download, how much debugging to print. Each has a default
that depends on the platform; the user’s own values are read from an XML
file and written back to it in music21’s layout, so a file written here
reads in music21 and the other way round.
use music21::environment::{self, Platform};
let defaults = environment::defaults(Platform::Nix, (0, 0, 0));
let musicxml = defaults.iter().find(|(key, _)| *key == "musicxmlPath");
assert_eq!(
musicxml.map(|(_, value)| value),
Some(&environment::Value::text("/usr/bin/mscore3"))
);
assert_eq!(environment::format_to_key("png"), Some("graphicsPath"));Structs§
- Local
Corpus - A local corpus’s settings: the directories it reads, the file its
metadata is cached in, and its name, which the unnamed corpus has none
of. music21’s
LocalCorpusSettings.
Enums§
- Platform
- The three kinds of system music21 tells apart, by the names it gives
them:
'win','darwin'and'nix'. - Value
- The value of one preference.
Constants§
- PATH_
KEYS - The preferences that name a file or an application, in music21’s order.
Functions§
- accepted
valueasshowFormat,writeFormatorautoDownloadtakes it: in lower case, and an error where it is not one music21 allows. Any other preference takes any value, andvaluecomes back as it was given.- debug_
level - The debugging level
debugis set to, read as music21 reads it:trueandfalse, a word naming a level, or a number. - default_
root_ temp_ dir - A directory for music21’s temporary files under
system_temp, as music21’sgetDefaultRootTempDirpicks it:music21there, thenmusic21-userid-<user>where a user is given, each made if missing and used only ifis_safe_temp_dir; failing both, a new directory namedmusic21-and something random. - defaults
- Every preference with its default on
platform, in music21’s order. - format_
to_ key - The preference naming the application that opens a format, if any.
- is_
accessible - Whether a path exists and can be read and written, roughly: it is there
and not marked read-only. Callers that can ask the system properly
(Python’s
os.access) pass their own answer to the functions here. - is_
path_ key - Whether a preference names a file or an application.
- is_
safe_ temp_ dir - Whether a directory is safe to keep temporary files in: accessible and,
where
useris given, a real directory (not a link) that user owns and no one else can write to. music21’s_isSafeTempDir. - read_
settings - The settings a settings file holds, in the order it holds them, as
music21’s
_fromSettingsreads them: each<preference>by its name, with its value or none, and the local corpora. - settings_
path - Where the settings file is on
platform, as music21’sgetSettingsPathfinds it. - settings_
xml - The settings as music21 writes them out, sorted by name: a
<settings>element holding a<preference>for each value and an element apiece for the local corpora. - xml_
reader_ type - Which MusicXML reader a path names: music21’s
xmlReaderType.