Skip to main content

Module environment

Module environment 

Source
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§

LocalCorpus
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
value as showFormat, writeFormat or autoDownload takes it: in lower case, and an error where it is not one music21 allows. Any other preference takes any value, and value comes back as it was given.
debug_level
The debugging level debug is set to, read as music21 reads it: true and false, a word naming a level, or a number.
default_root_temp_dir
A directory for music21’s temporary files under system_temp, as music21’s getDefaultRootTempDir picks it: music21 there, then music21-userid-<user> where a user is given, each made if missing and used only if is_safe_temp_dir; failing both, a new directory named music21- 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 user is 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 _fromSettings reads 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’s getSettingsPath finds 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.