instrument/auto-set-subset-id [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DATE
July 27th 2018, Heidhausen
DESCRIPTION
Set the subset-id slot to be the same as the id slot.
ARGUMENTS
- an instrument instance
RETURN VALUE
- the instrument instance
SYNOPSIS
(defmethod auto-set-subset-id ((ins instrument))
instrument/default-chord-function [ Functions ]
[ Top ] [ instrument ] [ Functions ]
DESCRIPTION
If an instrument is able to play chords, a function must be defined to select pitches from a list that it can play as a chord. This function (as a symbol) is passed as a slot to the instrument instance. This is the default function. It returns a 2-note chord with the pitch at index plus that below it, or that above it if there are no lower pitches available. Or it just returns a single-pitch chord object if neither of those cases are possible. NB: The arguments are supplied by slippery chicken when it calls the function.
ARGUMENTS
- The current number from the pitch-seq. Currently ignored by default. - The index that the first argument was translated into by the offset and scaler (based on trying to get a best fit for the instrument and set). This can be assumed to be a legal reference into pitch-list as it was calculated as fitting in pitch-seq::get-notes. (zero-based.) - The pitch-list created from the set, taking into account the instrument's range and other notes already played by other instruments. - The current pitch-seq object. Currently ignored by default. - The current instrument object. Currently ignored by default. - The current set object. Currently ignored by default.
RETURN VALUE
A chord object.
SYNOPSIS
(defun default-chord-function (curve-num index pitch-list pitch-seq instrument set)
instrument/force-in-range [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DATE
October 9th 2013
DESCRIPTION
Forces a pitch to be within an instrument's range by transposing up or down the required number of octaves. NB it doesn't force a microtonal pitch to the nearest chromatic pitch so whether it's playable on an instrument is not checked here.
ARGUMENTS
- the instrument object - the piece object
OPTIONAL ARGUMENTS
keyword argument: - :sounding. Whether the pitch should be considered a sounding pitch. Default = NIL. - see other keywords to the in-range method as these are also available
RETURN VALUE
A pitch object within the instrument's range.
EXAMPLE
(let ((cl (get-standard-ins 'b-flat-clarinet))) ;; needs to go down 1 octave (print (data (force-in-range cl (make-pitch 'e7)))) ;; needs to go up 2 octaves (print (data (force-in-range cl (make-pitch 'g1)))) ;; the t indicates we're dealing with sounding pitches so here there's no ;; transposition... (print (data (force-in-range cl (make-pitch 'd3) :sounding t))) ;; ... but here there is (print (data (force-in-range cl (make-pitch 'd3))))) => E6 G3 D3 D4
SYNOPSIS
(defmethod force-in-range ((ins instrument) pitch &key sounding try-artificial-harmonic impossible-microtones (no-missing-notes t))
instrument/in-range [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DESCRIPTION
Checks whether a specified pitch/chord falls within the defined range of a given instrument object or not.
ARGUMENTS
- An instrument object. - A pitch or chord item (either a chord object, pitch object, or note-name symbol). Chords are handled by a separate method (of the same name).
OPTIONAL ARGUMENTS
- T or NIL to indicate whether the pitch specified is to be compared with the given instrument object's sounding or written range. T = Sounding. Default = NIL. If T, a secondary NIL is also returned to indicate that the specified pitch is neither too high nor too low. - T or NIL to indiciate whether an artificial harmonic should be tried if the pitch is too high for an instrument whose :harmonics slot is T. Default = NIL. - T or NIL to indicate whether a microtonal pitch should be considered 'in-range' when the instrument can't play microtones. Default = NIL (although theoretically within range it's not playable). - T or NIL to indicate whether pitches the instrument can't play (the missing-notes slot) should cause the method to return NIL. Default = T = 'missing notes' will not be considered in range.
RETURN VALUE
Returns T if the specified pitch falls between the lowest-sounding/lowest-written and the highest-sounding/highest-written pitches of the given pitch object, otherwise NIL. If the specified pitch is outside of the range, an additional value of 0 or 1 is also returned to indicate whether the specified pitch is too high (1) or too low (0). If it's out of range but could be achieved by an artificial harmonic (just the perfect 4th variety) on an instrument with :harmonics T, then the additional value will be a chord object instead (the two pitches, including diamond notehead for the second, which would achieve the desired pitch.
EXAMPLE
;; Determine if a pitch provided as a note-name symbol falls within the written ;; range of a non-transposing instrument (let ((i1 (make-instrument 'inst1 :lowest-written 'bf3 :highest-written 'a6))) (in-range i1 'c4)) => T, NIL ;; Determine if a pitch provided as a note-name symbol falls within the ;; sounding range of a transposing instrument, using the optional argument T (let ((i2 (make-instrument 'inst1 :lowest-written 'fs3 :highest-written 'c6 :transposition 'BF))) (in-range i2 'c6 T)) => NIL, 1 ;; A pitch object can be used as the specified pitch (let ((i2 (make-instrument 'inst1 :lowest-written 'fs3 :highest-written 'c6 :transposition 'BF))) (in-range i2 (make-pitch 'd6))) => NIL, 1
SYNOPSIS
(defmethod in-range ((ins instrument) pitch &optional sounding try-artificial-harmonic impossible-microtones (no-missing-notes t))
instrument/make-instrument [ Functions ]
[ Top ] [ instrument ] [ Functions ]
DESCRIPTION
Create an instrument object, specifying the values for a number of parameters for describing characteristics of a given instrument, such as lowest and highest pitch, transposition, clefs used by the instrument etc. NB: The user will generally define instruments in the context of the :instrument-palette slot of a call to make-slippery-chicken, or an explicit call to the make-instrument-palette function.
ARGUMENTS
- A symbol that is the instrument ID.
OPTIONAL ARGUMENTS
keyword arguments: - :staff-name. String. This is the unabbreviated instrument name that will be used for the first page of printed scores. - :staff-short-name. String. This is the abbreviated instrument name that will be used for subsequent pages of printed scores. - :lowest-written. Note-name symbol. This is the lowest written pitch available on the given instrument. Defaults to NIL. A user may only define either the lowest-written value or the lowest-sounding value. If a lowest-written value is given, the method automatically determines the lowest-sounding value based on the lowest-written value and the transposition value. - :highest-written. Note-name symbol. This is the highest written pitch available on the given instrument. Defaults to NIL. A user may only define either the highest-written value or the highest-sounding value. If a highest-written value is given, the method automatically determines the highest-sounding value based on the highest-written value and the transposition value. - :lowest-sounding. Note-name symbol. This is the lowest sounding pitch available on the given instrument. Defaults to NIL. A user may only define either the lowest-sounding value or the lowest-written value. If a lowest-sounding value is given, the method automatically determines the lowest-written value based on the lowest-sounding value and the transposition value. - :highest-sounding. Note-name symbol. This is the highest sounding pitch available on the given instrument. Defaults to NIL. A user may only define either the highest-sounding value or the highest-written value. If a highest-sounding value is given, the method automatically determines the highest-written value based on the highest-sounding value and the transposition value. - :transposition. Note-name symbol. This is the key of the given instrument (such as the "B-flat" of the "B-flat clarinet"), given as a note-name symbol (such as 'BF for B-flat). If a value is only given for the :transposition argument but not for the :transposition-semitones argument, and there are multiple semitone transposition options for the key specified, the method will choose the most common semitone transposition for that given key. NB: When using keyword argument :transposition rather than :transposition-semitones, sc will have a warning printed by cm with indications as to which direction the transposition has been undertaken. - :transposition-semitones. Integer (positive or negative). The number of semitones lower that a given instrument sounds than written, e.g. -2 for B-flat Clarinet. If a value is only given for the :transposition-semitones argument but not for the :transposition argument, the method will automatically determine the key for the :transposition argument. The listener will drop into the debugger with an error if a key is given for the :transposition argument and the number specified for the :transposition-semitones does not correspond with that key. - :starting-clef. Symbol. This value determines the first clef that a given instrument is to use if that instrument can use different clefs. For a list of available clefs see the :clefs argument below. Default = 'treble. - :clefs. List of symbols. All clefs that a given instrument may use in the course of a piece. Clefs available are treble, treble-8vb, alto, tenor, bass, percussion, double-treble, and double-bass. Clefs are to be given in order of preference. Defaults automatically to the value given to :starting-clef if no other clefs are specified. NB: If a separate list is indeed given here, the method will automatically add the value for :starting-clef as well, should it have been omitted. In this case, a warning will also be printed. - :clefs-in-c. List of symbols. Similar to :clefs, but designates which clefs an instrument uses in a C-score; for example, bass clarinet may notated in bass clef for sounding pitches though it is standardly notated in treble clef for written pitches. For a list of clefs available see the :clefs argument above. - :largest-fast-leap. Number. This value indicates the largest interval, in semitones, that a player can feasibly perform at a fast tempo on the given instrument. Default = 999. "Fast" here is determined for the whole piece by the slippery-chicken class's fast-leap-threshold slot. - :score-write-in-c. T or NIL. Determines whether the musical material for the given instrument should be printed in C. T = print in C. Default = NIL. - :score-write-bar-line. Integer. This argument is used for indicating system-grouping in the printed score. The given integer specifies how many instruments above this one should be grouped together with an unbroken bar-line. Default = 1. - :midi-program. Integer. The number of the MIDI program to be used for playing back this instrument. Default = 1. - :chords. T or NIL. Indicates whether the given instrument is capable of playing chords (starting with 2-note simultaneities, but not multiphonics). - :subset-id. Symbol, string, number, or NIL. Indicates the ID of a specific subset of the current set to which the instrument's pitch selection is limited. No error will occur if no subset with this ID exists in a given set, i.e. some may include this subset, some may not and everything will function correctly--if the specified subset is not present in the current set the pitch selection routine will select from the whole set. In every case however, the usual set limiting according to instrument range etc. will also apply. Default = NIL. - :microtones. T or NIL. Indicates whether the instrument can play microtones. T = can play microtones. Default = NIL. NB: If this value is set to T, a separate :microtones-midi-channel must be specified; this can be done for the given instrument object in the :ensemble block of the make-slippery-chicken function. - :missing-notes. A list of note-name symbols. This is a list of any notes which the given instrument can't play, for example certain quarter-tones. These are to be given by the user as written-pitch note-name symbols, but are always stored by the method as sounding pitches. - :prefers-notes. Symbol. 'high, 'low or NIL. This value indicates whether to give preference, when choosing notes for the given instrument, to pitches from the upper or lower end of the instrument's range. When NIL, preference is given to notes from its middle register. Default = NIL. - :chord-function. If the given instrument can play chords then it will need a reference to a function that can select chords for it. NB This should be a symbol not a function object; thus, 'my-fun not #'my-fun. Default = NIL. - :staff-lines. How many the lines the staff should have when this instrument is playing. When we change instrument mid-piece the number of staff lines will change accordingly. Similarly, if we start with an instrument that doesn't use 5 staff lines, we'll begin a piece with the correct number. Default = 5.
RETURN VALUE
Returns an instrument object.
EXAMPLE
;; Make-instrument for the flute: ; (make-instrument 'flute :staff-name "Flute" :staff-short-name "Fl." :lowest-written 'c4 :highest-written 'd7 :starting-clef 'treble :midi-program 74 :chords nil :microtones t :missing-notes '(cqs4 dqf4)) => INSTRUMENT: lowest-written: PITCH: frequency: 261.626, midi-note: 60, midi-channel: 0 [...] , highest-written: PITCH: frequency: 2349.318, midi-note: 98, midi-channel: 0 [...] lowest-sounding: PITCH: frequency: 261.626, midi-note: 60, midi-channel: 0 [...] , highest-sounding: PITCH: frequency: 2349.318, midi-note: 98, midi-channel: 0 starting-clef: TREBLE, clefs: (TREBLE), clefs-in-c: (TREBLE) prefers-notes: NIL, midi-program: 74 transposition: C, transposition-semitones: 0 score-write-in-c: NIL, score-write-bar-line: 1 chords: NIL, chord-function: NIL, total-bars: 0 total-notes: 0, total-duration: 0.0 total-degrees: 0, microtones: T missing-notes: (CQS4 DQF4), subset-id: NIL staff-name: Flute, staff-short-name : Fl., largest-fast-leap: 999 [...] NAMED-OBJECT: id: FLUTE, tag: NIL, data: NIL ;; A make-instrument for the b-flat bass clarinet ; (make-instrument 'bass-clarinet :staff-name "Bass Clarinet" :lowest-written 'c3 :highest-written 'g6 :staff-short-name "Bass Cl." :chords nil :midi-program 72 :starting-clef 'treble :microtones t :prefers-notes 'low :missing-notes '(aqs4 bqf4 bqs4 cqs5 dqf5 gqf3 fqs3 fqf3 eqf3 dqs3 dqf3 cqs3) :clefs '(treble) :clefs-in-c '(treble bass) :transposition-semitones -14) => INSTRUMENT: lowest-written: PITCH: frequency: 130.813, midi-note: 48, midi-channel: 0 [...] , highest-written: PITCH: frequency: 1567.982, midi-note: 91, midi-channel: 0 [...] lowest-sounding: PITCH: frequency: 58.270, midi-note: 34, midi-channel: 0 [...] , highest-sounding: PITCH: frequency: 698.456, midi-note: 77, midi-channel: 0 [...] NAMED-OBJECT: id: BASS-CLARINET, tag: NIL, data: NIL
SYNOPSIS
(defun make-instrument (id &key staff-name staff-short-name lowest-written highest-written lowest-sounding highest-sounding transposition transposition-semitones (starting-clef 'treble) clefs (largest-fast-leap 999) score-write-in-c (score-write-bar-line 1) (midi-program 1) (staff-lines 5) chords clefs-in-c subset-id microtones missing-notes prefers-notes chord-function harmonics open-strings open-string-marks (nodes '((12 2) (7 3) (5 4) (4 5))))
instrument/natural-harmonic? [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DATE
8th January 2019, Heidhausen
DESCRIPTION
Determine whether a note can be played as a natural harmonic. If so, then we return the appropriate pitch object with harmonic marks, etc. (see below). In order for this to work, the :harmonics slot of the instrument will need to be T and the open-strings, nodes, and open-string-marks slots must be set appropriately. The default nodes are ((12 2) (7 3) (5 4) (4 5) (3 6)) where the first of each pair is the nodal point in semitones above the open string pitch and the second is the partial number produced. The open-strings slot should be a list of descending pitches (symbols or objects) and the open-strings-marks is something like (i ii iii iv) for orchestral strings or (c1 c2 c3 c4 c5 c6) for guitar. Note that these two slots must be in the same order and also that the marks must be recognised by the output score routine if they are to be meaningful. NB The note returned is the 'written' note (in the case of e.g. double-bass) but won't be transposed down an octave for e.g. harp notation. See also the natural-harmonic function in pitch.lsp for an on-the-fly (and thus less efficient) routine that works with any arbitrary string tuning independently of instrument objects.
ARGUMENTS
- an instrument object - a note, either as a pitch symbol or object. This should be the written pitch in the case of transposing instruments such as the guitar or double bass.
OPTIONAL ARGUMENTS
- frequency tolerance in cents. (A natural major third (5th partial) is 14 cents from its nearest equal-tempered neighbour.) Default = 15.
RETURN VALUE
A pitch object with marks attached for the harmonic (circle) and string, where appropriate, plus, as a second value, and only for instruments with open-strings (e.g. orchestral strings) the note at the nodal point, with a diamond note-head mark. These could be combined into a chord for notation purposes.
EXAMPLE
(natural-harmonic? (get-standard-ins 'violin) 'bf5) --> NIL NIL (natural-harmonic? (get-standard-ins 'violin) 'b5) --> PITCH: frequency: 987.767, midi-note: 83, midi-channel: 1 pitch-bend: 0.0 degree: 166, data-consistent: T, white-note: B5 nearest-chromatic: B5 src: 3.7754972, src-ref-pitch: C4, score-note: B5 qtr-sharp: NIL, qtr-flat: NIL, qtr-tone: NIL, micro-tone: NIL, sharp: NIL, flat: NIL, natural: T, octave: 5, c5ths: 0, no-8ve: B, no-8ve-no-acc: B show-accidental: T, white-degree: 48, accidental: N, accidental-in-parentheses: NIL, marks: (IV HARM), ... ;;; or with scordatura: (let ((vln (get-standard-ins 'violin))) (setf (open-strings vln) '(eqs5 a4 d4 g3)) (prog1 (natural-harmonic? vln 'eqs6) (setf (open-strings vln) '(e5 a4 d4 g3)))) ; reset --> PITCH: frequency: 1357.146, midi-note: 88, midi-channel: 1 pitch-bend: 0.5 degree: 177, data-consistent: T, white-note: E6 nearest-chromatic: E6 src: 5.1873584, src-ref-pitch: C4, score-note: ES6 qtr-sharp: 1, qtr-flat: NIL, qtr-tone: 1, micro-tone: T, sharp: NIL, flat: NIL, natural: NIL, octave: 6, c5ths: 0, no-8ve: EQS, no-8ve-no-acc: E show-accidental: T, white-degree: 51, accidental: QS, accidental-in-parentheses: NIL, marks: (I HARM), ...
SYNOPSIS
(defmethod natural-harmonic? ((ins instrument) note &optional (tolerance 15))
instrument/prefers-high [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DESCRIPTION
Determine whether the PREFERS-NOTES slot of a given instrument object is set to 'HIGH.
ARGUMENTS
- An instrument object.
RETURN VALUE
Returns T if the PREFERS-NOTES slot of the given instrument object is set to 'HIGH, otherwise NIL.
EXAMPLE
;; Returns T if the PREFERS-NOTES slot of the given instrument object is set to ; ;; 'HIGH ; (let ((i1 (make-instrument 'inst :prefers-notes 'high))) (prefers-high i1)) => T ;; Returns NIL if the PREFERS-NOTES slot of the given instrument object is not ; ;; set to 'HIGH ; (let ((i1 (make-instrument 'inst1)) (i2 (make-instrument 'inst2 :prefers-notes 'low))) (print (prefers-high i1)) (print (prefers-high i2))) => NIL NIL
SYNOPSIS
(defmethod prefers-high ((ins instrument))
instrument/prefers-low [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DESCRIPTION
Determine whether the PREFERS-NOTES slot of a given instrument object is set to 'LOW.
ARGUMENTS
- An instrument object.
RETURN VALUE
Returns T if the PREFERS-NOTES slot of the given instrument object is set to 'LOW, otherwise NIL.
EXAMPLE
;; Returns T if the PREFERS-NOTES slot of the given instrument object is set to ; ;; 'LOW ; (let ((i1 (make-instrument 'inst :prefers-notes 'low))) (prefers-low i1)) => T ;; Returns NIL if the PREFERS-NOTES slot of the given instrument object is not ; ;; set to 'LOW ; (let ((i1 (make-instrument 'inst1)) (i2 (make-instrument 'inst2 :prefers-notes 'high))) (print (prefers-low i1)) (print (prefers-low i2))) => NIL NIL
SYNOPSIS
(defmethod prefers-low ((ins instrument))
instrument/set-prefers-high [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DATE
05 Feb 2011
DESCRIPTION
Sets the PREFERS-NOTES slot of the given instrument object to 'HIGH.
ARGUMENTS
- An instrument object.
OPTIONAL ARGUMENTS
(- optional ignore argument; for internal use only).
RETURN VALUE
Returns symbol HIGH.
EXAMPLE
;; Returns symbol HIGH by default ; (let ((i1 (make-instrument 'inst))) (set-prefers-high i1)) => HIGH ;; Create an instrument object with only an ID, print the PREFERS-NOTES slot to ; ;; see that it is NIL by default, apply the set-prefers-high, and print the ; ;; slot again to see the changes ; (let ((i1 (make-instrument 'inst))) (print (prefers-notes i1)) (set-prefers-high i1) (print (prefers-notes i1))) => NIL HIGH ;; Reset to HIGH from LOW ; (let ((i1 (make-instrument 'inst :prefers-notes 'low))) (print (prefers-notes i1)) (set-prefers-high i1) (print (prefers-notes i1))) => LOW HIGH
SYNOPSIS
(defmethod set-prefers-high ((ins instrument) &optional ignore)
instrument/set-prefers-low [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DATE
05 Feb 2011
DESCRIPTION
Sets the PREFERS-NOTES slot of the given instrument object to 'LOW.
ARGUMENTS
- An instrument object.
OPTIONAL ARGUMENTS
(- optional ignore argument; for internal use only).
RETURN VALUE
Returns symbol LOW.
EXAMPLE
;; Returns symbol LOW by default (let ((i1 (make-instrument 'inst))) (set-prefers-low i1)) => LOW ;; Create an instrument object with only an ID, print the PREFERS-NOTES slot to ;; see that it is NIL by default, apply the set-prefers-low, and print the ;; slot again to see the changes (let ((i1 (make-instrument 'inst))) (print (prefers-notes i1)) (set-prefers-low i1) (print (prefers-notes i1))) => NIL LOW ;; Reset to LOW from HIGH (let ((i1 (make-instrument 'inst :prefers-notes 'high))) (print (prefers-notes i1)) (set-prefers-low i1) (print (prefers-notes i1))) => HIGH LOW
SYNOPSIS
(defmethod set-prefers-low ((ins instrument) &optional ignore)
instrument/transposing-instrument-p [ Methods ]
[ Top ] [ instrument ] [ Methods ]
DESCRIPTION
Determine whether a given instrument object defines a transposing instrument.
ARGUMENTS
- An instrument object.
OPTIONAL ARGUMENTS
- ignore-octaves. T or NIL to indicate whether instruments that transpose at the octave are to be considered transposing instruments. T = instruments that transpose at the octave are not considered transposing instruments. Default = T.
RETURN VALUE
Returns T if the given instrument object defines a transposing instrument, otherwise NIL.
EXAMPLE
;; Returns NIL if the instrument is not a transposing instrument ; (let ((i1 (make-instrument 'instrument-one))) (transposing-instrument-p i1)) => NIL ;; Returns T if the instrument object has been defined using a non-NIL value ; ;; for :transposition ; (let ((i2 (make-instrument 'instrument-two :transposition 'bf))) (transposing-instrument-p i2)) => T ;; Returns T if the instrument object has been defined using a non-0 value for ; ;; :transposition-semitones ; (let ((i3 (make-instrument 'instrument-two :transposition-semitones -3))) (transposing-instrument-p i3)) => T ;; Setting the optional argument to NIL causes instruments that transpose at ; ;; the octave to return T. ; (let ((i3 (make-instrument 'instrument-two :transposition-semitones -12))) (transposing-instrument-p i3)) => NIL (let ((i3 (make-instrument 'instrument-two :transposition-semitones -12))) (transposing-instrument-p i3 nil)) => T
SYNOPSIS
(defmethod transposing-instrument-p ((ins instrument) &optional (ignore-octaves t))
linked-named-object/instrument [ Classes ]
[ Top ] [ linked-named-object ] [ Classes ]
NAME
instrument File: instrument.lsp Class Hierarchy: named-object -> linked-named-object -> instrument Version: 1.1.0 Project: slippery chicken (algorithmic composition) Purpose: Implementation of the instrument class which defines musical instrument properties like range and collects/stores information about what the instrument plays: how many notes, in how many bars etc. Author: Michael Edwards: m@michael-edwards.org Creation date: 4th September 2001 $$ Last modified: 11:08:27 Wed Jul 17 2024 CEST SVN ID: $Id$