Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
PVGrammar
Description
This module contains common datatypes and functions specific to the protovoice grammar. In a protovoice derivations, slices are multisets of notes while transitions contain connections between these notes.
Code that is specific to parsing can be found in PVGrammar.Parse, while generative code is located in PVGrammar.Generate.
Synopsis
- newtype Notes n = Notes (MultiSet n)
- innerNotes :: StartStop (Notes n) -> [StartStop n]
- data Edges n = Edges {}
- topEdges :: Hashable n => Edges n
- type Edge n = (StartStop n, StartStop n)
- type InnerEdge n = (n, n)
- data Freeze = FreezeOp
- data Split n = SplitOp {
- splitReg :: !(Map (Edge n) [(n, DoubleOrnament)])
- splitPass :: !(Map (InnerEdge n) [(n, PassingOrnament)])
- fromLeft :: !(Map n [(n, RightOrnament)])
- fromRight :: !(Map n [(n, LeftOrnament)])
- keepLeft :: !(HashSet (Edge n))
- keepRight :: !(HashSet (Edge n))
- passLeft :: !(MultiSet (InnerEdge n))
- passRight :: !(MultiSet (InnerEdge n))
- data DoubleOrnament
- isRepetitionOnLeft :: DoubleOrnament -> Bool
- isRepetitionOnRight :: DoubleOrnament -> Bool
- data PassingOrnament
- data LeftOrnament
- data RightOrnament
- data Spread n = SpreadOp !(HashMap n SpreadDirection) !(Edges n)
- data SpreadDirection
- type PVLeftmost n = Leftmost (Split n) Freeze (Spread n)
- type PVAnalysis n = Analysis (Split n) Freeze (Spread n) (Edges n) (Notes n)
- analysisTraversePitch :: (Applicative f, Eq n', Hashable n', Ord n') => (n -> f n') -> PVAnalysis n -> f (PVAnalysis n')
- analysisMapPitch :: (Eq n', Hashable n', Ord n') => (n -> n') -> PVAnalysis n -> PVAnalysis n'
- loadAnalysis :: FilePath -> IO (Either String (PVAnalysis SPitch))
- loadAnalysis' :: FilePath -> IO (Either String (PVAnalysis SPC))
- slicesFromFile :: FilePath -> IO [[(SPitch, RightTied)]]
- slicesToPath :: (Interval i, Ord i, Eq i) => [[(Pitch i, RightTied)]] -> Path [Pitch i] [Edge (Pitch i)]
- loadSurface :: FilePath -> IO (Path [Pitch SInterval] [Edge (Pitch SInterval)])
- loadSurface' :: FilePath -> Int -> Int -> IO (Path [Pitch SInterval] [Edge (Pitch SInterval)])
Inner Structure Types
Slices: Notes
The content type of slices in the protovoice model. Contains a multiset of pitches, representing the notes in a slice.
Instances
innerNotes :: StartStop (Notes n) -> [StartStop n] Source #
Return the notes or start/stop symbols inside a slice.
This is useful to get all objects that an Edge
can connect to.
Transitions: Sets of Obligatory Edges
Transitions contain two kinds of edges, regular edges and passing edges.
The content type of transitions in the protovoice model. Contains a multiset of regular edges and a multiset of passing edges. The represented edges are those that are definitely used later on. Edges that are not used are dropped before creating a child transition. A transition that contains passing edges cannot be frozen.
Constructors
Edges | |
Instances
(Eq n, Hashable n, Notation n) => FromJSON (Edges n) Source # | |
(Hashable n, Eq n) => Monoid (Edges n) Source # | |
(Hashable n, Eq n) => Semigroup (Edges n) Source # | |
Generic (Edges n) Source # | |
Notation n => Show (Edges n) Source # | |
NFData n => NFData (Edges n) Source # | |
Eq n => Eq (Edges n) Source # | |
Ord n => Ord (Edges n) Source # | |
Hashable n => Hashable (Edges n) Source # | |
type Rep (Edges n) Source # | |
Defined in PVGrammar type Rep (Edges n) = D1 ('MetaData "Edges" "PVGrammar" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'False) (C1 ('MetaCons "Edges" 'PrefixI 'True) (S1 ('MetaSel ('Just "edgesReg") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashSet (Edge n))) :*: S1 ('MetaSel ('Just "edgesPass") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (MultiSet (InnerEdge n))))) |
type Edge n = (StartStop n, StartStop n) Source #
A proto-voice edge between two nodes (i.e. notes or start/stop symbols).
type InnerEdge n = (n, n) Source #
A proto-voice edge between two notes (excluding start/stop symbols).
Generative Operations
Freeze
Represents a freeze operation. Since this just ties all remaining edges (which must all be repetitions) no decisions have to be encoded.
Constructors
FreezeOp |
Split
Encodes the decisions made in a split operation. Contains a list of elaborations for every parent edge and note. Each elaboration contains the child pitch, and the corresponding ornament. For every produced edge, a decisions is made whether to keep it or not.
Constructors
SplitOp | |
Fields
|
Instances
data DoubleOrnament Source #
Two-sided ornament types (two parents).
Constructors
FullNeighbor | a full neighbor note |
FullRepeat | a repetition of both parents (which have the same pitch) |
LeftRepeatOfRight | a repetition of the right parent |
RightRepeatOfLeft | a repetitions of the left parent |
RootNote | a note inserted at the top of the piece (between ⋊ and ⋉) |
Instances
isRepetitionOnLeft :: DoubleOrnament -> Bool Source #
Returns True
if the child repeats the left parent
isRepetitionOnRight :: DoubleOrnament -> Bool Source #
Returns True
if the child repeats the right parent
data PassingOrnament Source #
Types of passing notes (two parents).
Constructors
PassingMid | a connecting passing note (step to both parents) |
PassingLeft | a step from the left parent |
PassingRight | a step from the right parent |
Instances
data LeftOrnament Source #
Types of single-sided ornaments left of the parent (child-parent
)
[ ] [p] / [c]
Constructors
LeftNeighbor | an incomplete left neighbor |
LeftRepeat | an incomplete left repetition |
Instances
data RightOrnament Source #
Types of single-sided ornaments right of the parent (parent--child
).
[p] [ ] \ [c]
Constructors
RightNeighbor | an incomplete right neighbor |
RightRepeat | an incomplete right repetition |
Instances
Spread
Represents a spread operation.
Records for every pitch how it is distributed (see SpreadDirection
).
The resulting edges (repetitions and passing edges) are represented in a child transition.
Constructors
SpreadOp !(HashMap n SpreadDirection) !(Edges n) |
Instances
(Notation n, Eq n, Hashable n) => FromJSON (Spread n) Source # | |
Generic (Spread n) Source # | |
Notation n => Show (Spread n) Source # | |
NFData n => NFData (Spread n) Source # | |
Eq n => Eq (Spread n) Source # | |
Ord n => Ord (Spread n) Source # | |
Defined in PVGrammar | |
type Rep (Spread n) Source # | |
Defined in PVGrammar type Rep (Spread n) = D1 ('MetaData "Spread" "PVGrammar" "proto-voice-model-0.1.0.0-IpbUkUcWDicKjQK7SlZCoP" 'False) (C1 ('MetaCons "SpreadOp" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HashMap n SpreadDirection)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Edges n)))) |
data SpreadDirection Source #
Encodes the distribution of a pitch in a spread.
All instances of a pitch must be either moved completely to the left or the right (or both).
In addition, some instances may be repeated on the other side.
The difference is indicated by the field of the ToLeft
and ToRight
constructors.
For example, ToLeft 3
indicates that out of n
instances,
all n
are moved to the left and n-3
are replicated on the right.
Constructors
ToLeft !Int | all to the left, n fewer to the right |
ToRight !Int | all to the right, n fewer to the left |
ToBoth | all to both |
Instances
Derivations
type PVLeftmost n = Leftmost (Split n) Freeze (Spread n) Source #
Leftmost
specialized to the split, freeze, and spread operations of the grammar.
type PVAnalysis n = Analysis (Split n) Freeze (Spread n) (Edges n) (Notes n) Source #
An Analysis
specialized to PV types.
analysisTraversePitch :: (Applicative f, Eq n', Hashable n', Ord n') => (n -> f n') -> PVAnalysis n -> f (PVAnalysis n') Source #
Apply an applicative action to all pitches in an analysis.
analysisMapPitch :: (Eq n', Hashable n', Ord n') => (n -> n') -> PVAnalysis n -> PVAnalysis n' Source #
Map a function over all pitches in an analysis.
Loading Files
loadAnalysis :: FilePath -> IO (Either String (PVAnalysis SPitch)) Source #
Loads an analysis from a JSON file (as exported by the annotation tool).
loadAnalysis' :: FilePath -> IO (Either String (PVAnalysis SPC)) Source #
Loads an analysis from a JSON file (as exported by the annotation tool). Converts all pitches to pitch classes.
slicesFromFile :: FilePath -> IO [[(SPitch, RightTied)]] Source #
Loads a MusicXML file and returns a list of salami slices. Each note is expressed as a pitch and a flag that indicates whether the note continues in the next slice.
slicesToPath :: (Interval i, Ord i, Eq i) => [[(Pitch i, RightTied)]] -> Path [Pitch i] [Edge (Pitch i)] Source #
Converts salami slices (as returned by slicesFromFile
) to a path as expected by parsers.