Sub BrailleToNeumes()
'
' This Macro takes a file of Byzantine music in Braille (i.e., ASCII code) and converts
' the braille characters for the lyrics into their corresponding Greek characters (using
' the Minion Pro font). Furthermore, it also converts the braille characters for the neumes
' into their corresponding characters of the EZ Psaltica font set and places those neumes above
' the Greek lyrics.
' The alignment of the neumes and lyrics is not perfect enough for the output of this
' macro to be published, but it is good enough so that a sighted chanter could use the output
' of this macro to chant with. Another small flaw is that occasionally a fthora will overlap
' another neume. For these reasons, a sighted person who knows how to use the EZ Psaltica fonts
' should always proofread the output of this macro so that any imperfections can be manually
' adjusted.
' Currently it assumes that the braille lyrics represent Greek characters. It is likely that in
' the near future I will add flexibility to this macro so that it can also convert Braille
' Byzantine music written with lyrics in English.
' In order to work, this macro relies on the following subroutines, which are included in this
' file: KentemataCombos, ShiftMultiGorgons, FixAplesinBraille, and FinalPolishing, and the
' following functions: AddSpace, RemoveSpace, and Switch.
'
' Macro created 5/19/2010 by Papa Ephraim and completed on 8/20/2010
'
Dim text, insertion, previous_char, current_char, change, vowel
Dim previous2_char, previous3_char, extend_count, extend
Dim oligon_flag, petaste_flag, vareia_flag, psefiston_flag
Dim caps_flag, all_caps_flag, wide_neume_flag, new_line_flag
Dim i, j, m, n, x, y, caps, next_char, max_char, next_char2
Dim get_low_martyria, combo_done, end_of_line, gorgon_dot
text = 1 ' This variable is 1 when the current selection is Braille codes that represent lyrics or martyrias
' It is 2 when the current selection is Braille codes that represent the melody.
' It is 3 when the current selection is Braille codes that represent a fthora.
' It is 0 when the current selection is Braille codes that represent numbers.
insertion = True 'The default value of insertion is True, since the loop will insert something
' after mo st Braille characters. But when it doesn't, it sets this to False
extend = False ' This flag variable is True when more than one Braille symbol need be combined
' into a single neume.
oligon_flag = False
petaste_flag = False
vareia_flag = False
psefiston_flag = False
caps_flag = False
all_caps_flag = False
wide_neume_flag = False
gorgon_dot = False
caps = 0
extend_count = 0
get_low_martyria = False
combo_done = False
end_of_line = False
new_line_flag = True
Selection.WholeStory 'these 4 lines create a new document for the output file
Selection.Copy
' Documents.Add DocumentType:=wdNewBlankDocument
' Selection.PasteAndFormat (wdPasteDefault)
Selection.WholeStory
With Selection.font
.Name = "Minion Pro"
.size = 12
.Spacing = 1 ' this helps MS Word recognize zero-width characters
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' The following 17 lines capitalize all letters of the alphabet
'
For x = 97 To 122
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = ChrW(x)
.Replacement.text = ChrW(x - 32)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next x
Selection.EndKey Unit:=wdStory
Selection.TypeText text:=ChrW(990) 'inserts a qoppa at the end of the file as a marker
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine
Selection.TypeText text:=ChrW(992) 'inserts a sampi at the end of the line as a marker
Selection.HomeKey Unit:=wdLine ' moves cursor to the beginning of the line
max_char = 2000 ' The maximum number of characters for this macro to convert is 2000.
' Doing more at a time makes it more time-consuming and prone to error.
For j = 1 To max_char
' --1
current_char = Selection
Selection.MoveRight Unit:=wdCharacter, Count:=1 ' PEEK AHEAD
next_char = Selection
Selection.MoveLeft Unit:=wdCharacter, Count:=1
If extend = True Then ' Beginning of CheckCombos Subroutine
extend_count = extend_count + 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Select Case text
' --10
Case 1 ' When current selection is for martyrias (columns beta, xi, and
'omicron), tempo, and "column alpha" names of notes
' --11
Select Case extend_count
Case 1 ' for extend_count = 1 and text = 1
' --111
' --1110
' PEEK AHEAD
Selection.MoveRight Unit:=wdCharacter, Count:=1
next_char = Selection
If (next_char = "I") Or (next_char = "A") Or (next_char = "U") Or (next_char = ">") Or (next_char = "J") Or (next_char = "E") Then
' --11100
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Else
' --11101
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Select Case previous_char
Case """" ' dot 5 (does this """" work???)
Select Case current_char
Case "D" ' Diatonic martyria for high Di
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m/"
End With
get_low_martyria = True ' This means I still need to get the lower
' part of the diatonic martyria
combo_done = True
Case "G" ' Diatonic martyria for high Ga
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n/"
End With
get_low_martyria = True
combo_done = True
Case "B" ' Diatonic martyria for high Vou
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b/"
End With
get_low_martyria = True
combo_done = True
Case "P" ' Diatonic martyria for high Pa
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v/"
End With
get_low_martyria = True
combo_done = True
Case "N" ' Diatonic martyria for high Nee
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c/"
End With
get_low_martyria = True
combo_done = True
Case "Z" ' Diatonic martyria for high Zo
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="./"
End With
get_low_martyria = True
combo_done = True
End Select ' End of previous_char = """"
Case "_" ' dots 456
Select Case current_char
Case "K" ' Diatonic martyria for Ke
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=","
End With
get_low_martyria = True
combo_done = True
Case "D" ' Diatonic martyria for Di
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m"
End With
get_low_martyria = True
combo_done = True
Case "G" ' Diatonic martyria for Ga
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n"
End With
get_low_martyria = True
combo_done = True
Case "B" ' Diatonic martyria for Vou
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b"
End With
get_low_martyria = True
combo_done = True
Case "P" ' Diatonic martyria for Pa
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v"
End With
get_low_martyria = True
combo_done = True
Case "N" ' Diatonic martyria for Nee
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c"
End With
get_low_martyria = True
combo_done = True
Case "Z" ' Diatonic martyria for Zo
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="."
End With
get_low_martyria = True
combo_done = True
End Select ' End of previous_char = "_"
Case "^" ' dots 45
Select Case current_char
Case "K" ' Diatonic martyria for Low Ke
With Selection
.font.Name = "EZ Special-I"
.TypeText text:=",<"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "D" ' Diatonic martyria for Low Di
With Selection
.font.Name = "EZ Special-I"
.TypeText text:="mM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "8" ' Hard Chromatic martyria for Low Ke
With Selection
.font.Name = "EZ Special-I"
.TypeText text:=","
End With
With Selection
.font.Name = "EZ Psaltica" ' Will this work?
.TypeText text:="M"
.font.Position = 6
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "5" ' Hard Chromatic martyria for Low Di
With Selection
.font.Name = "EZ Special-I"
.TypeText text:="m?"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select ' End of previous_char = "^"
Selection.Delete Unit:=wdCharacter, Count:=1 ' deletes braille last cell of martyria
End Select ' End of text = 1 extend_count = 3 combos
End If ' For next_char check
' --11101x
' Else ' (if previous_char = "X")
' --1111
' End If ' (when previous_char = "X")
Case 2 ' for extend_count = 2 and text = 1
' --112
Select Case previous2_char
Case """" ' dot 5
Select Case previous_char
Case "7" ' soft chromatic
Select Case current_char
Case "D"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m/"
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "B"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b/"
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c/"
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "6" ' soft chromatic
Select Case current_char
Case "G"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "Z"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=".<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "K"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=",<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "D"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "B"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c<?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "8" ' hard chromatic
Select Case current_char
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="vM/"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "Z"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=".M/"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "5" ' hard chromatic
Select Case current_char
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c?/"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
End Select ' for previous_char when previous2_char = """"
Case "_" ' dots 456
Select Case previous_char
Case "#" ' initial martyria for kentemata-oligon
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="y"
End With
combo_done = True
Case "7" 'soft chromatic
Select Case current_char
Case "K"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=","
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "G"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n"
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v"
End With
With Selection
.font.Name = "EZ Fthora"
.font.Position = -2
.TypeText text:="R"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "6" ' soft chromatic
Select Case current_char
Case "D"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "B"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "K"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=",<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "G"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "Z"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=".<?"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "8" ' hard chromatic
Select Case current_char
Case "D"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="mM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "B"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="bM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="cM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "K"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=",M"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "G"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="nM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="vM"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "Z"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=".M"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "5" ' hard chromatic
Select Case current_char
Case "K"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=",?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "G"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="n?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "P"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="v?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "Z"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:=".?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "B"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="b?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "N"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="c?"
End With
combo_done = True
text = 2
wide_neume_flag = False
Case "D"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="m?"
End With
combo_done = True
text = 2
wide_neume_flag = False
End Select
Case "B"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(914) & ChrW(927) & ChrW(933) ' VOU
End With
combo_done = True
text = 2
End Select
End Select ' for previous2_char
Case 3 ' for extend_count = 3 and text = 1
' --113
Select Case previous2_char
Case "D"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(916) & ChrW(921) ' DI
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Case "G"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(915) & ChrW(913) ' GA
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Case "B"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(914) & ChrW(927) & ChrW(933) ' VOU
End With
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
combo_done = True
text = 2
Case "P"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(928) & ChrW(913) ' PA
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Case "N"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(925) & ChrW(919) ' NEE
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Case "Z"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(918) & ChrW(937) ' ZO
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Case "K"
With Selection
.font.Name = "Minion Pro"
.TypeText text:=ChrW(922) & ChrW(917) ' KE
End With
combo_done = True
text = 2
If current_char = "4" Then
Selection.TypeText text:="."
Selection.Delete Unit:=wdCharacter, Count:=1
End If
Selection.TypeText text:=" "
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' The rest of these cases are initial martyrias
Case "9"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="Q" ' chart: Xi-2
End With
combo_done = True
Case "6"
Select Case current_char
Case "P"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="W" ' chart: Xi-3
End With
combo_done = True
Case "&"
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="nB" ' chart: Xi-12
.font.Name = "EZ Special-II"
.TypeText text:="|"
End With
combo_done = True
Case Else
Selection.TypeText text:="Initial Martyria Error - dots 235"
End Select
Case "7"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="pe" ' chart: Xi-4
End With
combo_done = True
Case "8"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="R" ' chart: Xi-5
End With
combo_done = True
Case "0"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="E" ' chart: Xi-9
End With
combo_done = True
Case "5"
Select Case current_char
Case "Z"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="q" ' chart: Xi-7
End With
combo_done = True
Case "O"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="w" ' chart: Xi-8
End With
combo_done = True
Case Else
Selection.TypeText text:="Initial Martyria Error - dots 26"
End Select
Case "4"
With Selection
.font.Name = "EZ Special-II"
.TypeText text:="r" ' chart: Xi-10
End With
combo_done = True
End Select ' End of text = 1 extend_count = 3 combos
End Select ' End of text = 1 combos
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case 2 ' When current selection is for neume combos (text = 2)
' --12
Select Case extend_count
Case 1 ' for extend_count = 1 and text = 2
' --121
' Check if any two-symbol combos match previous_char and current_char
Select Case previous_char
Case "_" ' dots 456
Select Case current_char
Case "W" ' +7
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="7"
End With
wide_neume_flag = True
combo_done = True
Case "T" ' +7 with klasma
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="7z"
End With
wide_neume_flag = True
combo_done = True
Case ")" ' +7 with diple
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="7k"
End With
wide_neume_flag = True
combo_done = True
Case "J" ' +7 with gorgon
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="7x"
End With
wide_neume_flag = True
combo_done = True
Case "?" ' -7
If petaste_flag = True Then
With Selection
.font.Name = "EZ Special-I"
.TypeText text:="R"
End With
Else
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="&"
End With
End If
wide_neume_flag = True
combo_done = True
Case "D" ' -7 with gorgon
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="&S"
End With
wide_neume_flag = True
combo_done = True
Case "V" ' +4 with petaste
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="r"
End With
wide_neume_flag = True
combo_done = True
Case "U" ' +4 with petaste and klasma
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="r" & ChrW(61585)
End With
wide_neume_flag = True
combo_done = True
End Select
Case "@" ' dot 4
Select Case current_char
Case "%" ' sharp with one crossbeam
With Selection
.font.Name = "EZ Fthora"
.TypeText text:="}"
End With
combo_done = True
Case "<" ' flat with one crossbeam
With Selection
.font.Name = "EZ Fthora"
.TypeText text:="{"
End With
combo_done = True
Case "]" ' +3
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="3"
End With
wide_neume_flag = True
combo_done = True
Case "Q" ' +3 with klasma
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="3z"
End With
wide_neume_flag = True
combo_done = True
Case "=" ' +3 with diple
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="3k"
End With
wide_neume_flag = True
combo_done = True
Case "G" ' +3 with gorgon
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="3S"
End With
wide_neume_flag = True
combo_done = True
Case "W" ' +5
With Selection
.font.Name = "EZ Psaltica"
.TypeText text:="5"
End With
wide_neume_flag = True
combo_done = True
Case "T" ' +5 with klasma