-- |
-- Module      : Harmonic.Interface.Tidal.PolytonalT
-- Description : Live-coding helpers for the polytonal genE family
--
-- Pretty-printers for inspecting a polytonal
-- 'Harmonic.Rules.Types.ProgressionContext.ProgressionContext' at the
-- REPL: every layer view a pattern can select — the three triad layers,
-- each pair, the full pentad, and the pivot tones — printed as the
-- standard progression grids. No semantic behaviour — purely diagnostic
-- output for humans.
--
-- @
-- s \<- seek \"*\" $ len 8 $ entropy 0.3 $ genE
-- genEReport s
-- @

module Harmonic.Interface.Tidal.PolytonalT
  ( polyLayerViews
  , genEReport
  ) where

import qualified Harmonic.Rules.Types.Progression as Prog
import qualified Harmonic.Rules.Types.ProgressionContext as PC

-- |Every layer view of a polytonal context, labelled: single layers,
-- pair unions, the pentad, the pivot tones. Returns 'Nothing' for other
-- families — the labels are genE-specific (partner chains, pentad, pivot
-- dyad). gen\/genJ layer content is printed by
-- 'Harmonic.Interface.Tidal.ChordscaleT.chordscaleReport', genP's by
-- 'Harmonic.Interface.Tidal.OctatripentatonicT.genPReport'.
polyLayerViews :: PC.ProgressionContext -> Maybe [(String, Prog.Progression)]
polyLayerViews :: ProgressionContext -> Maybe [(String, Progression)]
polyLayerViews ProgressionContext
pc
  | ProgressionContext -> Family
PC.pcFamily ProgressionContext
pc Family -> Family -> Bool
forall a. Eq a => a -> a -> Bool
/= Family
PC.FPoly = Maybe [(String, Progression)]
forall a. Maybe a
Nothing
  | Bool
otherwise = [(String, Progression)] -> Maybe [(String, Progression)]
forall a. a -> Maybe a
Just
      [ (String
label, Layer -> ProgressionContext -> Progression
PC.layer Layer
sel ProgressionContext
pc)
      | (String
label, Layer
sel) <-
          [ (String
"T (foundation)",   Layer
PC.T)
          , (String
"S (partner)",      Layer
PC.S)
          , (String
"M (partner)",      Layer
PC.M)
          , (String
"TS",               Layer
PC.TS)
          , (String
"TM",               Layer
PC.TM)
          , (String
"SM",               Layer
PC.SM)
          , (String
"TSM (pentad)",     Layer
PC.TSM)
          , (String
"PT (pivot tones)", Layer
PC.PT)
          ] ]

-- |Live-coding helper: print every layer view of a polytonal context as
-- progression grids. Use at the REPL between takes to see what each
-- pattern-level layer selection will sound.
genEReport :: PC.ProgressionContext -> IO ()
genEReport :: ProgressionContext -> IO ()
genEReport ProgressionContext
pc = case ProgressionContext -> Maybe [(String, Progression)]
polyLayerViews ProgressionContext
pc of
  Maybe [(String, Progression)]
Nothing -> String -> IO ()
putStrLn String
"[not a polytonal context — genEReport applies to genE results]"
  Just [(String, Progression)]
views -> ((String, Progression) -> IO ())
-> [(String, Progression)] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (String, Progression) -> IO ()
forall {a}. Show a => (String, a) -> IO ()
printView [(String, Progression)]
views
  where
    printView :: (String, a) -> IO ()
printView (String
label, a
prog) = do
      String -> IO ()
putStrLn String
""
      String -> IO ()
putStrLn (String
"   " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
label String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
":")
      a -> IO ()
forall a. Show a => a -> IO ()
print a
prog