1:- module(mxml_portray, []).

Provides pretty portrayal of notes and chords

Chords are portrayed as Root Triad [Extensions] [/Bass]. Alterables (ie things that can have sharps and flats) get nice Unicode sharps and flats. */
    8:- use_module(library(listutils), [rep/3]).    9:- use_module(library(mxml_chords), [ ivals_triad_exts/3 ]).   10
   11user:portray(flat(X)) :- sign(flat,S), format('~w~p',[S,X]).
   12user:portray(sharp(X)) :- sign(sharp,S), format('~w~p',[S,X]).
   13user:portray(a(N,A)) :- 
   14   accidentals(A,Chars,Sep), 
   15   (  number(N) 
   16   -> format('~s~w~w', [Chars,Sep,N])
   17   ;  format('~w~s', [N,Chars])
   18   ).
   19
   20user:portray(chord(R,B,Is)) :-
   21   ivals_triad_exts(Is, Triad, Exts),
   22   format('~p ~w', [R,Triad]),
   23   maplist(space_print, Exts),
   24   ( R=B -> true
   25   ; write('/'), print(B)
   26   ).
   27
   28space_print(X) :- format(' ~p',[X]).
   29
   30bip(N,N,sharp) :- N>0.
   31bip(N,M,flat) :- N<0, M is -N.
   32
   33accidentals(0, [], '').
   34accidentals(N, Chars, ' ') :- bip(N,M,S), sign(S,C), rep(M,C,Chars).
   35
   36sign(ascii, sharp, #).
   37sign(ascii, flat, b).
   38sign(uni, sharp, ♯).
   39sign(uni, flat, ♭).
   40sign(uni, natural, ♮).
   41sign(uni, double_flat, 𝄫).
   42sign(uni, double_sharp, 𝄪).
   43sign(uni, crotchet, ♩).
   44sign(uni, quaver, ♪).
   45sign(uni, two_quavers, ♫).
   46sign(uni, two_semiquavers, ♬).
   47
   48sign(Name,Char) :- sign(uni,Name,Char)