{ "cells": [ { "cell_type": "markdown", "id": "baad2eb5-4025-4807-a012-a0b40b287e21", "metadata": { "tags": [] }, "source": [ "# Configuration \n", "\n", "* [The Active config](#The-Active-Config)\n", "* [Creating a new Config](#Creating-a-new-Config)\n", "* [Validation](#Validation)\n", "* [Making customizations persistent across sessions](#Making-customizations-persistent-across-sessions)\n", "* [The active Workspace](#The-active-Workspace)\n", "* [Ad-hoc config](#Ad-hoc-config)\n", "\n", "\n", "---------------\n", "\n", "## The Active Config\n", "\n", "Within *maelzel.core* **there is, at any moment, an active config object** (an instance of `CoreConfig`). This config encompasses settings related to notation, playback, quantization and many other aspects of *maelzel.core*. It is a subclass of *dict* with a fixed set of possible keys" ] }, { "cell_type": "code", "execution_count": 1, "id": "d4d15777-c462-4ae7-b8a6-08037b5c85e7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "

CoreConfig: maelzel:core


KeyValueTypeDescr
A4442between 10 - 10000Freq. of the Kammerton A4. Normal values are 440, 442, 443 or 432 for old tuning, but any 'fantasy' value can be used
splitAcceptableDeviation4type: intWhen splitting notes between staves, notes within this range of the split point will be grouped together if they all fit
chordAdjustGainTruetype: boolAdjust the gain of a chord according to the number of notes, to prevent clipping
reprShowFreqFalsetype: boolShow frequency when printing a Note in the console
semitoneDivisions4{1, 2, 4}The number of divisions per semitone (2=quarter-tones, 4=eighth-tones)
musescorepathtype: strThe command to use when calling MuseScore. For macOS users: it must be an absolute path pointing to the actual binary inside the .app bundle
reprShowFractionsAsFloatTruetype: boolAll time offsets and durations are kept as rational numbers to avoid rounding errors. If this option is True, these fractions are printed as floats in order to make them more readable.
jupyterHtmlReprTruetype: boolIf True, output html inside jupyter as part of the _repr_html_ hook. Under certain circumstances (for example, when generating documentation from a notebook) this html might result in style conflict. Setting in False will just output plain text
fixStringNotenamesFalsetype: boolIf True, pitches given as string notenames are fixed at the spelling given at creation. Otherwise pitches might be respelled to match their context for better readability. Pitches given as midi notes or frequencies are always respelled
openImagesInExternalAppFalsetype: boolForce opening images with an external tool, even when inside a Jupyter notebook
enharmonic.horizontalWeight1type: intThe weight of the horizontal dimension (note sequences) when evaluating an enharmonic variant
enharmonic.verticalWeight0.01type: floatThe weight of the vertical dimension (chords within a voice) when evaluating an enharmonic variant
enharmonic.debugFalsetype: boolIf True, print debug information while calculating automatic enharmonic spelling
enharmonic.threeQuarterMicrotonePenalty20type: intNone
show.arpeggiateChordauto{auto, False, True}Arpeggiate notes of a chord when showing. In auto mode, only arpeggiate when needed
show.lastBreakpointDur0.125between 0.015625 - 1Dur of a note representing the end of a line/gliss, which has no totalDuration per se
show.centsDeviationAsTextAnnotationTruetype: boolshow cents deviation as text when rendering notation
show.centsAnnotationFontSize8type: intFont size used for cents annotations
show.centSep,type: strSeparator used when displaying multiple cents deviation (in a chord)
show.scaleFactor1.0type: floatAffects the size of the generated image when using png format
show.staffSize12.0type: floatThe size of a staff, in points
show.backendlilypond{lilypond, music21}method/backend used when rendering notation
show.formatpng{pdf, png, repr}Used when no explicit format is passed to .show
show.cacheImagesTruetype: boolIf True, cache rendered images. Set it to False for debugging. call `resetImageCache()` to reset manually
show.arpeggioDuration0.5type: floatDuration used for individual notes when rendering a chord as arpeggio
show.labelFontSize10.0type: floatFont size to use for labels
show.pageOrientationportrait{landscape, portrait}Page orientation when rendering to pdf
show.pageSizea4{a2, a3, a4}The page size when rendering to pdf
show.pageMarginMillimeters4between 0 - 1000The page margin in mm
show.glissEndStemlessFalsetype: boolWhen the end pitch of a gliss. is shown as gracenote, make this stemless
show.glissHideTiedNotesTruetype: boolHide tied notes which are part of a glissando
show.glissLineThickness2{1, 2, 3, 4}Line thikness when rendering glissandi. The value is abstract and it isup to the renderer to interpret it
show.lilypondPngStaffsizeScale1.5type: floatA factor applied to the staffsize when rendering to png via lilypond. Useful if rendered images appear too small in a jupyter notebook
show.lilypondGlissandoMinimumLength5type: intThe minimum length of a glissando in points. Increase this value if glissando linesare not shown or are too short (this might be the case within the context of dottednotes or accidentals)
show.pngResolution200{100, 200, 300, 600, 1200}DPI used when rendering to png
show.measureAnnotationStylebox=square; fontsize=12type: strNone
show.respellPitchesTruetype: boolIf True, try to find a suitable enharmonic representation of pitches whichhave not been fixed already by the user. Otherwise the canonical form of eachpitch is used, independent of the context
show.horizontalSpacingmedium{default, large, medium, small, xlarge}Hint for the renderer to adjust horizontal spacing. The actual result depends on the backend and the format used.
show.fillDynamicFromAmplitudeFalsetype: boolIf True, when rendering notation, if an object has an amplitude and does not have an explicit dynamic, add a dynamic according to the amplitude
show.jupyterMaxImageWidth1000type: intA max. width in pixels for images displayed in a jupyter notebook
show.hideRedundantDynamicsTruetype: boolHide redundant dynamics within a voice
show.asoluteOffsetForDetachedObjectsFalsetype: boolWhen showing an object which has a parent but is shown detached from it, shouldthe absolute offset be used?
show.voiceMaxStaves1between 1 - 4The maximum number of staves per voice when showing a Voice as notation. A voiceis a sequence of non-simultaneous events (notes, chords, etc.) but these canbe exploded over multiple staves (for example, a chord might expand across awide range and would need multiple extra lines in any clef
show.clipNoteheadShapesquare{, cluster, cross, diamond, harmonic, normal, rectangle, rhombus, slash, square, triangle, xcircle}Notehead shape to use for clips
play.gain1.0between 0 - 1Default gain used when playing/recording
play.engineNamemaelzel.coretype: strName of the play engine used
play.instrpianotype: str | default: sinDefault instrument used for playback. A list of available instruments can be queried via `availableInstrs`. New instrument presets can be defined via `defPreset`
play.fade0.02type: floatdefault fade time
play.fadeShapecos{cos, linear, scurve}Curve-shape used for fading in/out
play.pitchInterpolationlinear{cos, linear}Curve shape for interpolating between pitches
play.numChannels2between 1 - 128Default number of channels (channels can be set explicitely when calling startPlayEngine
play.unschedFadeout0.05type: floatfade out when stopping a note
play.backenddefault{alsa, auhal, default, jack, pa_cb, portaudio, pulse}backend used for playback
play.defaultAmplitude1.0between 0 - 1The amplitude of a Note/Chord when an amplitude is needed and the object has an undefined amplitude. This is only used if play.useDynamics if False
play.defaultDynamicf{f, ff, fff, ffff, mf, mp, p, pp, ppp, pppp}THe dynamic of a Note/Chord when a dynamic is needed. This is only used if play.useDynamics is True. Any event with an amplitude will use that amplitude instead
play.generalMidiSoundfonttype: strPath to a soundfont (sf2 file) with a general midi mapping
play.soundfontAmpDiv16384type: intA divisor used to scale the amplitude of soundfonts to a range 0-1
play.soundfontInterpolationlinear{cubic, linear}Interpolation used when reading sample data from a soundfont.
play.schedLatency0.05type: floatAdded latency when scheduling events to ensure time precission
play.verboseFalsetype: boolIf True, outputs extra debugging information regarding playback
play.useDynamicsTruetype: boolIf True, any note/chord with a set dynamic will use that to modify its playback amplitude if no explicit amplitude is set
play.waitAfterStart0.5type: floatHow much to wait for the sound engine to be operational after starting it
play.gracenoteDuration1/14type: (int, float, str)Duration assigned to a gracenote for playback (in quarternotes)
rec.blockingTruetype: boolShould recording be blocking or should be done async?
rec.sr44100{44100, 48000, 88200, 96000, 144000, 176400, 192000, 352800, 384000}Sample rate used when rendering offline
rec.ksmps64{1, 16, 32, 64, 128, 256}Samples per cycle when rendering offline (passed as ksmps to csound)
rec.numChannels2between 1 - 128The default number of channels when rendering to disk
rec.pathtype: strpath used to save output files when rendering offline. If not given the default can be queried via `recordPath`
rec.quietTruetype: boolSupress debug output when calling csound as a subprocess
rec.compressionBitrate224type: intdefault bitrate to use when encoding to ogg or mp3
htmlThemelight{dark, light}Theme used when displaying html inside jupyter
quant.minBeatFractionAcrossBeats0.5type: floatwhen merging durations across beats, a merged totalDuration cannot be smaller than this totalDuration. This is to prevent joining durations across beats which might result in high rhythmic complexity
quant.nestedTupletsNone{False, None, True}Are nested tuples allowed when quantizing? Not all display backends support nested tuples (musescore, used to render musicxml has no support for nested tuples). If None, this flag is determined based on the complexity preset (quant.complexity)
quant.breakSyncopationsLevelweak{all, none, strong, weak}Level at which to break syncopations, one of \"all\" (break all syncopations), \"weak (break only syncopations over secondary beats)\", \"strong\" (break syncopations at strong beats) or \"none\" (do not break any syncopations)
quant.complexityhigh{high, highest, low, lowest, medium}Controls the allowed complexity in the notation. The higher the complexity, the more accurate the quantization, at the cost of a more complex notation.
quant.divisionErrorWeightNonetype: NoneTypeA weight (between 0 and 1) applied to the penalty of complex quantization of the beat. The higher this value is, the simpler the subdivision chosen. If set to None, this value is derived from the complexity preset (quant.complexity)
quant.gridErrorWeightNonetype: NoneTypeA weight (between 0 and 1) applied to the deviation of a quantization to the actual attack times and durations during quantization. The higher this value, the more accurate the quantization (possibly resulting in more complex subdivisions of the beat). If None, the value is derived from the complexity preset (quant.complexity)
quant.rhythmComplexityWeightNonetype: NoneTypeA weight (between 0 and 1) applied to the penalty calculated from the complexity of the rhythm during quantization. A higher value results in more complex rhythms being considered for quantization. If None, the value is derived from the complexity (quant.complexity)
quant.gridErrorExpNonetype: NoneTypeAn exponent applied to the grid error. The grid error is a value between 0-1 which indicates how accurate the grid representation is for a given quantization (a value of 0 indicates perfect timing). An exponent betwenn 0 < exp <= 1 will make grid errors weight more dramatically as they diverge from the most accurate solution. If None, the value is derived from the complexity setting (quant.complexity)
quant.debugFalsetype: boolTurns on debugging for the quantization process. This will show how different divisions of the beat are being evaluated by the quantizer in terms of what is contributing more to the ranking. With this information it is possible to adjust the weights (quant.rhythmCompleityWeight, quant.divisionErrorWeight, etc)
quant.debugShowNumRows50type: intWhen quantization debugging is turned on this setting limits the number of different quantization possibilities shown
dynamicCurveShapeexpon(0.3)type: strThe shape used to create the default dynamics curve. The most convenient shape is some variation of an exponential, given as expon(exp), where exp is the exponential used. exp < 1 will result in more resolution for soft dynamics
dynamicCurveMindb-60between -160 - 0The amplitude (in dB) corresponding to the softest dynamic
dynamicCurveMaxdb0between -160 - 0The amplitude (in dB) corresponding to the loudest dynamic
dynamicCurveDynamicsppp pp p mp mf f ff ffftype: strPossible dynamic steps. A string with all dynamic steps, sorted from softest to loudest
" ], "text/plain": [ "Config: maelzel:core\n", "--------------------------------------- ------------------- ----------------------------------\n", "A4 442 between 10 - 10000\n", " Freq. of the Kammerton A4. Normal\n", " values are 440, 442, 443 or 432\n", " for old tuning, but any 'fantasy'\n", " value can be used\n", "chordAdjustGain True type: bool\n", " Adjust the gain of a chord\n", " according to the number of notes,\n", " to prevent clipping\n", "dynamicCurveDynamics ppp pp p mp mf f ff type: str\n", " fff\n", " Possible dynamic steps. A string\n", " with all dynamic steps, sorted\n", " from softest to loudest\n", "dynamicCurveMaxdb 0 between -160 - 0\n", " The amplitude (in dB)\n", " corresponding to the loudest\n", " dynamic\n", "dynamicCurveMindb -60 between -160 - 0\n", " The amplitude (in dB)\n", " corresponding to the softest\n", " dynamic\n", "dynamicCurveShape expon(0.3) type: str\n", " The shape used to create the\n", " default dynamics curve. The most\n", " convenient shape is some variation\n", " of an exponential, given as\n", " expon(exp), where exp is the\n", " exponential used. exp < 1 will\n", " result in more resolution for soft\n", " dynamics\n", "enharmonic.debug False type: bool\n", " If True, print debug information\n", " while calculating automatic\n", " enharmonic spelling\n", "enharmonic.horizontalWeight 1 type: int\n", " The weight of the horizontal\n", " dimension (note sequences) when\n", " evaluating an enharmonic variant\n", "enharmonic.threeQuarterMicrotonePenalty 20 type: int\n", "enharmonic.verticalWeight 0.01 type: float\n", " The weight of the vertical\n", " dimension (chords within a voice)\n", " when evaluating an enharmonic\n", " variant\n", "fixStringNotenames False type: bool\n", " If True, pitches given as string\n", " notenames are fixed at the\n", " spelling given at creation.\n", " Otherwise pitches might be\n", " respelled to match their context\n", " for better readability. Pitches\n", " given as midi notes or frequencies\n", " are always respelled\n", "htmlTheme light {dark, light}\n", " Theme used when displaying html\n", " inside jupyter\n", "jupyterHtmlRepr True type: bool\n", " If True, output html inside\n", " jupyter as part of the _repr_html_\n", " hook. Under certain circumstances\n", " (for example, when generating\n", " documentation from a notebook)\n", " this html might result in style\n", " conflict. Setting in False will\n", " just output plain text\n", "musescorepath type: str\n", " The command to use when calling\n", " MuseScore. For macOS users: it\n", " must be an absolute path pointing\n", " to the actual binary inside the\n", " .app bundle\n", "openImagesInExternalApp False type: bool\n", " Force opening images with an\n", " external tool, even when inside a\n", " Jupyter notebook\n", "play.backend default {alsa, auhal, default, jack,\n", " pa_cb, portaudio, pulse}\n", " backend used for playback\n", "play.defaultAmplitude 1.0 between 0 - 1\n", " The amplitude of a Note/Chord when\n", " an amplitude is needed and the\n", " object has an undefined amplitude.\n", " This is only used if\n", " play.useDynamics if False\n", "play.defaultDynamic f {f, ff, fff, ffff, mf, mp, p, pp,\n", " ppp, pppp}\n", " THe dynamic of a Note/Chord when a\n", " dynamic is needed. This is only\n", " used if play.useDynamics is True.\n", " Any event with an amplitude will\n", " use that amplitude instead\n", "play.engineName maelzel.core type: str\n", " Name of the play engine used\n", "play.fade 0.02 type: float\n", " default fade time\n", "play.fadeShape cos {cos, linear, scurve}\n", " Curve-shape used for fading in/out\n", "play.gain 1.0 between 0 - 1\n", " Default gain used when\n", " playing/recording\n", "play.generalMidiSoundfont type: str\n", " Path to a soundfont (sf2 file)\n", " with a general midi mapping\n", "play.gracenoteDuration 1/14 type: (int, float, str)\n", " Duration assigned to a gracenote\n", " for playback (in quarternotes)\n", "play.instr piano type: str | default: sin\n", " Default instrument used for\n", " playback. A list of available\n", " instruments can be queried via\n", " `availableInstrs`. New instrument\n", " presets can be defined via\n", " `defPreset`\n", "play.numChannels 2 between 1 - 128\n", " Default number of channels\n", " (channels can be set explicitely\n", " when calling startPlayEngine\n", "play.pitchInterpolation linear {cos, linear}\n", " Curve shape for interpolating\n", " between pitches\n", "play.schedLatency 0.05 type: float\n", " Added latency when scheduling\n", " events to ensure time precission\n", "play.soundfontAmpDiv 16384 type: int\n", " A divisor used to scale the\n", " amplitude of soundfonts to a range\n", " 0-1\n", "play.soundfontInterpolation linear {cubic, linear}\n", " Interpolation used when reading\n", " sample data from a soundfont.\n", "play.unschedFadeout 0.05 type: float\n", " fade out when stopping a note\n", "play.useDynamics True type: bool\n", " If True, any note/chord with a set\n", " dynamic will use that to modify\n", " its playback amplitude if no\n", " explicit amplitude is set\n", "play.verbose False type: bool\n", " If True, outputs extra debugging\n", " information regarding playback\n", "play.waitAfterStart 0.5 type: float\n", " How much to wait for the sound\n", " engine to be operational after\n", " starting it\n", "quant.breakSyncopationsLevel weak {all, none, strong, weak}\n", " Level at which to break\n", " syncopations, one of \"all\" (break\n", " all syncopations), \"weak (break\n", " only syncopations over secondary\n", " beats)\", \"strong\" (break\n", " syncopations at strong beats) or\n", " \"none\" (do not break any\n", " syncopations)\n", "quant.complexity high {high, highest, low, lowest,\n", " medium}\n", " Controls the allowed complexity in\n", " the notation. The higher the\n", " complexity, the more accurate the\n", " quantization, at the cost of a\n", " more complex notation.\n", "quant.debug False type: bool\n", " Turns on debugging for the\n", " quantization process. This will\n", " show how different divisions of\n", " the beat are being evaluated by\n", " the quantizer in terms of what is\n", " contributing more to the ranking.\n", " With this information it is\n", " possible to adjust the weights\n", " (quant.rhythmCompleityWeight,\n", " quant.divisionErrorWeight, etc)\n", "quant.debugShowNumRows 50 type: int\n", " When quantization debugging is\n", " turned on this setting limits the\n", " number of different quantization\n", " possibilities shown\n", "quant.divisionErrorWeight None type: NoneType\n", " A weight (between 0 and 1) applied\n", " to the penalty of complex\n", " quantization of the beat. The\n", " higher this value is, the simpler\n", " the subdivision chosen. If set to\n", " None, this value is derived from\n", " the complexity preset\n", " (quant.complexity)\n", "quant.gridErrorExp None type: NoneType\n", " An exponent applied to the grid\n", " error. The grid error is a value\n", " between 0-1 which indicates how\n", " accurate the grid representation\n", " is for a given quantization (a\n", " value of 0 indicates perfect\n", " timing). An exponent betwenn 0 <\n", " exp <= 1 will make grid errors\n", " weight more dramatically as they\n", " diverge from the most accurate\n", " solution. If None, the value is\n", " derived from the complexity\n", " setting (quant.complexity)\n", "quant.gridErrorWeight None type: NoneType\n", " A weight (between 0 and 1) applied\n", " to the deviation of a quantization\n", " to the actual attack times and\n", " durations during quantization. The\n", " higher this value, the more\n", " accurate the quantization\n", " (possibly resulting in more\n", " complex subdivisions of the beat).\n", " If None, the value is derived from\n", " the complexity preset\n", " (quant.complexity)\n", "quant.minBeatFractionAcrossBeats 0.5 type: float\n", " when merging durations across\n", " beats, a merged totalDuration\n", " cannot be smaller than this\n", " totalDuration. This is to prevent\n", " joining durations across beats\n", " which might result in high\n", " rhythmic complexity\n", "quant.nestedTuplets None {False, None, True}\n", " Are nested tuples allowed when\n", " quantizing? Not all display\n", " backends support nested tuples\n", " (musescore, used to render\n", " musicxml has no support for nested\n", " tuples). If None, this flag is\n", " determined based on the complexity\n", " preset (quant.complexity)\n", "quant.rhythmComplexityWeight None type: NoneType\n", " A weight (between 0 and 1) applied\n", " to the penalty calculated from the\n", " complexity of the rhythm during\n", " quantization. A higher value\n", " results in more complex rhythms\n", " being considered for quantization.\n", " If None, the value is derived from\n", " the complexity (quant.complexity)\n", "rec.blocking True type: bool\n", " Should recording be blocking or\n", " should be done async?\n", "rec.compressionBitrate 224 type: int\n", " default bitrate to use when\n", " encoding to ogg or mp3\n", "rec.ksmps 64 {1, 16, 32, 64, 128, 256}\n", " Samples per cycle when rendering\n", " offline (passed as ksmps to\n", " csound)\n", "rec.numChannels 2 between 1 - 128\n", " The default number of channels\n", " when rendering to disk\n", "rec.path type: str\n", " path used to save output files\n", " when rendering offline. If not\n", " given the default can be queried\n", " via `recordPath`\n", "rec.quiet True type: bool\n", " Supress debug output when calling\n", " csound as a subprocess\n", "rec.sr 44100 {44100, 48000, 88200, 96000,\n", " 144000, 176400, 192000, 352800,\n", " 384000}\n", " Sample rate used when rendering\n", " offline\n", "reprShowFractionsAsFloat True type: bool\n", " All time offsets and durations are\n", " kept as rational numbers to avoid\n", " rounding errors. If this option is\n", " True, these fractions are printed\n", " as floats in order to make them\n", " more readable.\n", "reprShowFreq False type: bool\n", " Show frequency when printing a\n", " Note in the console\n", "semitoneDivisions 4 {1, 2, 4}\n", " The number of divisions per\n", " semitone (2=quarter-tones,\n", " 4=eighth-tones)\n", "show.arpeggiateChord auto {auto, False, True}\n", " Arpeggiate notes of a chord when\n", " showing. In auto mode, only\n", " arpeggiate when needed\n", "show.arpeggioDuration 0.5 type: float\n", " Duration used for individual notes\n", " when rendering a chord as arpeggio\n", "show.asoluteOffsetForDetachedObjects False type: bool\n", " When showing an object which has a\n", " parent but is shown detached from\n", " it, shouldthe absolute offset be\n", " used?\n", "show.backend lilypond {lilypond, music21}\n", " method/backend used when rendering\n", " notation\n", "show.cacheImages True type: bool\n", " If True, cache rendered images.\n", " Set it to False for debugging.\n", " call `resetImageCache()` to reset\n", " manually\n", "show.centSep , type: str\n", " Separator used when displaying\n", " multiple cents deviation (in a\n", " chord)\n", "show.centsAnnotationFontSize 8 type: int\n", " Font size used for cents\n", " annotations\n", "show.centsDeviationAsTextAnnotation True type: bool\n", " show cents deviation as text when\n", " rendering notation\n", "show.clipNoteheadShape square {, cluster, cross, diamond,\n", " harmonic, normal, rectangle,\n", " rhombus, slash, square, triangle,\n", " xcircle}\n", " Notehead shape to use for clips\n", "show.fillDynamicFromAmplitude False type: bool\n", " If True, when rendering notation,\n", " if an object has an amplitude and\n", " does not have an explicit dynamic,\n", " add a dynamic according to the\n", " amplitude\n", "show.format png {pdf, png, repr}\n", " Used when no explicit format is\n", " passed to .show\n", "show.glissEndStemless False type: bool\n", " When the end pitch of a gliss. is\n", " shown as gracenote, make this\n", " stemless\n", "show.glissHideTiedNotes True type: bool\n", " Hide tied notes which are part of\n", " a glissando\n", "show.glissLineThickness 2 {1, 2, 3, 4}\n", " Line thikness when rendering\n", " glissandi. The value is abstract\n", " and it isup to the renderer to\n", " interpret it\n", "show.hideRedundantDynamics True type: bool\n", " Hide redundant dynamics within a\n", " voice\n", "show.horizontalSpacing medium {default, large, medium, small,\n", " xlarge}\n", " Hint for the renderer to adjust\n", " horizontal spacing. The actual\n", " result depends on the backend and\n", " the format used.\n", "show.jupyterMaxImageWidth 1000 type: int\n", " A max. width in pixels for images\n", " displayed in a jupyter notebook\n", "show.labelFontSize 10.0 type: float\n", " Font size to use for labels\n", "show.lastBreakpointDur 0.125 between 0.015625 - 1\n", " Dur of a note representing the end\n", " of a line/gliss, which has no\n", " totalDuration per se\n", "show.lilypondGlissandoMinimumLength 5 type: int\n", " The minimum length of a glissando\n", " in points. Increase this value if\n", " glissando linesare not shown or\n", " are too short (this might be the\n", " case within the context of\n", " dottednotes or accidentals)\n", "show.lilypondPngStaffsizeScale 1.5 type: float\n", " A factor applied to the staffsize\n", " when rendering to png via\n", " lilypond. Useful if rendered\n", " images appear too small in a\n", " jupyter notebook\n", "show.measureAnnotationStyle box=square; type: str\n", " fontsize=12\n", "show.pageMarginMillimeters 4 between 0 - 1000\n", " The page margin in mm\n", "show.pageOrientation portrait {landscape, portrait}\n", " Page orientation when rendering to\n", " pdf\n", "show.pageSize a4 {a2, a3, a4}\n", " The page size when rendering to\n", " pdf\n", "show.pngResolution 200 {100, 200, 300, 600, 1200}\n", " DPI used when rendering to png\n", "show.respellPitches True type: bool\n", " If True, try to find a suitable\n", " enharmonic representation of\n", " pitches whichhave not been fixed\n", " already by the user. Otherwise the\n", " canonical form of eachpitch is\n", " used, independent of the context\n", "show.scaleFactor 1.0 type: float\n", " Affects the size of the generated\n", " image when using png format\n", "show.staffSize 12.0 type: float\n", " The size of a staff, in points\n", "show.voiceMaxStaves 1 between 1 - 4\n", " The maximum number of staves per\n", " voice when showing a Voice as\n", " notation. A voiceis a sequence of\n", " non-simultaneous events (notes,\n", " chords, etc.) but these canbe\n", " exploded over multiple staves (for\n", " example, a chord might expand\n", " across awide range and would need\n", " multiple extra lines in any clef\n", "splitAcceptableDeviation 4 type: int\n", " When splitting notes between\n", " staves, notes within this range of\n", " the split point will be grouped\n", " together if they all fit\n", "--------------------------------------- ------------------- ----------------------------------\n" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from maelzel.core import *\n", "from pitchtools import *\n", "\n", "# Get the active config\n", "conf = getConfig()\n", "conf" ] }, { "cell_type": "markdown", "id": "4bd40961-2026-4491-8424-0f876b39ceef", "metadata": {}, "source": [ "**The config is a subclass of dict where only a well defined set of keys are allowed and values are validated**.\n", "\n", "All operations on a built-in dict can be performed. \n", "\n", "\n", "## Creating a new Config\n", "\n", "To create a new configuration you can simply call `CoreConfig()` to get a copy of the default config.\n", "\n", "As an example, here we **create a new config** with a custom reference frequency. This modifies the reference frequency for any operation converting frequency to midinote or note name. After evaluating the following cell one can confirm that a frequency of 442 Hz is now 12 cents lower than A4" ] }, { "cell_type": "code", "execution_count": 3, "id": "6b2b0642-530d-4dd6-aee0-bf329d280024", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'A4': 445, 'play.instr': 'piano'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "conf = CoreConfig({'A4': 445}, active=True)\n", "\n", "# Diff show the differences with the default config\n", "conf.diff()" ] }, { "cell_type": "code", "execution_count": 4, "id": "8890fb77-3b3a-4ed3-b2cb-8a4633def01a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4A-12'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2n(442)" ] }, { "cell_type": "markdown", "id": "7bf3099a-59c8-44d3-b688-517f278894aa", "metadata": {}, "source": [ "To restore the original frequency, just modify the value of the active config:" ] }, { "cell_type": "code", "execution_count": 5, "id": "9be9b547-aa8a-4d3a-98b9-b3148edf6eed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4A'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "getConfig()['A4'] = 442\n", "f2n(442)" ] }, { "cell_type": "markdown", "id": "57fe3d14-1064-4d5c-b9ce-0f50a0974671", "metadata": {}, "source": [ "Or activate the previous config" ] }, { "cell_type": "code", "execution_count": 6, "id": "e4d27711-15f6-46ec-8124-e5cb9e3125c6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4A'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "conf.activate()\n", "f2n(442)" ] }, { "cell_type": "markdown", "id": "a1919a73-f69d-431f-b0b8-6f3401cad85e", "metadata": {}, "source": [ "-----------------\n", "\n", "## Validation\n", "\n", "A `CoreConfig` is always valid (it is aware about valid values for its keys). For example, it is possible to customize the number of playback channels used by the sound engine, or the latency used for scheduling events. " ] }, { "cell_type": "code", "execution_count": 7, "id": "b30d5da7-4b38-4e57-af74-758c5962a723", "metadata": {}, "outputs": [], "source": [ "# Set the default number of channels for playback. Any playback engine created will use this setting\n", "conf['play.numChannels'] = 4\n", "conf['play.schedLatency'] = 0.1" ] }, { "cell_type": "markdown", "id": "8862c3b2-b304-4721-b53b-09227f5732e5", "metadata": {}, "source": [ "A wrong type or range will throw an error and the previous value will not be overwritten so that the configuration remains in a usable state." ] }, { "cell_type": "code", "execution_count": 8, "id": "9f7c84c2-e52b-4fe6-ad9a-019b6b8c5ada", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "Expected int for key play.numChannels, got str", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mconf\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mplay.numChannels\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfour\u001b[39m\u001b[38;5;124m'\u001b[39m\n", "File \u001b[0;32m~/.virtualenvs/em10/lib/python3.10/site-packages/configdict/configdict.py:682\u001b[0m, in \u001b[0;36mCheckedDict.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 680\u001b[0m errormsg \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcheckValue(key, value)\n\u001b[1;32m 681\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m errormsg:\n\u001b[0;32m--> 682\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(errormsg)\n\u001b[1;32m 683\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_precallback:\n\u001b[1;32m 684\u001b[0m newvalue \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_precallback(\u001b[38;5;28mself\u001b[39m, key, oldvalue, value)\n", "\u001b[0;31mValueError\u001b[0m: Expected int for key play.numChannels, got str" ] } ], "source": [ "conf['play.numChannels'] = 'four'" ] }, { "cell_type": "markdown", "id": "251a68d8-9908-4f5b-b3b3-7a29777e6e64", "metadata": {}, "source": [ "## Making customizations persistent across sessions\n", "\n", "Customizations can be made persistent by calling `save` on the dictionary (independently of it being active). After that, any config created in a future session will use this dict as its prototype" ] }, { "cell_type": "code", "execution_count": 5, "id": "3320b86f-0c1f-43e0-9919-931abd15066d", "metadata": {}, "outputs": [], "source": [ "conf.save()" ] }, { "cell_type": "markdown", "id": "7cbc8a69-8be5-400b-9703-25f2f454fcd7", "metadata": {}, "source": [ "To revert a config to its factory defaults, use `reset`. Call `save` to make the reset persistent." ] }, { "cell_type": "code", "execution_count": 8, "id": "27f372eb-3fe0-4de7-b07e-81a8a8f4dcea", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "conf.reset()\n", "conf['play.numChannels']" ] }, { "cell_type": "markdown", "id": "bbd2b7fe-611e-4469-b808-0d02ed892211", "metadata": { "tags": [] }, "source": [ "## Customizing playback / recording" ] }, { "cell_type": "markdown", "id": "a72a299d-4d2c-4f0c-951d-8f5b30c95577", "metadata": {}, "source": [ "By default any `Note`/`Chord` is played back using the default preset. It is possible to customize this default preset: " ] }, { "cell_type": "code", "execution_count": 11, "id": "d6da5a01-9d31-4c2f-8b80-710bc3833e56", "metadata": {}, "outputs": [ { "data": { "text/html": [ "Preset: accordion\n", "
\n", " (routing=True, properties={'sfpath': '/home/em/Lib/snd/sf2/Accordion.sf2'}, numouts=2, numsignals=2)\n", "\n", "init:
  iSfTable_ sfloadonce "/home/em/Lib/snd/sf2/Accordion.sf2"\n",
       "
\n", "\n", "audiogen:\n", "
  ipresetidx sfPresetIndex "/home/em/Lib/snd/sf2/Accordion.sf2", 0, 0\n",
       "  inote0_ = round(p(idataidx_ + 1))\n",
       "  ivel_ = p(idataidx_ + 2) * 127\n",
       "  aout1, aout2 sfplay ivel_, inote0_, kamp/16384, mtof:k(kpitch), ipresetidx, 1\n",
       "
\n", "
\n", "epilogue:\n", "
  turnoffWhenSilent aout1\n",
       "
\n" ], "text/plain": [ "Preset: accordion \n", " routing=True, properties={'sfpath': '/home/em/Lib/snd/sf2/Accordion.sf2'}\n", " init: iSfTable_ sfloadonce \"/home/em/Lib/snd/sf2/Accordion.sf2\"\n", "\n", " ipresetidx sfPresetIndex \"/home/em/Lib/snd/sf2/Accordion.sf2\", 0, 0\n", " inote0_ = round(p(idataidx_ + 1))\n", " ivel_ = p(idataidx_ + 2) * 127\n", " aout1, aout2 sfplay ivel_, inote0_, kamp/16384, mtof:k(kpitch), ipresetidx, 1\n", "\n", " epilogue:\n", " turnoffWhenSilent aout1" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "defPresetSoundfont(\"accordion\", \"/home/em/Lib/snd/sf2/Accordion.sf2\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "dd6a3633-856e-44d7-b2ca-1618970a698c", "metadata": {}, "outputs": [], "source": [ "conf['play.instr'] = 'accordion'" ] }, { "cell_type": "markdown", "id": "eb7ff879-2799-4b14-ade0-804cc33fde83", "metadata": {}, "source": [ "We create a simple chromatic scale to have something to play with" ] }, { "cell_type": "code", "execution_count": 13, "id": "58adf288-18f5-46eb-845b-652f2dbd64ff", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAATwAAABBCAIAAADDrI/6AAAJMmlDQ1BkZWZhdWx0X3JnYi5pY2MAA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+spypdaKGIa9vvvlmiYKKSUli/VYx5FXlxaWYNpP9DHa0rqxeT1t2VVdt12c937ZZRaw1s6pKYaWVmKYki0gbr7Q0Q9zaDlZppFaa1jar0tQUHR6TkMPOaDTaSMc3pL3/6KOPioUZkMPLGg5W1SgClbVLQVUmv0NBdgUQ4diwnoEyFQ50dzUfrD6vUQQqzU6piCiGYQKBANlkbTZbg8fGkCVcrqhdXV1nz54NhUKkljbjYFVVWhWllImIMhgMPp8vFAoFAgGz2UyuHGgk8sFqbauBNZ90wDQGVWlVlFLqo9KQ6CAUCsHSSpZlVzERriAIlJkEqqHBHw5Gz77AoPp1VOgp/yX4F4rGK62KilKorMcqKiprB1Vp/wPHcepIVWWNow6PVVSajP8BZ8EIkS99B8AAAAAASUVORK5CYII=", "text/plain": [ "" ] }, "metadata": { "image/png": { "width": 316 } }, "output_type": "display_data" }, { "data": { "text/html": [ "OfflineRenderer(outfile=\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T12:19:04.213.wav\", 2 channels, 3.10 secs, 44100 Hz)
\n", "
\n", " \n", " " ], "text/plain": [ "OfflineRenderer(sr=44100)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scale = Chain([Note(m, dur=0.25) for m in range(60, 72)])\n", "scale.show()\n", "scale.rec(extratime=0.1)" ] }, { "cell_type": "code", "execution_count": 16, "id": "b472dbf7-79d4-4028-b7a2-5ac3b1dab59d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "OfflineRenderer(outfile=\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T12:19:31.684.wav\", 1 channels, 3.02 secs, 48000 Hz)
\n", "
\n", " \n", " " ], "text/plain": [ "OfflineRenderer(sr=48000)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "conf['rec.sr'] = 48000 # set default recording samplerate\n", "scale.rec(nchnls=1)" ] }, { "cell_type": "markdown", "id": "dd7a6d0b-0020-4347-af37-fa22d31fe814", "metadata": { "tags": [] }, "source": [ "----------------\n", "\n" ] }, { "cell_type": "markdown", "id": "f564ed9a-4a57-4693-a768-6b94cb78799d", "metadata": {}, "source": [ "## The active Workspace\n", "\n", "At any moment there is one (and only one) active workspace. Whenever a config is made active, it is assigned to the active Workspace\n", "\n", "A workspace contains the following attributes:\n", "\n", "* `.config` (`CoreConfig`): a config \n", "* `.scorestruct` (`ScoreStruct`): a score structure \n", "* `.dynamicCurve`: a dynamics curve, mapping dynamics to amplitudes\n", "* internal attributes which determine the current state" ] }, { "cell_type": "code", "execution_count": 17, "id": "72499728-c5b7-4d4a-8488-678d475cde82", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Workspace(scorestruct=ScoreStruct(tempo=60, timesig=(4, 4)), config={'play.instr': 'accordion', 'play.numChannels': 4, 'play.schedLatency': 0.1, 'rec.sr': 48000, 'quant.minBeatFractionAcrossBeats': 0.3333333333333333}, dynamicCurve=DynamicCurve(shape=expon(0.3), mindb=-60.0, maxdb=0.0))" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w = getWorkspace()\n", "w" ] }, { "cell_type": "code", "execution_count": 18, "id": "f58ed051-740d-4944-b8b7-7eb70e85ad09", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is the active workspace\n", "Its config is active\n" ] } ], "source": [ "if w.isActive():\n", " print(\"This is the active workspace\")\n", "\n", "if w.config is getConfig():\n", " print(\"Its config is active\")\n", " " ] }, { "cell_type": "markdown", "id": "dfcff084-b705-459a-865a-3a713f403406", "metadata": {}, "source": [ "## Ad-hoc config\n", "\n", "It is possible to create a config to perform only one specific set of actions. This is accomplished by using a `CoreConfig` as **context manager**" ] }, { "cell_type": "code", "execution_count": 19, "id": "b1f9f8e8-4505-4e33-a158-1029b9190d2f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "OfflineRenderer(outfile=\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T12:20:04.658.wav\", 1 channels, 3.10 secs, 44100 Hz)
\n", "
\n", " \n", " " ], "text/plain": [ "OfflineRenderer(sr=44100)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "OfflineRenderer(outfile=\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T12:20:05.306.wav\", 1 channels, 3.10 secs, 48000 Hz)
\n", "
\n", " \n", " " ], "text/plain": [ "OfflineRenderer(sr=48000)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scale = Chain([Note(m, dur=0.25) for m in range(60, 72)])\n", "\n", "with CoreConfig({'play.instr': 'saw'}):\n", " scale.rec(gain=0.1, nchnls=1, extratime=0.1).show()\n", "\n", "# Outside the context the instr uses the previous default\n", "scale.rec(nchnls=1, extratime=0.1)" ] }, { "cell_type": "code", "execution_count": null, "id": "381d8611-ad5b-4179-8cc3-78e9dc89ae11", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.7" } }, "nbformat": 4, "nbformat_minor": 5 }