abcsound: an abc Front End for CSound


Python: module abcsound
 
 
abcsound
index
/cygdrive/d/jk/abcsound/abcsound.py

Convert (enhanced) abc notation to a Csound score.

 
Modules
       
copy
re
string
sys

 
Classes
       
AbcException
CsoundScoreAnalyzer
Element
AbcDefaultDurationElement
AbcElement
AbcBowDirection
AbcChord
AbcDecoration
AbcLineEnd
AbcMeasureBar
AbcNlet
AbcNote
AbcRepeat
AbcRepeatEnd
AbcRest
AbcSlurEnd
AbcSlurStart
AbcTie
AbcMetaElement
AbcMeterElement
AbcTempoElement
CsoundElement
InstrumentElement
VoiceData
VoicesElement

 
class AbcBowDirection(AbcElement)
    Represents an abc bow-direction instruction.
 
 
Method resolution order:
AbcBowDirection
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcChord(AbcElement)
    Represents the guitar-chord notation in abc.
 
 
Method resolution order:
AbcChord
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcDecoration(AbcElement)
    Represents a decoration. Decorations can contain free-form text;
here we use them for Csound control data. NOTE: DECORATORS MUST
APPEAR ENTIRELY ON A SINGLE LINE!
 
 
Method resolution order:
AbcDecoration
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcDefaultDurationElement(Element)
    Represents an abc L: element.
 
  Methods defined here:
__str__(self)
analyze(self, score)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcElement(Element)
    A musical element of an abc score.  May be a note, measure, repeat
marker, or almost anything else.  Most elements have a start time
and a duration, although even this is not necessarily universal.
Subclasses of AbcElement implement processing specific to each
kind of score element.  Note that elements parsed from the score
are NOT represented recursively, but rather as simple linear
lists. This is because, contrary to what a casual inspection might
suggest, abc is a line-oriented language with non-recursive
structure.  A tie or repeat, for example, my begin or end in the
middle of a measure, which breaks the obvious representation of a
score containing lines containing measures containing notes. Also
the fact that multiple voices are written as successive parallel
lines causes practical problems with recursive structure.
 
  Static methods defined here:
read(txt, pos)
Read this element from txt at the given position.
Return the next position to look at.

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcException
    A general exception class.
 
  Methods defined here:
__init__(self, cls, meth, msg)

 
class AbcLineEnd(AbcElement)
    We saw an end-of-line. Not very interesting.
 
 
Method resolution order:
AbcLineEnd
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcMeasureBar(AbcElement)
    Represents a measure bar.
 
 
Method resolution order:
AbcMeasureBar
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcMetaElement(Element)
    Represents an abc meta-element. Handles "X:" notation not handled
by the classes above.
 
  Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcMeterElement(Element)
    Represents an abc M: element.
 
  Methods defined here:
__str__(self)
analyze(self, score)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcNlet(AbcElement)
    Represents a triplet, quadruplet, etc.
 
 
Method resolution order:
AbcNlet
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcNote(AbcElement)
    Represents a note at a particular time, duration, frequency.
 
 
Method resolution order:
AbcNote
AbcElement
Element

Methods defined here:
__str__(self)
analyze(self, score)
csoundPrint(self, score)
determinePitch(self, score)
implementSlur(self)
parseNote(self)
Convert a textual note into a note element.
prevNote(self)
readNote(self, txt, pos)
Read the note at txt.pos, returning the new position.

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)

 
class AbcRepeat(AbcElement)
    Represents a repeat mark (beginning or end of a repeated
range). Alternate repeat ending marks are represented by
the
 
 
Method resolution order:
AbcRepeat
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcRepeatEnd(AbcElement)
    Represents the beginning of a repeat-section ending.
 
 
Method resolution order:
AbcRepeatEnd
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcRest(AbcElement)
    A rest.
 
 
Method resolution order:
AbcRest
AbcElement
Element

Methods defined here:
__str__(self)
analyze(self, score)
csoundPrint(self, score)
parseRest(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)

 
class AbcSlurEnd(AbcElement)
    End of a slur.
 
 
Method resolution order:
AbcSlurEnd
AbcElement
Element

Methods defined here:
__str__(self)
analyze(self, score)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcSlurStart(AbcElement)
    Beginning of a slur.
 
 
Method resolution order:
AbcSlurStart
AbcElement
Element

Methods defined here:
__str__(self)
analyze(self, score)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcTempoElement(Element)
    Represents an abc Q: element.
 
  Methods defined here:
__str__(self)
analyze(self, score)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class AbcTie(AbcElement)
    A 2-note tie.
 
 
Method resolution order:
AbcTie
AbcElement
Element

Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class CsoundElement(Element)
    Represents a literal line of Csound code to be inserted in the score.
 
  Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
class CsoundScoreAnalyzer
    Analyze score data and generate a Csound score.
 
  Methods defined here:
__init__(self)
analyzeItem(self, item)
analyzeScore(self, lines)
analyzeTimes(self)
assignPartLine(self, line)
buildRepeat(self, rpt, endings)
buildTimeline(self, lines)
clone(self, elLst)
establishVoices(self, voiceEl)
expandRepeats(self, voiceLine)
getInstrument(self, name)
isRepeat(self, item)
linkNoteElements(self, line)
nVoices(self)
newInstrument(self, name, instrEl)
setDefaultLen(self, dlen)
setMeter(self, n, kind)
setTempo(self, tempo)
timeLineAsString(self)
voiceDataPresent(self)
writeCsdScore(self, csdLines)
writeScore(self, csdLines)

 
class Element
    An element of the composition.  May represent musical notation,
metadata, Csound directives, or just about anything else. Subclasses
implement parsing and analysis logic.
 
  Methods defined here:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

Static methods defined here:
read(txt, pos)

 
class InstrumentElement(Element)
    Represents an "instr" directive. This maps an abcsound voice
to a Csound instrument defintion. An instr directive must
appear alone on a single line.
 
The instrument named "Oboe" corresponds to Csound instrument 104,
except that initial slurred notes are rendered with instrument 105,
and successive slurred notes are rendered with instrument 106.
Csound field p4 should be set to the amplitude and p5 to the pitch;
fields p6 and p7 should be set to 13.2 and 99, respectively:
 
instr Oboe csound=104 initslur=105 slur=106 p4=amp p5=pitch p6=13.2 p7=99
 
  Methods defined here:
__str__(self)
analyze(self, score)
buildIstmt(self, noteEl)
Build the score i-statement for a particular note.

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyzeTime(self, time)
csoundPrint(self, score)

 
class VoiceData(Element)
    Represents one or more complete parallel lines of music.
 
  Methods defined here:
__init__(self, voices, lines)
analyze(self, score)
analyzeTime(self, time)
assignPartTimes(self, startTime, part)
csoundPrint(self, score)

Static methods inherited from Element:
read(txt, pos)

 
class VoicesElement(Element)
    Represents a "voices" directive, telling us how many parallel
voices will be present in the score following, and which
instruments they use.  There can be different parts directives
in effect at different parts of the score. A voices directive
must appear alone on a single line.
 
Three parallel voices are in effect, named "Oboe", "Flute", "Guitar":
 
voices Oboe Flute Guitar
 
  Methods defined here:
__str__(self)

Static methods defined here:
read(txt, pos)

Methods inherited from Element:
__init__(self, **args)
analyze(self, score)
analyzeTime(self, time)
csoundPrint(self, score)

 
Functions
       
detail(chan, msg)
Print a debug message if the given chan is in details.
generateNoteMap()
Buils a map of note names to frequency.
getElement(txt, pos)
Extract an element from txt at position pos. Return
a tuple (element,nextPos).
 
Strategy: ask each AbcElement subclass to read an instance of itself
at the given location. When one succeeds, return the created AbcElement.
getElementsInString(txt)
Parse a string into its constituent elements.
getPitch(note)
Return the pitch associated with a given note name.
listToString(lst)
mapcan(func, lst)
parse(lines)
Parse the score into allElements.  analyzeScore() will then
build timing and instrument data.
preprocessLine(line)
Do an initial massage to get things the way we like.

 
Data
        BOW_DIRECTIONS = 'uv'
CHORD_MARK = '"'
CLOSE_TIE = ')'
DECORATOR_END = '}'
DECORATOR_START = '{'
DIGITS = '0123456789'
MEASURE_BAR = '|'
NLET_MARK = '('
NOTE_CONTENT = "ABCDEFGabcdefg_^.~0123456789',>/"
NOTE_INITIALS = 'ABCDEFGabcdefg_^.~'
NOTE_NAMES = 'ABCDEFGabcdefg'
NOTE_NAMES_HI = 'abcdefg'
NOTE_NAMES_LOW = 'ABCDEFG'
OCT_DOWN_MARK = ','
OCT_UP_MARK = "'"
OPEN_TIE_OR_NLET = '('
ORNAMENT_MARK = '~'
REPEAT_MARK = ':'
REST_CONTENT = '0123456789/>'
REST_MARK = 'z'
SINGLE_DECORATION = '~'
SLUR_END = ')'
SLUR_START = '('
TIE_MARK = '-'
allElementClasses = [<class abcsound.CsoundElement at 0x7fef55cc>, <class abcsound.VoicesElement at 0x7fef55fc>, <class abcsound.InstrumentElement at 0x7fef562c>, <class abcsound.AbcDefaultDurationElement at 0x7fef565c>, <class abcsound.AbcMeterElement at 0x7fef568c>, <class abcsound.AbcTempoElement at 0x7fef56bc>, <class abcsound.AbcMetaElement at 0x7fef56ec>, <class abcsound.AbcMeasureBar at 0x7fef571c>, <class abcsound.AbcLineEnd at 0x7fef574c>, <class abcsound.AbcRest at 0x7fef577c>, <class abcsound.AbcNote at 0x7fef57ac>, <class abcsound.AbcRepeatEnd at 0x7fef57dc>, <class abcsound.AbcRepeat at 0x7fef580c>, <class abcsound.AbcNlet at 0x7fef583c>, <class abcsound.AbcSlurStart at 0x7fef586c>, <class abcsound.AbcSlurEnd at 0x7fef589c>, <class abcsound.AbcTie at 0x7fef58cc>, <class abcsound.AbcDecoration at 0x7fef58fc>, <class abcsound.AbcChord at 0x7fef592c>, <class abcsound.AbcBowDirection at 0x7fef595c>]
allLines = []
details = ['analyze']
noteFreqs = {12: 256.0, 'a': 430.53896457590599, 'b': 483.2636480463882, 'bb': 456.14014364783441, 'c': 256.0, 'c#': 271.22255215360002, 'd': 287.35028436215737, 'd#': 304.43702143268371, 'e': 322.53978876176836, 'f': 341.71900265253851, ...}
semitoneMult = 1.0594630943500001
testLines = ['K:G', 'R:jig', 'instr Oboe csound=104 p4=amp p5=pitch p6=13.2 p7=99', 'voices Oboe', ':a~buc (dvef)::"Am"g (3 zdz {whoohoo!}b ^c\'/2._D2,(e\'\'/2|1z/2A-B-C-D)zC/2|2z/2A-B-D-D)z/2C:|', ':abc def:||:gab cde|[1defabc|[2abcdef:|', ':ABC DEF:||:GAB CDE|[1DEFABC|[2ABCDEF:|', ':a~buc (dvef)::"Am"g (3 zdz {whoohoo!}b ^c\'/2._D2,(e\'\'/2|1z/2A-B-C-D)zC/2|2z/2A-B-D-D)z/2C:|', ':abc def:||:gab cde|[1defabc|[2abcdef:|', ':ABC DEF:||:GAB CDE|[1DEFABC|[2ABCDEF:|']


Last changed:
09-07-09 01:21:46


This page was rendered by LittleSite.
LittleSite is Copyright (c) 2005 by J.Knapka.
Questions and comments to JK