### Start Audio Recording - Python Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusMidiFluidsynth.rst Starts a new wave file for recording audio. This method is used to prepare the system for capturing sound to a specified file. ```python def start_recording(self, file=mingus_dump.wav) Initialize a new wave file for recording. ``` -------------------------------- ### Initialize StringTuning Instance Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraStringtuning.rst Creates a new StringTuning instance. The 'instrument' and 'description' should be strings, while 'tuning' can be a list of strings or a list of lists representing courses. See tunings.add_tuning for usage examples. ```python t = tunings.StringTuning('guitar', 'standard', ['E-2', 'A-2', 'D-3', 'G-3', 'B-3', 'E-4']) ``` -------------------------------- ### Using NoteContainers as Lists (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteContainerModule.rst Demonstrates how NoteContainer objects can be treated like Python lists, supporting indexing, slicing, and item assignment. It also shows how to get the length of the container. ```python from mingus.containers import NoteContainer n = NoteContainer(["C", "E", "G"]) print(n[0]) print(n[:-1]) n[0] = "D" print(n) print(len(n)) ``` -------------------------------- ### NoteContainer Interval Shorthand Initialization Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNote_container.rst Initializes a NoteContainer by parsing interval shorthand notation from a starting note. The container is emptied before adding the notes. Dependencies: mingus.containers.note_container.NoteContainer, mingus.core.intervals Input: A starting note string, an interval shorthand string, and a boolean indicating direction (upwards by default). Output: A NoteContainer populated with the notes based on the interval shorthand. ```python from mingus.containers import NoteContainer nc = NoteContainer() nc.from_interval_shorthand('C', '5') print(nc) # Expected output: ['C-4', 'G-4'] nc.from_interval_shorthand('C', '5', False) print(nc) # Expected output: ['F-3', 'C-4'] ``` -------------------------------- ### FluidSynth Initialization and Usage Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusMidiFluidsynth.rst This section details how to initialize FluidSynth with a sound font and start playing musical elements using the FluidSynthSequencer. ```APIDOC ## FluidSynth Module Overview ### Description Provides support for FluidSynth, a software MIDI synthesizer, allowing real-time playback of mingus containers. Requires FluidSynth and a sound font file (.sf2). ### Initialization To start using FluidSynth with mingus: ```python from mingus.midi import fluidsynth fluidsynth.init('soundfontlocation.sf2') ``` This prepares FluidSynth for playing notes and other musical structures. ## FluidSynthSequencer Class ### Description Manages the playback of musical elements through FluidSynth. ### Methods #### `__init__(self)` Initializes the FluidSynthSequencer. #### `init(self)` Initializes the internal FluidSynth instance. #### `load_sound_font(self, sf2)` Loads a sound font file. **Parameters:** - **sf2** (str) - The path to the sound font file (.sf2). **Returns:** - bool - True on success, False on failure. **Description:** This must be called before audio can be played, as instruments are stored in the sound font. #### `start_audio_output(self, driver=None)` Starts the audio output stream. **Parameters:** - **driver** (str, optional) - The audio driver to use (e.g., 'alsa', 'portaudio', 'coreaudio'). Defaults to None, letting FluidSynth choose. **Description:** Available drivers vary by platform. #### `play_Note(self, note, channel=1, velocity=100)` Plays a single Note object. **Parameters:** - **note** (Note) - The Note object to play. - **channel** (int, optional) - The MIDI channel (1-16). Defaults to 1. - **velocity** (int, optional) - The note velocity (0-127). Defaults to 100. **Description:** If `note.velocity` or `note.channel` attributes are set, they will take precedence over the function arguments. #### `play_NoteContainer(self, nc, channel=1, velocity=100)` Plays all Notes within a NoteContainer. **Parameters:** - **nc** (NoteContainer) - The NoteContainer object. - **channel** (int, optional) - The MIDI channel (1-16). Defaults to 1. - **velocity** (int, optional) - The note velocity (0-127). Defaults to 100. #### `play_Bar(self, bar, channel=1, bpm=120)` Plays a Bar object. **Parameters:** - **bar** (Bar) - The Bar object to play. - **channel** (int, optional) - The MIDI channel (1-16). Defaults to 1. - **bpm** (int, optional) - The beats per minute. Defaults to 120. **Returns:** - dict - A dictionary with the bpm lemma on success, or an empty dictionary on failure. **Description:** The tempo can be changed by setting the `bpm` attribute on a NoteContainer within the Bar. #### `play_Bars(self, bars, channels, bpm=120)` Plays multiple Bar objects simultaneously. **Parameters:** - **bars** (list[Bar]) - A list of Bar objects. - **channels** (list[int]) - A list of MIDI channels corresponding to each bar. - **bpm** (int, optional) - The beats per minute. Defaults to 120. **Description:** The tempo can be changed by providing `bpm` arguments in the NoteContainers. #### `play_Track(self, track, channel=1, bpm=120)` Plays a Track object. **Parameters:** - **track** (Track) - The Track object to play. - **channel** (int, optional) - The MIDI channel (1-16). Defaults to 1. - **bpm** (int, optional) - The beats per minute. Defaults to 120. #### `play_Tracks(self, tracks, channels, bpm=120)` Plays a list of Track objects. **Parameters:** - **tracks** (list[Track]) - A list of Track objects. - **channels** (list[int]) - A list of MIDI channels corresponding to each track. - **bpm** (int, optional) - The beats per minute. Defaults to 120. **Description:** If `MidiInstrument` objects are used, instruments will be set automatically. #### `play_Composition(self, composition, channels=None, bpm=120)` Plays a Composition object. **Parameters:** - **composition** (Composition) - The Composition object to play. - **channels** (list[int], optional) - A list of MIDI channels to use for playback. Defaults to None. - **bpm** (int, optional) - The beats per minute. Defaults to 120. ### Control Methods #### `set_instrument(self, channel, instr, bank=0)` Sets the instrument for a given MIDI channel. **Parameters:** - **channel** (int) - The MIDI channel (1-16). - **instr** (int) - The instrument program number. - **bank** (int, optional) - The instrument bank number. Defaults to 0. #### `control_change(self, channel, control, value)` Sends a MIDI control change message. **Parameters:** - **channel** (int) - The MIDI channel (1-16). - **control** (int) - The control number. - **value** (int) - The control value. **Description:** Refer to the MIDI specification for control numbers. #### `main_volume(self, channel, value)` Sets the main volume for a channel. **Parameters:** - **channel** (int) - The MIDI channel (1-16). - **value** (int) - The volume value (typically 0-127). #### `modulation(self, channel, value)` Sets the modulation wheel value for a channel. **Parameters:** - **channel** (int) - The MIDI channel (1-16). - **value** (int) - The modulation value (typically 0-127). #### `pan(self, channel, value)` Sets the panning for a channel. **Parameters:** - **channel** (int) - The MIDI channel (1-16). - **value** (int) - The panning value (typically 0-127, where 64 is center). ### Listener Management #### `attach(self, listener)` Attaches an object to receive notifications. **Parameters:** - **listener** (object) - An object with a `notify(msg_type, param_dict)` method. #### `detach(self, listener)` Detaches a previously attached listener. **Parameters:** - **listener** (object) - The listener object to detach. #### `notify_listeners(self, msg_type, params)` Sends a notification to all attached listeners. **Parameters:** - **msg_type** (int) - The type of message. - **params** (dict) - A dictionary of parameters for the notification. ### Constants - **MSG_CC**: `2` (MIDI Control Change message type) - **MSG_INSTR**: `3` (MIDI Instrument Change message type) - **MSG_PLAY_BAR**: `9` (Play Bar message type) - **MSG_PLAY_BARS**: `10` (Play Bars message type) - **MSG_PLAY_COMPOSITION**: `13` (Play Composition message type) - **MSG_PLAY_INT**: `0` (Play arbitrary MIDI message type) - **MSG_PLAY_NC**: `7` (Play NoteContainer message type) - **MSG_PLAY_NOTE**: `5` (Play Note message type) - **MSG_PLAY_TRACK**: `11` (Play Track message type) - **MSG_PLAY_TRACKS**: `12` (Play Tracks message type) - **MSG_SLEEP**: `4` (Sleep/Delay message type) - **MSG_STOP_INT**: `1` (Stop arbitrary MIDI message type) - **MSG_STOP_NC**: `8` (Stop NoteContainer message type) - **MSG_STOP_NOTE**: `6` (Stop Note message type) ``` -------------------------------- ### Getting Notes in a Key Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialDiatonic.rst Retrieves all the notes belonging to a specific key. The function returns a list of notes, starting with the tonic. It accepts various key syntaxes. ```python diatonic.get_notes("C") # Output: ["C", "D", "E", "F", "G", "A", "B"] ``` ```python diatonic.get_notes("E") # Output: ["E", "F#", "G#", "A", "B", "C#", "D#"] ``` ```python diatonic.get_notes("Bb") # Output: ["Bb", "C", "D", "Eb", "F", "G", "A"] ``` -------------------------------- ### Get Notes in a Key Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialIntervals.rst Retrieves all natural notes within a specified key. This is useful for understanding the context of diatonic intervals. ```python >>> diatonic.get_notes("C") ['C', 'D', 'E', 'F', 'G', 'A', 'B'] ``` -------------------------------- ### FluidSynth Sequencer Initialization and Audio Output Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusMidiFluidsynth.rst This code shows how to initialize the FluidSynthSequencer and start its audio output. The `start_audio_output` method can optionally take a driver name for specific audio backends. Initialization and loading soundfonts should precede audio playback. ```python from mingus.midi.fluidsynth import FluidSynthSequencer sequencer = FluidSynthSequencer() sequencer.load_sound_font('path/to/your/soundfont.sf2') sequencer.start_audio_output() ``` -------------------------------- ### Scale Creation Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreScales.rst This section details how to create various types of scales provided by the mingus.core.scales module. Each scale can be initialized with a starting note and optionally the number of octaves. ```APIDOC ## Scale Creation This section details how to create various types of scales provided by the mingus.core.scales module. Each scale can be initialized with a starting note and optionally the number of octaves. ### Scale Types **Diatonic Scale** ```python from mingus.core.scales import Diatonic diatonic_scale = Diatonic('C', semitones=(2, 2, 1, 2, 2, 2, 1)) ``` **Ancient Scales (Modes)** - Ionian - Dorian - Phrygian - Lydian - Mixolydian - Aeolian - Locrian ```python from mingus.core.scales import Dorian dorian_scale = Dorian('D') ``` **Major Scales** - Major - HarmonicMajor ```python from mingus.core.scales import Major major_scale = Major('G') ``` **Minor Scales** - NaturalMinor - HarmonicMinor - MelodicMinor - Bachian - MinorNeapolitan ```python from mingus.core.scales import HarmonicMinor harmonic_minor_scale = HarmonicMinor('E') ``` **Other Scales** - Chromatic - WholeTone - Octatonic ```python from mingus.core.scales import Chromatic chromatic_scale = Chromatic('A') ``` ### Class: [ScaleName] #### Method: __init__(self, note, octaves=1) **Description**: Create the [ScaleName] scale starting on the chosen note. **Parameters**: - **note** (str) - The starting note of the scale (e.g., 'C', 'G#'). - **octaves** (int, optional) - The number of octaves the scale should span. Defaults to 1. #### Method: degree(self, degree_number, direction='a') **Description**: Return the asked scale degree. **Parameters**: - **degree_number** (int) - The number of the degree to retrieve (e.g., 1 for the root, 7 for the leading tone). - **direction** (str, optional) - The direction of the scale traversal. 'a' for ascending (default) and 'd' for descending. #### Method: ascending(self) **Description**: Return the list of notes in the scale in ascending order. #### Method: descending(self) **Description**: Return the list of notes in the scale in descending order. #### Attribute: type **Description**: The type of the scale (e.g., 'diatonic', 'ancient', 'major', 'minor', 'other'). **Type**: str ### Example Usage (Aeolian Scale) ```python from mingus.core.scales import Aeolian # Create an A Aeolian scale aeolian_scale = Aeolian('A') # Get the ascending notes print(aeolian_scale.ascending()) # Get the 3rd degree ascending print(aeolian_scale.degree(3, 'a')) # Get the descending notes print(aeolian_scale.descending()) # Get the scale type print(aeolian_scale.type) ``` ### Example Usage (Diatonic Scale) ```python from mingus.core.scales import Diatonic # Create a C major scale (Diatonic with standard major intervals) diatonic_c_major = Diatonic('C', semitones=(2, 2, 1, 2, 2, 2, 1)) print(diatonic_c_major.ascending()) # Create a custom diatonic scale (e.g., a mode) custom_diatonic = Diatonic('D', semitones=(2, 1, 2, 2, 2, 1, 2)) # Dorian intervals print(custom_diatonic.ascending()) ``` ``` -------------------------------- ### Calculate Absolute Intervals Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialIntervals.rst Calculates specific major, minor, or perfect intervals starting from a given note. Functions like `minor_second` or `major_sixth` are used. ```python >>> intervals.minor_second("C") "Db" >>> intervals.major_sixth("C") "A" >>> intervals.minor_third("Cb") "Ebb" >>> intervals.perfect_fifth("C") "G" >>> intervals.perfect_fourth("C") "F" ``` -------------------------------- ### Creating Track Instances Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialTrackModule.rst Shows how to create a new Track instance. Optionally, an Instrument can be provided for range checking and other features. ```python t = Track() t = Track(Instrument()) ``` -------------------------------- ### Get Note from String and Fret with StringTuning Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraTunings.rst Retrieves the Note object corresponding to a specific string and fret on a StringTuning. It will raise a RangeError if the fret or string is unplayable. Examples demonstrate retrieving notes like 'A-3' or 'A#-3'. ```python def get_Note(self, string=0, fret=0, maxfret=24): # Return the Note on 'string', 'fret'. # Throw a RangeError if either the fret or string is unplayable. # Examples: # >>> t = tunings.StringTuning('test', 'test', ['A-3', 'A-4']) # >>> t,get_Note(0, 0) # 'A-3' # >>> t.get_Note(0, 1) # 'A#-3' # >>> t.get_Note(1, 0) # 'A-4' pass ``` -------------------------------- ### Creating a New NoteContainer Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteContainerModule.rst Demonstrates the creation of NoteContainer objects, both empty and pre-filled with notes specified as strings or Note objects. It shows the initial state and representation of the container. ```python from mingus.containers import NoteContainer from mingus.core import notes n = NoteContainer() print(n) n = NoteContainer(notes.Note("A", 4)) print(n) n = NoteContainer("A") print(n) n = NoteContainer(["A-3", "C-5", "E-5"]) print(n) ``` -------------------------------- ### Get Chords by Function and Aliases with mingus.core.chords Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst This example shows how to retrieve chords based on their musical function (tonic, dominant, etc.) and Roman numeral aliases using the mingus.core.chords module. It utilizes functions that map these concepts to specific chord structures. ```python from mingus.core import chords # Get the tonic and tonic7 chords for C major tonic_chords = chords.tonic("C", "major") tonic7_chords = chords.tonic7("C", "major") print(f"Tonic chord in C major: {tonic_chords}") print(f"Tonic7 chord in C major: {tonic7_chords}") # Get the dominant and dominant7 chords for C major dominant_chords = chords.dominant("C", "major") dominant7_chords = chords.dominant7("C", "major") print(f"Dominant chord in C major: {dominant_chords}") print(f"Dominant7 chord in C major: {dominant7_chords}") # Get the V chord (dominant) in C major using Roman numeral alias v_chord = chords.from_roman("V", "C", "major") print(f"V chord in C major: {v_chord}") # Get the ii7 chord in C major using Roman numeral alias ii7_chord = chords.from_roman("ii7", "C", "major") print(f"ii7 chord in C major: {ii7_chord}") ``` -------------------------------- ### Python: Generate and Recognize Chords with mingus.core.chords Source: https://context7.com/bspaans/python-mingus/llms.txt This example showcases the `mingus.core.chords` module for creating various types of chords, including triads, seventh chords, and extended chords. It demonstrates how to build chords from a root note and highlights the library's capability to represent complex harmonic structures programmatically. ```python from mingus.core import chords # Build basic triads major = chords.major_triad('C') # Returns: ['C', 'E', 'G'] minor = chords.minor_triad('C') # Returns: ['C', 'Eb', 'G'] dim = chords.diminished_triad('C') # Returns: ['C', 'Eb', 'Gb'] augmented = chords.augmented_triad('C') # Returns: ['C', 'E', 'G#'] # Build seventh chords maj7 = chords.major_seventh('C') # Returns: ['C', 'E', 'G', 'B'] min7 = chords.minor_seventh('C') # Returns: ['C', 'Eb', 'G', 'Bb'] dom7 = chords.dominant_seventh('C') # Returns: ['C', 'E', 'G', 'Bb'] dim7 = chords.diminished_seventh('C') # Returns: ['C', 'Eb', 'Gb', 'Bbb'] half_dim7 = chords.half_diminished_seventh('C') # Returns: ['C', 'Eb', 'Gb', 'Bb'] # Build extended chords min9 = chords.minor_ninth('C') # Returns: ['C', 'Eb', 'G', 'Bb', 'D'] maj9 = chords.major_ninth('C') # Returns: ['C', 'E', 'G', 'B', 'D'] min11 = chords.minor_eleventh('C') # Returns: ['C', 'Eb', 'G', 'Bb', 'F'] dom13 = chords.dominant_thirteenth('C') # Returns: ['C', 'E', 'G', 'Bb', 'D', 'A'] ``` -------------------------------- ### Calculate Note at a Given Interval within a Key Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreIntervals.rst The `interval` function finds the note at a specific interval starting from a given note within a particular key. It requires the key, the starting note, and the interval as input, and will raise a `KeyError` if the start note is invalid. ```python >>> interval('C', 'D', 1) 'E' ``` -------------------------------- ### Creating and Setting Notes with mingus.containers.Note Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteModule.rst Demonstrates various ways to create and set Note objects, including specifying the note name, octave, and dynamically updating them. It also shows how to access note attributes like name, octave, and dynamics. ```python from mingus.containers import Note # Creating notes print(Note("C")) print(Note("C", 4)) print(Note("C", 5)) print(Note("C-3")) # Setting notes dynamically n = Note() n.set_note("C", 5) print(n) ``` -------------------------------- ### Importing the Track Class Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialTrackModule.rst Demonstrates how to import the Track class from the mingus.containers library. ```python from mingus.containers import Track ``` -------------------------------- ### Get Length of NoteContainer Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNotecontainer.rst Returns the total number of notes stored within the NoteContainer. ```python from mingus.containers import NoteContainer nc = NoteContainer(['C', 'E', 'G']) print(len(nc)) ``` -------------------------------- ### Get Note Names from NoteContainer Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNotecontainer.rst Returns a list containing the names of all unique notes currently in the container. ```python from mingus.containers import NoteContainer nc = NoteContainer(['C', 'E', 'G', 'C']) print(nc.get_note_names()) ``` -------------------------------- ### Note Initialization and Comparison in Python Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNote.rst Demonstrates how to initialize Note objects and compare them for equality, greater than, less than, etc. This enables sorting and other comparative operations on notes. ```python from mingus.containers import Note # Initialize notes n1 = Note('C', 4) n2 = Note('B', 4) # Comparison examples print(n1 == Note('C', 4)) # True print(n1 < n2) # True print(n1 > n2) # False print(n1 >= Note('C', 4)) # True print(n1 <= n2) # True print(n1 != n2) # True ``` -------------------------------- ### Hertz Conversion with Note Methods (from_hertz, to_hertz) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteModule.rst Explains the methods `from_hertz()` and `to_hertz()` for converting between Hertz values and Note objects. The `standard_pitch` parameter allows setting the reference pitch for A-4. ```python # Example usage (assuming Note class is imported and a Note object 'a' exists) # a.to_hertz() # Note.from_hertz(440) # Note.from_hertz(440, standard_pitch=442) ``` -------------------------------- ### Create NoteContainer from Interval Shorthand Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNotecontainer.rst Empties the container and adds notes defined by a starting note and an interval shorthand. Can specify direction (up or down). ```python from mingus.containers import NoteContainer nc = NoteContainer() nc.from_interval_shorthand('C', '5') print(nnc) ``` ```python from mingus.containers import NoteContainer nc = NoteContainer() nc.from_interval_shorthand('C', '5', False) print(nnc) ``` -------------------------------- ### Convert Progressions to Chords Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialProgressions.rst Demonstrates converting a list of roman numeral chord progressions into actual chords for a given key. It handles simple and complex progressions, including prefixes and suffixes. ```python progression = ["I", "IV", "V7"] progressions.to_chords(progression, "C") progressions.to_chords(progression, "F") ``` ```python progressions.to_chords(["I", "bIV", "VIIdim7"]) ``` -------------------------------- ### List Notation for Composition (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialCompositionModule.rst Explains how to use list notation with a Composition object, including checking its length and assigning a Track to a specific index. This allows for direct manipulation of tracks by their position. ```python from mingus.containers import Composition, Track c = Composition() len(c) c + Track() c[0] = Track ``` -------------------------------- ### Track List Notation Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialTrackModule.rst Shows how Tracks can be treated as lists, allowing access and assignment of Bars using index notation. ```python t = Track() b = Bar() b + "C" t + b t[0] t[0] = Bar() t[0] ``` -------------------------------- ### Integer to Note Conversion with mingus.containers.Note.from_int Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteModule.rst Demonstrates the `from_int` method of the Note class, which converts an integer representation back into a musical note, correctly mapping integers to notes and octaves. ```python from mingus.containers import Note c = Note() c.from_int(12) print(c) ``` -------------------------------- ### Get Supertonic Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the supertonic chord in a given musical key. The supertonic is the second chord in a major scale. ```python >>> supertonic('C') ['D', 'F', 'A'] ``` -------------------------------- ### Get Submediant Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the submediant chord in a given musical key. The submediant is the sixth chord in a major scale. ```python >>> submediant('C') ['A', 'C', 'E'] ``` -------------------------------- ### Adding Notes to a NoteContainer Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteContainerModule.rst Illustrates various methods for adding notes to a NoteContainer, including single notes as strings or Note objects, and multiple notes via lists or another NoteContainer. It highlights the flexibility in adding note collections. ```python from mingus.containers import NoteContainer from mingus.core import notes n = NoteContainer() n.add_note("C") print(n) n.empty() n.add_notes(["C", "E"]) print(n) n.empty() n.add_notes(NoteContainer(["C", "E"])) print(n) n.empty() n.add_notes([notes.Note("C"), notes.Note("E")]) print(n) n.empty() n.add_notes(notes.Note("C")) n.add_notes(notes.Note("E")) print(n) ``` -------------------------------- ### Get Subdominant Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the subdominant chord in a given musical key. The subdominant is the fourth chord in a major scale. ```python >>> subdominant('C') ['F', 'A', 'C'] ``` -------------------------------- ### Validate meter representation (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreMeter.rst Checks if a given tuple is a valid representation of a musical meter. Examples include (3,4) and (4,4). ```python from mingus.core import meter print(meter.is_valid((3, 4))) print(meter.is_valid((4, 4))) print(meter.is_valid((5, 8))) ``` -------------------------------- ### Listing Basic Keys Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialDiatonic.rst Accesses a predefined list of basic keys. This list is based on the circle of fifths and provides a standard set of keys for reference. ```python diatonic.basic_keys ``` -------------------------------- ### Get Subtonic Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the subtonic chord in a given musical key. The subtonic is the seventh chord in a natural minor scale. ```python >>> subtonic('C') ['B', 'D', 'F'] ``` -------------------------------- ### Initialize FluidSynth MIDI Synthesizer Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialFluidsynth.rst Initializes the FluidSynth MIDI synthesizer. The first argument is the path to the SoundFont file (.SF2). An optional second argument can specify the audio driver (e.g., 'alsa', 'portaudio'). If no driver is specified, the system's default driver will be used. ```python from mingus.midi import fluidsynth fluidsynth.init("soundfont.SF2") fluidsynth.init("soundfont.SF2", "alsa") ``` -------------------------------- ### Get Dominant Chord Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the dominant chord for a given musical key. This function is essential for understanding tonal harmony and chord progressions. ```python def dominant(key): """ Return the dominant chord in key. """ pass ``` -------------------------------- ### Chord Substitutions Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialProgressions.rst Illustrates how to find possible chord substitutions for a given progression at a specific index. The depth parameter controls recursive substitution. ```python progressions.substitute(["I", "IV", "V", "I"], 0) ``` -------------------------------- ### Create Intervals using Shorthand Notation Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialIntervals.rst Uses the `from_shorthand` function to create intervals programmatically. It accepts a note, an interval shorthand (e.g., '3', 'b3'), and an optional boolean to indicate direction (up/down). ```python >>> from mingus.core.intervals import from_shorthand >>> from_shorthand("A", "3") 'C#' >>> from_shorthand("A", "b3") 'C' >>> from_shorthand("E", "2", False) 'D' ``` -------------------------------- ### Note Diminution (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreScales.rst Diminishes a given musical note by a semitone. For example, 'C' becomes 'Cb', and 'C#' becomes 'C'. This function is useful for chromatic alterations. ```python mingus.core.notes.diminish('C') # Output: 'Cb' mingus.core.notes.diminish('C#') # Output: 'C' ``` -------------------------------- ### Migrated Methods for Note Manipulation (augment, diminish, to_major, to_minor) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteModule.rst Demonstrates convenient methods migrated from `mingus.core.notes` to the Note class, such as `augment()`, `diminish()`, `to_major()`, and `to_minor()` for common note alterations. ```python from mingus.containers import Note a = Note("A") a.augment() print(a) a.diminish() print(a) a.to_major() print(a) a.to_minor() print(a) ``` -------------------------------- ### Note Augmentation (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreScales.rst Augments a given musical note by a semitone. For example, 'C' becomes 'C#', and 'Cb' becomes 'C'. This function is useful for chromatic alterations. ```python mingus.core.notes.augment('C') # Output: 'C#' mingus.core.notes.augment('Cb') # Output: 'C' ``` -------------------------------- ### Accessing Note Attributes (name, octave, dynamics) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialNoteModule.rst Illustrates how to access the fundamental attributes of a Note object: its name (e.g., 'C'), octave (e.g., 4), and dynamics (a dictionary for additional information like volume and effects). ```python from mingus.containers import Note c = Note("C") print(c) print(c.name) print(c.octave) print(c.dynamics) ``` -------------------------------- ### begin_track Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraTablature.rst A helper function to construct the initial characters of each bar in the tablature. ```APIDOC ## begin_track ### Description Helper function that builds the first few characters of every bar. ### Method begin_track ### Parameters #### Arguments - **tuning** (StringTuning or None) - Required - The tuning of the instrument. - **padding** (integer) - Optional - Default: 2. The amount of padding before the bar starts. ### Request Example ```python begin_track(tuning='standard', padding=2) ``` ### Response #### Success Response - **string**: The initial characters for a tablature bar. #### Response Example ```python '| ' ``` ``` -------------------------------- ### Get Mediant Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Returns the mediant chord within a given musical key. The mediant is typically the major third chord in a key. ```python >>> mediant('C') ['E', 'G', 'B'] ``` -------------------------------- ### Get Available Instruments Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraTunings.rst Retrieves a sorted list of all instrument names for which string tunings are defined within the module. This provides an overview of supported instruments. ```python def get_instruments(): # Return a sorted list of instruments that have string tunings defined # for them. pass ``` -------------------------------- ### add_headers Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraTablature.rst Creates a formatted header for tablature using provided information like title, subtitle, author, and tunings. ```APIDOC ## add_headers ### Description Creates a formatted header in the form of a list of strings using provided information. ### Method add_headers ### Parameters #### Arguments - **width** (integer) - Optional - Default: 80. The width of the header. - **title** (string) - Optional - Default: 'Untitled'. The title of the piece. - **subtitle** (string) - Optional - Default: ''. The subtitle of the piece. - **author** (string) - Optional - Default: ''. The author of the piece. - **email** (string) - Optional - Default: ''. The author's email. - **description** (string) - Optional - Default: ''. A description of the piece. - **tunings** (list) - Optional - Default: []. A list of tunings representing the instruments. ### Request Example ```python add_headers(width=80, title='My Song', subtitle='A great tune', author='Me', tunings=['standard']) ``` ### Response #### Success Response - **list of strings**: Each string represents a line in the header. #### Response Example ```python [ 'Title: My Song', 'Subtitle: A great tune', 'Author: Me', 'E-mail: ', 'Description: ', 'Standard tuning:', ' E A D G B E' ] ``` ``` -------------------------------- ### Initialize FluidSynth with a SoundFont File Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusMidiFluidsynth.rst This snippet demonstrates how to initialize FluidSynth with a specified soundfont file. This is a prerequisite for playing any audio using the fluidsynth module. Ensure the path to the soundfont file is correct. ```python from mingus.midi import fluidsynth fluidsynth.init('soundfontlocation.sf2') ``` -------------------------------- ### Get Natural Key Notes (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreScales.rst Returns an ordered list of notes belonging to a natural key. This can be specified with either uppercase for major keys or lowercase for minor keys. ```python mingus.core.scales.get_notes('F') # Output: ['F', 'G', 'A', 'Bb', 'C', 'D', 'E'] mingus.core.scales.get_notes('c') # Output: ['C', 'D', 'Eb', 'F', 'G', 'Ab', 'Bb'] ``` -------------------------------- ### Get Notes in a Key (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreKeys.rst Returns an ordered list of notes belonging to the natural scale of a given key. Handles both major and minor keys. ```python from mingus.core.keys import get_notes # Get notes for F major f_major_notes = get_notes('F') print(f"Notes in F major: {f_major_notes}") # Get notes for c minor c_minor_notes = get_notes('c') print(f"Notes in c minor: {c_minor_notes}") ``` -------------------------------- ### NoteContainer Initialization and Addition Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNote_container.rst Demonstrates initializing a NoteContainer with a list of notes and adding more notes using the add_note method. The add_note method automatically sorts notes and can handle notes as strings or Note objects, with optional octave and dynamics. Dependencies: mingus.containers.note_container.NoteContainer Input: Initial list of notes (strings or Note objects), a single note to add (string or Note object), optional octave and dynamics. Output: NoteContainer instance with added notes, sorted. ```python from mingus.containers import NoteContainer n = NoteContainer(['C', 'E', 'G']) n.add_note('A', octave=5) print(n) # Expected output: ['C-4', 'E-4', 'G-4', 'A-5'] ``` -------------------------------- ### Interval Calculation and Manipulation Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreIntervals.rst Functions to calculate intervals from shorthands, get notes at a specific interval, and invert intervals. These are useful for more complex musical analysis and composition. ```APIDOC ## GET /from_shorthand ### Description Return the note a specified interval away from a starting note, either up or down. ### Method GET ### Endpoint /from_shorthand ### Parameters #### Query Parameters - **note** (string) - Required - The starting note. - **interval** (string) - Required - The interval shorthand (e.g., 'b3', '2'). - **up** (boolean) - Optional - True to go up, False to go down. Defaults to True. ### Request Example ```json { "note": "A", "interval": "b3" } ``` ### Response #### Success Response (200) - **note** (string) - The resulting note. #### Response Example ```json { "note": "C" } ``` ## GET /get_interval ### Description Return the note an interval (in half notes) away from a given note. This function provides a direct calculation based on half steps. ### Method GET ### Endpoint /get_interval ### Parameters #### Query Parameters - **note** (string) - Required - The starting note. - **interval** (integer) - Required - The interval in half notes. - **key** (string) - Optional - The key to use for reference. Defaults to 'C'. ### Request Example ```json { "note": "C", "interval": 4 } ``` ### Response #### Success Response (200) - **note** (string) - The resulting note. #### Response Example ```json { "note": "E" } ``` ## POST /invert ### Description Invert a given interval. ### Method POST ### Endpoint /invert ### Parameters #### Request Body - **interval** (array) - Required - An array representing the interval, e.g., `['C', 'E']`. ### Request Example ```json { "interval": ["C", "E"] } ``` ### Response #### Success Response (200) - **inverted_interval** (array) - The inverted interval, e.g., `['E', 'C']`. #### Response Example ```json { "inverted_interval": ["E", "C"] } ``` ``` -------------------------------- ### Create and Set Composition Attributes (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/tutorialCompositionModule.rst Demonstrates how to create a Composition object and set its author and title attributes using the set_author and set_title methods. No external dependencies beyond the mingus library. ```python from mingus.containers import Composition c = Composition() c.set_author('Author', 'author@email.com') c.set_title('First Mingus Composition') ``` -------------------------------- ### NoteContainer Chord Shorthand Initialization Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNote_container.rst Initializes a NoteContainer by parsing chord shorthand notation. The container is emptied before adding the notes corresponding to the chord. Dependencies: mingus.containers.note_container.NoteContainer, mingus.core.chords.from_shorthand Input: A string representing a chord shorthand (e.g., 'Am'). Output: A NoteContainer populated with the notes of the specified chord. ```python from mingus.containers import NoteContainer nc = NoteContainer() nc.from_chord_shorthand('Am') print(nc) # Expected output: ['A-4', 'C-5', 'E-5'] ``` -------------------------------- ### Get Mediant Seventh Chord (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusCoreChords.rst Retrieves the mediant seventh chord for a specified musical key. This chord includes the root, third, fifth, and seventh of the mediant. -------------------------------- ### Note Class Initialization and Attributes Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusContainersNote.rst Details on how to initialize a Note object and its core attributes. ```APIDOC ## Note Class ### Description Represents a musical note with attributes such as name, octave, dynamics, velocity, and channel. ### Initialization `__init__(self, name=C, octave=4, dynamics=None, velocity=None, channel=None)` - **name** (str) - The name of the note (e.g., 'C', 'G#'). Defaults to 'C'. - **octave** (int) - The octave of the note. Defaults to 4. - **dynamics** (dict) - Deprecated. Use `velocity` and `channel`. - **velocity** (int) - The velocity of the note. - **channel** (int) - The MIDI channel of the note. ### Attributes - **name** (str) - The name of the note. - **octave** (int) - The octave of the note. - **dynamics** (dict) - Deprecated attribute for dynamics. - **velocity** (int) - The velocity of the note. - **channel** (int) - The MIDI channel of the note. ### Example ```python from mingus.containers import Note # Initialize a C note in octave 4 my_note = Note('C', 4) # Initialize a G# note in octave 5 with velocity 100 and channel 1 sharp_note = Note('G#', 5, velocity=100, channel=1) ``` ``` -------------------------------- ### Get Tunings by Number of Strings (Python) Source: https://github.com/bspaans/python-mingus/blob/master/doc/wiki/refMingusExtraTunings.rst Retrieves default tunings for a specified number of strings. This function is useful for initializing stringed instruments with common tuning configurations. ```python >>> tunings.get_tunings(nr_of_string = 4) ```