| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Harmonic.Framework.Builder.Types
Description
Data types and configuration for the Builder module. Includes HarmonicContext, GeneratorConfig, ParsedContext, and all diagnostic types.
Synopsis
- data HarmonicContext = HarmonicContext {
- _hcOvertones :: Text
- _hcKey :: Text
- _hcRoots :: Text
- _hcDrift :: Drift
- _hcInversionSpacing :: Int
- _hcPedal :: Text
- _hcTristrata :: Text
- harmonicContext :: Text -> Text -> Text -> HarmonicContext
- hContext :: HarmonicContext
- data Drift
- hcOvertones :: String -> HarmonicContext -> HarmonicContext
- hcKey :: String -> HarmonicContext -> HarmonicContext
- hcRoots :: String -> HarmonicContext -> HarmonicContext
- dissonant :: HarmonicContext -> HarmonicContext
- consonant :: HarmonicContext -> HarmonicContext
- invSkip :: Int -> HarmonicContext -> HarmonicContext
- hcPedal :: String -> HarmonicContext -> HarmonicContext
- hcTristrata :: String -> HarmonicContext -> HarmonicContext
- data GeneratorConfig = GeneratorConfig {}
- defaultConfig :: GeneratorConfig
- data ParsedContext = ParsedContext {
- pcEffectiveOvertones :: !IntSet
- pcAllowedBassNotes :: !IntSet
- pcIsRootsWild :: !Bool
- pcIsKeyWild :: !Bool
- pcIsOvertonesWild :: !Bool
- pcRawOvertones :: ![Int]
- pcBassDirectionSpec :: !(Maybe BassDirectionSpec)
- pcDrift :: !Drift
- pcInversionSpacing :: !Int
- pcPedalRequired :: !IntSet
- pcPedalPreferred :: !IntSet
- pcAllowedTristrata :: ![Tristrata]
- pcSoftBoost :: !Double
- pcStrictContainment :: !Bool
- pcKeySpelling :: !(Maybe EnharmonicSpelling)
- parseContextOnce :: HarmonicContext -> ParsedContext
- keySpellingOf :: Text -> Maybe EnharmonicSpelling
- data BassDirection
- data BassDirectionSpec = BassDirectionSpec {
- bdsKind :: !BDKind
- bdsChoices :: ![Int]
- bdsSelector :: !BDSelector
- bdsOptional :: !Bool
- data BDKind
- data BDSelector
- data Verbosity
- data GenConfig = GenConfig {
- _gcCue :: IO CadenceState
- _gcLen :: Int
- _gcSeek :: String
- _gcEntropy :: Double
- _gcTonal :: HarmonicContext
- _gcVerbosity :: Verbosity
- _gcMode :: GenMode
- _gcLenOverride :: Maybe Int
- _gcRelStrata :: Maybe [Int]
- _gcAbsStrata :: Maybe [StrataLabel]
- _gcBoostSame :: Double
- _gcBoostFlip :: Double
- _gcBoostTri :: Double
- _gcQuad :: Bool
- _gcMaxAttempts :: Int
- _gcViableTarget :: Int
- _gcViabilityFloor :: Double
- data GenMode
- data TransformTrace = TransformTrace {
- ttRawDbIntervals :: String
- ttRawDbMovement :: String
- ttRawDbFunctionality :: String
- ttRootPC :: Int
- ttRootNoteName :: String
- ttTones :: [Int]
- ttTransposedPitches :: [Int]
- ttNormalizedPs :: [Int]
- ttZeroForm :: [Int]
- ttDetectedRoot :: String
- ttFunctionality :: String
- ttFinalChord :: String
- ttStoredFunc :: String
- data AdvanceTrace = AdvanceTrace {}
- data StepDiagnostic = StepDiagnostic {
- sdStepNumber :: Int
- sdPriorCadence :: String
- sdPriorRoot :: String
- sdPriorRootPC :: Int
- sdSelectedDbIntervals :: String
- sdSelectedDbMovement :: String
- sdSelectedDbFunctionality :: String
- sdGraphCount :: Int
- sdGraphTop6 :: [(String, Double)]
- sdFallbackCount :: Int
- sdFallbackTop6 :: [(String, Double, Double, Double, Double)]
- sdPoolSize :: Int
- sdEntropyUsed :: Double
- sdGammaIndex :: Int
- sdSelectedFrom :: String
- sdPosteriorRoot :: String
- sdPosteriorRootPC :: Int
- sdRenderedChord :: Maybe String
- sdTransformTrace :: Maybe TransformTrace
- sdAdvanceTrace :: Maybe AdvanceTrace
- sdTristrataIdx :: Maybe Int
- sdTristrata :: Maybe Tristrata
- sdStrataLabel :: Maybe StrataLabel
- sdMode :: Maybe Mode
- sdStrataChroma :: Maybe [PitchClass]
- sdModeChroma :: Maybe [PitchClass]
- sdSoftBoost :: Maybe Double
- sdHarmonicRootPC :: Maybe Int
- sdParentKey :: Maybe (PitchClass, ScaleFamily)
- sdModeResult :: Maybe ModeResult
- sdBarSpelling :: Maybe EnharmonicSpelling
- sdFusion :: Maybe FusionDiag
- data FusionDiag = FusionDiag {
- fdAddedPC :: Int
- fdFusedName :: String
- fdGammaIdx :: Int
- fdPoolK :: Int
- data GenerationDiagnostics = GenerationDiagnostics {}
- data AttemptDiagnostic = AttemptDiagnostic {}
Harmonic Context (R constraints)
data HarmonicContext Source #
Harmonic context defines the Rules (R) that constrain the generative space.
These filters are applied BEFORE database evaluation (R in R→E→T pipeline), limiting which cadences can even be considered as candidates.
Three-part filtering system: * overtones: Pitch candidate set (e.g., "E A D G" for bass tuning overtones) * key: Key filter applied to candidates (e.g., C, "#", "bb" for key signature) * roots: Root/bass candidate set (e.g., "E F# G" for valid root notes)
Filters use "*" as wildcard (match all). Format matches legacy Overtone.hs notation.
Constructors
| HarmonicContext | |
Fields
| |
Instances
| Show HarmonicContext Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> HarmonicContext -> ShowS # show :: HarmonicContext -> String # showList :: [HarmonicContext] -> ShowS # | |
| Eq HarmonicContext Source # | |
Defined in Harmonic.Framework.Builder.Types Methods (==) :: HarmonicContext -> HarmonicContext -> Bool # (/=) :: HarmonicContext -> HarmonicContext -> Bool # | |
harmonicContext :: Text -> Text -> Text -> HarmonicContext Source #
Constructor for HarmonicContext.
Arguments: * overtones: Pitch set filter ("E A D G", C, "*") * key: Key signature filter (C, "#", "bb", Am, "*") * roots: Root notes filter ("E F# G", "1#", "*")
Example: harmonicContext "*" "*" "*" -- No filtering (all candidates) harmonicContext "E A D G" C "*" -- Bass tuning, C major key harmonicContext "*" "#" "E G" -- G major key, E/G roots only
hContext :: HarmonicContext Source #
Default harmonic context for Tidal live coding: all wildcards (chromatic).
Named hContext to avoid collision with TidalCycles' EventF.context field.
Use modifier functions to constrain the context:
ctx = invSkip 2
$ consonant
$ hcRoots "C E G"
$ hcKey "0#"
$ hcOvertones "E A D G"
$ hContext
Context Modifiers
Direction of dissonance drift across a generated progression.
When applied to a HarmonicContext, the generation engine filters the candidate pool at each step so that only chords with equal or greater (Dissonant) or equal or lesser (Consonant) dissonance than the current chord are preferred. Free imposes no constraint (default).
Advisory, not hard: if the drift predicate would empty the pool at a
step, the filter relaxes and that step proceeds unconstrained rather than
reaching an absorbing state (applyDriftFilter in Builder.Core). Note the
predicate is dissonanceScore — an evaluation function acting as a
filter, the documented E-inside-R leak (see ARCHITECTURE §2).
Instances
hcOvertones :: String -> HarmonicContext -> HarmonicContext Source #
Set overtone filter. Default: "*" (all pitches).
hcOvertones "E A D G" $ hContext — bass tuning overtones
hcKey :: String -> HarmonicContext -> HarmonicContext Source #
Set key filter. Default: "*" (chromatic).
hcKey "0#" $ hContext — C major
hcRoots :: String -> HarmonicContext -> HarmonicContext Source #
Set roots/bass filter. Default: "*" (all roots).
hcRoots "C E G" $ hContext — only C, E, G as bass notes
dissonant :: HarmonicContext -> HarmonicContext Source #
Modify context to trend toward increasing dissonance. Each subsequent chord should have dissonance >= the current chord; advisory — relaxes at any step where it would empty the pool.
consonant :: HarmonicContext -> HarmonicContext Source #
Modify context to trend toward decreasing dissonance. Each subsequent chord should have dissonance <= the current chord; advisory — relaxes at any step where it would empty the pool.
invSkip :: Int -> HarmonicContext -> HarmonicContext Source #
Set minimum number of non-inversion states between inversions.
invSkip 0 allows inversions at any step (default, current behaviour).
invSkip 1 requires at least 1 non-inversion between inversions.
invSkip 2 requires at least 2 non-inversions between inversions.
The starting state counts toward the counter (a non-inversion start
means the first generated step may already be an inversion with invSkip 1).
Advisory, not hard: if excluding inversions would empty the pool at a step, the spacing constraint relaxes for that step rather than halting generation.
hcPedal :: String -> HarmonicContext -> HarmonicContext Source #
Require specific pitch classes to be present in every generated chord.
Tokens are note names (C, G, Bb). A trailing ? marks a tone
as preferred rather than required — it is applied when it does not reduce
the candidate pool below a minimum viable size, and relaxed otherwise.
Advisory at the limit: the relaxation chain is preferred → required →
unfiltered (applyPedalFilter in Builder.Core), so even required tones
are dropped as a last resort at a step where enforcing them would leave no
candidates — generation never reaches an absorbing state through a pedal
constraint.
hcPedal C $ hContext — C must appear in every chord
hcPedal "C G" $ hContext — C and G must both appear
hcPedal "C G?" $ hContext — C required, G preferred
hcTristrata :: String -> HarmonicContext -> HarmonicContext Source #
Restrict the active tristrata pool for genP.
"" (default) — all 12 tristrata allowed.
"5" — lock to a single tristrata (here #5, IV-VI-X).
"1 2 5" — whitelist multiple tristrata.
"[1,2,5]" — bracket form accepted.
Parsed via parseTristrataList; unknown tokens are silently discarded.
Configuration
data GeneratorConfig Source #
Configuration for the progression generator.
gcQuad switches on the gen4 family: after each triad selection, the
step fuses one R-valid palette tone into the chord (4-note output) and
the walk continues from the fused chord's most-consonant embedded triad
(see fuseState).
Historical note: the former gcPoolSize field was removed (2026-08-19)
because no generation path ever read it — the candidate pool is
deliberately unlimited (full 660-candidate fallback; see
Core).
Constructors
| GeneratorConfig | |
Instances
| Show GeneratorConfig Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> GeneratorConfig -> ShowS # show :: GeneratorConfig -> String # showList :: [GeneratorConfig] -> ShowS # | |
| Eq GeneratorConfig Source # | |
Defined in Harmonic.Framework.Builder.Types Methods (==) :: GeneratorConfig -> GeneratorConfig -> Bool # (/=) :: GeneratorConfig -> GeneratorConfig -> Bool # | |
defaultConfig :: GeneratorConfig Source #
Default configuration.
Pre-parsed Context
data ParsedContext Source #
Pre-parsed HarmonicContext for O(1) membership tests. Computed once per generation run, avoiding repeated text parsing.
Constructors
| ParsedContext | |
Fields
| |
parseContextOnce :: HarmonicContext -> ParsedContext Source #
Parse a HarmonicContext once into efficient lookup structures.
keySpellingOf :: Text -> Maybe EnharmonicSpelling Source #
Enharmonic side implied by a key-signature string. A key filter may carry several tokens (their pitch sets union into the candidate pool), so the side is a per-token vote: every token flat-side -> flat, every token sharp-side -> sharp, mixed or indeterminate -> neutral (spelling falls back to content inference and continuity). Count forms carry their side directly ("2b" flat, "3#" sharp; zero-accidental forms are neutral); note-name forms follow the circle of fifths (F and every flat name -> flat; G, D, A, E, B and every sharp name -> sharp; C is ambiguous -> neutral). Removal tokens ("-G") shape the pool, not the spelling, and do not vote. Wildcards are neutral.
Bass Direction (re-exported from Filter)
data BassDirection Source #
Concrete direction action resolved for a single generation step. When active, the bass/root at the next step is forced to the Nth note above (Rise) or below (Fall) in the allowed set, with mod-12 wrapping. Step size 1 = closest note, 2 = skip one, etc.
Instances
| Show BassDirection Source # | |
Defined in Harmonic.Rules.Constraints.Filter Methods showsPrec :: Int -> BassDirection -> ShowS # show :: BassDirection -> String # showList :: [BassDirection] -> ShowS # | |
| Eq BassDirection Source # | |
Defined in Harmonic.Rules.Constraints.Filter Methods (==) :: BassDirection -> BassDirection -> Bool # (/=) :: BassDirection -> BassDirection -> Bool # | |
data BassDirectionSpec Source #
Parsed specification for a rise/fall direction token. Resolved per step
at generation time to a concrete BassDirection (or Nothing when the
optional ? flag causes the direction to be skipped for that step).
Constructors
| BassDirectionSpec | |
Fields
| |
Instances
| Show BassDirectionSpec Source # | |
Defined in Harmonic.Rules.Constraints.Filter Methods showsPrec :: Int -> BassDirectionSpec -> ShowS # show :: BassDirectionSpec -> String # showList :: [BassDirectionSpec] -> ShowS # | |
| Eq BassDirectionSpec Source # | |
Defined in Harmonic.Rules.Constraints.Filter Methods (==) :: BassDirectionSpec -> BassDirectionSpec -> Bool # (/=) :: BassDirectionSpec -> BassDirectionSpec -> Bool # | |
data BDSelector Source #
How to pick a step size from bdsChoices at each generation step.
Constructors
| BDFixed | single value (bare |
| BDRotate | cycle choices by step index (space-delimited |
| BDRandomPick | uniform random per step (comma-delimited |
Instances
| Show BDSelector Source # | |
Defined in Harmonic.Rules.Constraints.Filter Methods showsPrec :: Int -> BDSelector -> ShowS # show :: BDSelector -> String # showList :: [BDSelector] -> ShowS # | |
| Eq BDSelector Source # | |
Defined in Harmonic.Rules.Constraints.Filter | |
Generation Configuration (Modifier-Based API)
Configuration for the modifier-based generation API.
Built via modifier chains:
s <- seek "*" $ cue start $ tonal ctx $ len 4 $ entropy 0.3 $ gen
Constructors
| GenConfig | |
Fields
| |
Generation mode.
Constructors
| Fresh | Standard gen (new progression) |
| FromProg Progression !Int !Int | Regenerate range in existing triad layer |
| FromProgPC ProgressionContext !Int !Int | Regenerate range in a strata-aware context (preserves all three layers + provenance) |
| GridMode | Static repetition of cue chord |
| StrataMode StrataLabel |
|
Diagnostics Types
data TransformTrace Source #
Transform trace captures intermediate values in fromCadenceState → toTriad pipeline. Used for maximum verbosity debugging (gen''). Includes raw DB data plus all transformation stages.
Constructors
| TransformTrace | |
Fields
| |
Instances
| Show TransformTrace Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> TransformTrace -> ShowS # show :: TransformTrace -> String # showList :: [TransformTrace] -> ShowS # | |
| Eq TransformTrace Source # | |
Defined in Harmonic.Framework.Builder.Types Methods (==) :: TransformTrace -> TransformTrace -> Bool # (/=) :: TransformTrace -> TransformTrace -> Bool # | |
data AdvanceTrace Source #
Advance trace captures intermediate values in root advancement. Used for maximum verbosity debugging (gen'').
Constructors
| AdvanceTrace | |
Fields
| |
Instances
| Show AdvanceTrace Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> AdvanceTrace -> ShowS # show :: AdvanceTrace -> String # showList :: [AdvanceTrace] -> ShowS # | |
| Eq AdvanceTrace Source # | |
Defined in Harmonic.Framework.Builder.Types | |
data StepDiagnostic Source #
Diagnostic information for a single generation step
Constructors
| StepDiagnostic | |
Fields
| |
Instances
| Show StepDiagnostic Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> StepDiagnostic -> ShowS # show :: StepDiagnostic -> String # showList :: [StepDiagnostic] -> ShowS # | |
| Eq StepDiagnostic Source # | |
Defined in Harmonic.Framework.Builder.Types Methods (==) :: StepDiagnostic -> StepDiagnostic -> Bool # (/=) :: StepDiagnostic -> StepDiagnostic -> Bool # | |
data FusionDiag Source #
Diagnostic record for one gen4 fusion (the added-tone draw that turns the selected triad into a 4-note chord).
Constructors
| FusionDiag | |
Fields
| |
Instances
| Show FusionDiag Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> FusionDiag -> ShowS # show :: FusionDiag -> String # showList :: [FusionDiag] -> ShowS # | |
| Eq FusionDiag Source # | |
Defined in Harmonic.Framework.Builder.Types | |
data GenerationDiagnostics Source #
Complete diagnostics for a generation run
Constructors
| GenerationDiagnostics | |
Fields
| |
Instances
| Show GenerationDiagnostics Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> GenerationDiagnostics -> ShowS # show :: GenerationDiagnostics -> String # showList :: [GenerationDiagnostics] -> ShowS # | |
data AttemptDiagnostic Source #
Per-attempt diagnostic record for the multi-attempt rank-and-select
(generateBest) loop. Captured once per attempt and surfaced at
Verbose via printAttemptScoreboard. At Silent / Standard the
list is discarded after the winner is picked.
Constructors
| AttemptDiagnostic | |
Fields
| |
Instances
| Show AttemptDiagnostic Source # | |
Defined in Harmonic.Framework.Builder.Types Methods showsPrec :: Int -> AttemptDiagnostic -> ShowS # show :: AttemptDiagnostic -> String # showList :: [AttemptDiagnostic] -> ShowS # | |
| Eq AttemptDiagnostic Source # | |
Defined in Harmonic.Framework.Builder.Types Methods (==) :: AttemptDiagnostic -> AttemptDiagnostic -> Bool # (/=) :: AttemptDiagnostic -> AttemptDiagnostic -> Bool # | |