예제 #1
0
        private void ProcessFile()
        {
            bool PreviousStaffLayered = false;
            btnGo.Enabled = false;
            Cursor OldCursor = this.Cursor;
            this.Cursor = Cursors.WaitCursor;
            SetSlurComplex = false;
            try
            {
                Encoding isoIn = Encoding.GetEncoding("UTF-8");
                NWCTextFile = new StreamReader(txtFile.Text.ToString(), isoIn);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to read file " + txtFile.Text.ToString(), "NWC2LY");
                return;
            }
            FileInfo Info = new FileInfo(txtFile.Text.ToString());
            string Line, CopyLine;
            string Command;
            string StaffName = "";
            string Headers = "";
            CurrentDir = Info.DirectoryName + "\\";
            char LyricName = 'A';

            StaffNames.Clear();

            string LilyPondFileName = txtFile.Text.ToString();
            LilyPondFileName = LilyPondFileName.Replace(Info.Extension, ".ly");

            while (NWCTextFile.Peek() >= 0)
            {
                Line = NWCTextFile.ReadLine();
                InputLines.Add(Line);
                if (Line.IndexOf("setSlurComplex") > -1)
                {
                    SetSlurComplex = true;
                }
            }
            while (InputLines.Count > 0)
            {
                Line = CopyLine = InputLines[0];
                InputLines.RemoveAt(0);
                Command = nwc2ly.nwc2ly.GetCommand(ref Line);
                switch (Command)
                {
                    case "Version":
                        {
                            ThisVersion = Convert.ToDouble(Line);
                            if (ThisVersion > 2.7)
                            {
                                // Get rid of backslashes escaped with following closing bracket
                                for (int ThisLine = 0; ThisLine < InputLines.Count; ThisLine++)
                                {
                                    if (InputLines[ThisLine].IndexOf("|Text|Text:") == 0)
                                    {
                                        int EscPos = InputLines[ThisLine].IndexOf("\\]");
                                        while (EscPos > -1)
                                        {
                                            InputLines[ThisLine] = InputLines[ThisLine].Substring(0, EscPos + 1) + InputLines[ThisLine].Substring(EscPos + 2);
                                            EscPos = InputLines[ThisLine].IndexOf("\\]");
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    case "SongInfo":
                        {
                            Headers = DoHeaders(Line);
                            break;
                        }
                    case "PgSetup":
                        {
                            break;
                        }
                    case "Font":
                        {
                            break;
                        }
                    case "PgMargins":
                        {
                            break;
                        }
                    case "AddStaff":
                        {
                            StaffName = nwc2ly.nwc2ly.GetPar("Name", Line);
                            if (StaffName == "")
                            {
                                // Do something here to create a name
                            }
                            StaffInfo Staff = new StaffInfo();
                            Staff.Name = StaffName; // This is used for creating solo parts
                            Staff.StaffName = StaffName;
                            StaffName = StaffName.Replace("\"", "");
                            StaffName = StaffName.Replace(" ", "");
                            StaffName = StaffName.Replace("/", "");
                            StaffName = StaffName.Replace("\\", "");
                            Staff.Name = StaffName;
                            Staff.StaffName = Staff.StaffName.Replace("\"", "");
                            Staff.Label = nwc2ly.nwc2ly.GetPar("Label", Line);
                            Staff.Label = Staff.Label.Replace("\"", "");
                            Staff.Abbrev = nwc2ly.nwc2ly.GetPar("LabelAbbr", Line);
                            Staff.Abbrev = Staff.Abbrev.Replace("\"", "");
                            Staff.FileName = txtName.Text + StaffName;
                            if (nwc2ly.nwc2ly.GetPar("Group", Line).IndexOf("Instrument") > -1)
                            {
                                Staff.isInst = true;
                            }
                            StaffNames.Add(Staff);
                            break;
                        }
                    case "StaffProperties":
                        {
                            string Layer = "";
                            string StaffLabel = StaffNames[StaffNames.Count - 1].Name.ToLower();

                            StaffType Style = StaffType.None;
                            if (Line.IndexOf("|EndingBar:") > -1) // Ugh.  Have to do this since there are 2 StaffProperties lines, and WithNextStaff
                            // is only ever on one of them, but not always...
                            {
                                string NextStaffVal = "";
                                if (ThisVersion < 2.5)
                                {
                                    Layer = nwc2ly.nwc2ly.GetPar("Layer", Line);
                                }
                                else
                                {
                                    NextStaffVal = nwc2ly.nwc2ly.GetPar("WithNextStaff", Line, true);
                                    if (NextStaffVal.Length > 0)
                                    {
                                        if (NextStaffVal.IndexOf("Layer") > -1)
                                        {
                                            Layer = "Y";
                                        }
                                    }
                                }
                                if (StaffLabel.ToLower().IndexOf("solo") > -1)
                                {
                                    StaffNames[StaffNames.Count - 1].Type = StaffType.Solo;
                                }
                                else
                                {

                                    if (ThisVersion < 2.5)
                                    {
                                        string StaffStyle = nwc2ly.nwc2ly.GetPar("Style", Line);
                                        switch (StaffStyle)
                                        {
                                            case "Standard":
                                                Style = StaffType.Standard;
                                                break;
                                            case "Upper Grand Staff":
                                                Style = StaffType.UpperGrandStaff;
                                                break;
                                            case "Lower Grand Staff":
                                                Style = StaffType.LowerGrandStaff;
                                                break;
                                            case "Orchestral":
                                                Style = StaffType.Orchestral;
                                                break;
                                        }
                                    }
                                    else
                                    {
                                        Style = StaffType.NoBracketNext;
                                        NextStaffVal = nwc2ly.nwc2ly.GetPar("WithNextStaff", Line, true);
                                        if (NextStaffVal.Length > 0)
                                        {
                                            if (NextStaffVal.IndexOf("Brace") > -1)  // At present, this means we can't have GrandStaff _and_ bracket
                                            {
                                                Style = StaffType.GrandStaffNext;
                                            }
                                            if (NextStaffVal.IndexOf("Bracket") > -1)
                                            {
                                                if (NextStaffVal.IndexOf("ConnectBars") > -1)
                                                {
                                                    Style = StaffType.OrchestralNext;
                                                }
                                                else
                                                {
                                                    Style = StaffType.BracketNext;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (Style != StaffType.None)
                            {
                                StaffNames[StaffNames.Count - 1].Type = Style;
                            }

                            if (Layer != "")
                            {
                                StaffNames[StaffNames.Count - 1].Layer = Layer; // i.e. set _this_ SN.Layer property
                            }

                            if (StaffNames.Count > 1)
                            {
                                if (StaffNames[StaffNames.Count - 2].Layer == "Y")
                                {
                                    StaffNames[StaffNames.Count - 1].StaffName = StaffNames[StaffNames.Count - 2].StaffName;
                                    PreviousStaffLayered = true;
                                }
                                else
                                {
                                    PreviousStaffLayered = false;
                                }
                            }

                            if (Line.IndexOf("Visible:N") > -1)
                            {
                                StaffNames[StaffNames.Count - 1].Visible = false;
                            }
                            if (Line.IndexOf("EndingBar:Master Repeat Close") > -1)
                            {
                                StaffNames[StaffNames.Count - 1].MasterRepeatClose = true;
                            }
                            break;
                        }
                    case "StaffInstrument":
                        {
                            break;
                        }
                    case "Lyrics":
                        {
                            if (Line.IndexOf("Placement:Top") >= 0)
                            {
                                StaffNames[StaffNames.Count - 1].bLyricsTop = true;
                            }
                            if (StaffNames[StaffNames.Count - 1].Visible)
                            {
                                GetLyrics(ref LyricName);
                            }
                            break;
                        }
                    case "Clef":
                        {
                            NWCStaffFile = new StreamWriter(CurrentDir + txtName.Text + StaffName + ".nwcextract");
                            GetNoteInfo(CopyLine);
                            NWCStaffFile.Close();
                            string DynamicDir = GetDynDir(StaffNames.Count - 1);
                            string[] args = { CurrentDir + txtName.Text + StaffName + ".nwcextract", CurrentDir + txtName.Text + StaffName + ".ly", DynamicDir, radAcc.Checked.ToString(), PreviousStaffLayered.ToString(), chkAutobeam.Checked.ToString(), udDynSpace.Value.ToString(), chkSkipLyr.Checked.ToString() };
                            nwc2ly.nwc2ly.Main(args);
                            break;
                        }
                }
            }

            // The bits below are the ossia lyric processing code
            // Start by looping over all the staves.
            for (int i = 0; i < StaffNames.Count; i++)
            {
                StreamReader Staff = null;
                try
                {
                    Staff = new StreamReader(CurrentDir + StaffNames[i].FileName + ".ly");
                }
                catch (Exception eEx)
                {
                    MessageBox.Show(eEx.Message + "\nPerhaps you have an empty stave?", "NWCTXT2ly error");
                    break;
                }
                string InputLine = Staff.ReadLine();
                // The nwctxt processor marks staves with an ossiaStave command with %OssiaStave as the first text
                if (InputLine.IndexOf("%OssiaStave") == 0)
                {
                    StaffNames[i].Type = StaffType.Ossia;
                    // It places the ossia names with spaces between, so we can use split.
                    string[] OssiaMusic = InputLine.Split(' ');
                    for (int j = 1; j < OssiaMusic.Length; j++)
                    {
                        // Store the ossia names provided by this staff.
                        StaffNames[i].OssiaMusic.Add(OssiaMusic[j]);
                    }
                }
                if (InputLine.IndexOf("%OssiaInclude") == 0)
                {
                    // These staves have ossia music included in them
                    StaffNames[i].OssiaInclude = true;
                    while (InputLine.IndexOf("%OssiaInclude") == 0)
                    {
                        // The included ossia music is listed at the top of the file, one per line
                        StaffNames[i].OssiaMusic.Add(InputLine.Substring(14));  // Store the name, less %OssiaInclude
                        InputLine = Staff.ReadLine();
                    }
                }
                Staff.Close();
            }
            // OK, now we've found them all, let's process them
            for (int i = 0; i < StaffNames.Count; i++)  // Just doing this separate from the loop above for easier reading
            {
                if (StaffNames[i].MasterRepeatClose == true)
                {
                    StreamReader InputFile = new StreamReader(CurrentDir + StaffNames[i].FileName + ".ly");
                    // Get the contents of the file which includes the ossia
                    string FileContents = InputFile.ReadToEnd();
                    InputFile.Close();
                    FileContents=FileContents.Replace("|.", ":|.");
                    StreamWriter FileOutput = new StreamWriter(CurrentDir + StaffNames[i].FileName + ".ly");
                    FileOutput.Write(FileContents);
                    FileOutput.Flush();
                    FileOutput.Close();
                }
            }
            for (int i = 0; i < StaffNames.Count; i++)  // Just doing this separate from the loop above for easier reading
            {
                if (StaffNames[i].OssiaInclude)
                {
                    // i.e. this staff has ossia music included in it
                    List<OssiaMusicInfo> OssiaInfo = new List<OssiaMusicInfo>();
                    int OssiaPieces = 0;
                    for (int j = 0; j < StaffNames[i].OssiaMusic.Count; j++)
                    {
                        // Looping over all the included ossia parts by name
                        string OssiaMusic = StaffNames[i].OssiaMusic[j];
                        string [] OssiaMusicSplit;
                        // if (OssiaMusic.IndexOf(" Staff ") > -1)
                        {
                            OssiaMusicSplit = OssiaMusic.Split(' '); ;
                            OssiaPieces++;
                        }
                        for (int k = 0; k < StaffNames.Count; k++)  // Look for the stave(s) that contain the actual ossia music
                        {
                            if (StaffNames[k].Type == StaffType.Ossia)  // Ignore non-ossia staves
                            {
                                for (int l = 0; l < StaffNames[k].OssiaMusic.Count; l++)  // Loop over all the ossia names
                                {
                                    string OssiaInclude = StaffNames[k].OssiaMusic[l];
                                    if (OssiaMusicSplit[0] == OssiaInclude)
                                    {
                                        // Found the staff with the included ossia music
                                        OssiaMusicInfo ThisOssiaDetails = new OssiaMusicInfo();
                                        ThisOssiaDetails.StaffName = StaffNames[k].Name;
                                        ThisOssiaDetails.StaffNum = k;
                                        ThisOssiaDetails.Layer = (StaffNames[k].Layer == "Y");
                                        ThisOssiaDetails.OssiaMusicName = OssiaMusicSplit[0];
                                        ThisOssiaDetails.OssiaPiece = OssiaPieces;
                                        OssiaInfo.Add(ThisOssiaDetails);
                                    }
                                }
                            }
                        }
                    }
                    Console.WriteLine(""); // Process the OssiaMusicIncludes here
                    for (int j = 0; j < OssiaInfo.Count; j++)
                    {
                        int OssiaPiece = OssiaInfo[j].OssiaPiece;
                        int LastBottom = -1;
                        int LayerCount = 0;
                        // Check if there are other simultaneous pieces
                        for (int k = 0; k < OssiaInfo.Count; k++)
                        {
                            if (j != k)
                            {
                                if (OssiaInfo[k].OssiaPiece == OssiaPiece)
                                {
                                    // Yes, there are - so check whether they're layered
                                    if (OssiaInfo[j].Layer)
                                    {
                                        // Layered - but need to check whether the next stave is the one below
                                        if (OssiaInfo[k].StaffNum - OssiaInfo[j].StaffNum == LayerCount + 1)
                                        {
                                            // Yes - so these are 2 voices on a single stave - but there could still be more
                                            LayerCount++;
                                            OssiaInfo[Math.Min(j, k)].TopOfLayer = true;
                                            OssiaInfo[Math.Min(j, k)].BottomOfLayer = false;
                                            OssiaInfo[Math.Max(j, k)].BottomOfLayer = true;
                                            OssiaInfo[Math.Max(j, k)].TopOfLayer = false;
                                            if (LayerCount > 1)
                                            {
                                                OssiaInfo[LastBottom].BottomOfLayer = false;
                                            }
                                            LastBottom = Math.Max(j, k);
                                        }
                                    }
                                }
                            }
                        }
                        j += LayerCount;
                    }
                    // OK - so now we have identified which ossias start staves and which finish them.  Loop and write
                    StreamReader OssiaFile = new StreamReader(CurrentDir + StaffNames[i].FileName + ".ly");
                    // Get the contents of the file which includes the ossia
                    string FileContents = OssiaFile.ReadToEnd();
                    OssiaFile.Close();

                    string OssiaStaff = "";
                    for (int j = 0; j < OssiaInfo.Count; j++)
                    {
                        string MusicDetails = "";
                        if (OssiaInfo[j].TopOfLayer)
                        {
                            MusicDetails += " \\new Staff = \"" + OssiaInfo[j].OssiaMusicName + "OssiaStaff\" \\with {\r\n";
                            MusicDetails += "   \\remove \"Time_signature_engraver\"\r\n";
                            //MusicDetails += "   alignAboveContext = #\"" + StaffNames[i].Name + "Dyn\"\r\n";
                            if (chkSpacer.Checked)
                            {
                                MusicDetails += "   alignAboveContext = #\"" + StaffNames[i].OssiaMusic[j].Split(' ')[1] + "\"\r\n";
                            }
                            else
                            {
                                MusicDetails += "   alignAboveContext = #\"" + StaffNames[i].OssiaMusic[j].Split(' ')[1] + "Dyn\"\r\n";
                            }
                            MusicDetails += "   \\override StaffSymbol #'staff-space = #(magstep -3) % Sets the staff line spacing\r\n";
                            MusicDetails += "   fontSize = #-2\r\n";
                            MusicDetails += " } \r\n";
                            MusicDetails += " << \r\n";
                            OssiaStaff = OssiaInfo[j].OssiaMusicName;
                        }
                        MusicDetails += "\\new Voice = \"" + OssiaInfo[j].OssiaMusicName + "Ossia\" { \r\n";
                        if (!chkAutobeam.Checked)
                        {
                            MusicDetails += "   \\autoBeamOff\r\n";
                        }
                        MusicDetails += "   \\" + OssiaInfo[j].OssiaMusicName + "\r\n";
                        MusicDetails += " } \r\n";

                        if (OssiaInfo[j].BottomOfLayer)
                        {
                            MusicDetails += ">>\r\n";
                        }

                        // Replace the marker with the music string
                        FileContents = FileContents.Replace("%" + OssiaInfo[j].OssiaMusicName + "Music", MusicDetails);

                        // Process the lyrics
                        string LyricString = "";
                        // Loop over all the lyric lines in this included music, in reverse order (lily requires this)
                        for (int m = StaffNames[OssiaInfo[j].StaffNum].LyricLines - 1; m >= 0; m--)
                        {
                            LyricString += "\\new Lyrics \\with { \r\n  alignBelowContext = \"";
                            LyricString += OssiaStaff + "OssiaStaff";
                            LyricString += "\"\r\n  \\override VerticalAxisGroup.nonstaff-nonstaff-spacing = #'((basic-distance . 2))\r\n}";
                            LyricString += "\\lyricsto \"" + OssiaInfo[j].OssiaMusicName + "Ossia\" { \\teeny ";
                            StreamReader OssiaLyricsFile = new StreamReader(CurrentDir + StaffNames[OssiaInfo[j].StaffNum].LyricFileNames[m]);
                            string OssiaLyrics = OssiaLyricsFile.ReadToEnd();
                            OssiaLyricsFile.Close();
                            Regex FindOssiaLyrics = new Regex("(<oss\\(" + OssiaInfo[j].OssiaMusicName + "\\)>)([-_\\'\\,\\.\\;\\:\\!\\)\\?\\w\\s\\\"#={}\\\\]+)(</oss>)([\\\"]?)", RegexOptions.Multiline);
                            Match LyricMatch = FindOssiaLyrics.Match(OssiaLyrics);
                            string ThisLyric = "";
                            if (LyricMatch.Success)
                            {
                                ThisLyric = LyricMatch.Result("$2" + "$4");
                            }
                            LyricString += ThisLyric;
                            LyricString += " }\r\n";
                        }
                        // Replace the marker with the lyric string
                        FileContents = FileContents.Replace("%" + OssiaInfo[j].OssiaMusicName + "Lyrics", LyricString);
                    }

                    // And write it out again
                    StreamWriter OssiaFileOutput = new StreamWriter(CurrentDir + StaffNames[i].FileName + ".ly");
                    OssiaFileOutput.Write(FileContents);
                    OssiaFileOutput.Flush();
                    OssiaFileOutput.Close();
                }
            }
            // End of ossia code

            if (chkSkipLyr.Checked)
            {
                for (int i = 0; i < StaffNames.Count; i++)
                {
                    DoLyricSkips(StaffNames[i]);
                }
            }

            LilyPondFile = new StreamWriter(LilyPondFileName, false);
            string ver = Application.ProductVersion;
            LilyPondFile.WriteLine("% Generated by NWCTXT2Ly C# version " + ver + " by Phil Holmes");
            LilyPondFile.WriteLine("% Based on nwc2ly by Mike Wiering");
            LilyPondFile.WriteLine();
            LilyPondFile.WriteLine("\\version \"2.19.16\"");
            if (SetSlurComplex)
            {
                LilyPondFile.WriteLine(Resource1.SetSlurCode.ToString());
                LilyPondFile.WriteLine();
            }
            LilyPondFile.WriteLine("\\pointAndClickOff");
            LilyPondFile.WriteLine("#(set-global-staff-size " + udFontSize.Value.ToString() + ")");
            LilyPondFile.WriteLine("");

            LilyPondFile.WriteLine(Headers);

            LilyPondFile.WriteLine("\\paper{");
            LilyPondFile.WriteLine("  top-margin = " + udTopMargin.Value.ToString());
            LilyPondFile.WriteLine("  bottom-margin = " + udBottomMargin.Value.ToString());
            LilyPondFile.WriteLine("  left-margin = " + udLeftMargin.Value.ToString());
            LilyPondFile.WriteLine("  line-width = " + udLineWidth.Value.ToString());
            if (chkLast.Checked)
            {
                LilyPondFile.WriteLine("  ragged-last-bottom = ##f");
            }
            LilyPondFile.WriteLine("}");
            LilyPondFile.WriteLine("");

            for (int i = 0; i < StaffNames.Count; i++)
            {
                if (StaffNames[i].Type == StaffType.Ossia)
                {
                    LilyPondFile.WriteLine("\\include \"" + StaffNames[i].FileName + ".ly\"");

                }
            }

            if (chkPiano.Checked)
            {
                LilyPondFile.WriteLine("\\layout {");
                LilyPondFile.WriteLine("  \\context {");
                LilyPondFile.WriteLine("    \\PianoStaff \\remove \"Keep_alive_together_engraver\" ");
                LilyPondFile.WriteLine("  }");
                LilyPondFile.WriteLine("}");
            }
            if (chkRemove.Checked)
            {
                LilyPondFile.WriteLine("\\layout {");
                LilyPondFile.WriteLine("  \\context {");
                LilyPondFile.WriteLine("    \\Staff \\RemoveEmptyStaves");
                if (chkFirstStave.Checked)
                {
                    LilyPondFile.WriteLine("    \\override VerticalAxisGroup #'remove-first = ##t");
                }
                LilyPondFile.WriteLine("  }");
                LilyPondFile.WriteLine("}");
            }

            LilyPondFile.WriteLine("\\new Score \\with {");
            if (chkForcePage.Checked)
            {
                LilyPondFile.WriteLine("  \\override NonMusicalPaperColumn #'page-break-permission = ##f");
            }
            LilyPondFile.WriteLine("  \\override PaperColumn #'keep-inside-line = ##t");
            LilyPondFile.WriteLine("  \\override NonMusicalPaperColumn #'keep-inside-line = ##t");

            LilyPondFile.WriteLine("}");
            LilyPondFile.WriteLine("{");

            if (chkCompress.Checked)
            {
                LilyPondFile.WriteLine("  \\compressFullBarRests");
                LilyPondFile.WriteLine("  \\override Score.MultiMeasureRest #'expand-limit = #1");
            }

            LilyPondFile.WriteLine("  <<");

            WriteVoices();

            LilyPondFile.WriteLine("  >> % Music end");

            LilyPondFile.WriteLine("}");
            LilyPondFile.Close();
            NWCTextFile.Close();
            this.Cursor = OldCursor;
            btnGo.Enabled = true;
        }
예제 #2
0
        private void WriteVoices()
        {
            string Layer;
            bool Layering = false;
            char Name1 = 'A', Name2 = 'A';
            char LyricName = 'A';
            string[] VoiceNames = { "\\voiceOne", "\\voiceTwo", "\\voiceThree", "\\voiceFour" };
            int VoiceNumber = 0;
            int Staves = 0;
            StaffType StaveTypeAbove = StaffType.None;
            StaffType NewStaveType;
            string ThisVoiceName;
            string FontSize = "";
            string FurnitureSize = "";
            bool PianoStaff=false;
            int StavesWritten = 0;
            int NonOssiaStaves = 0;
            StaffInfo ThisStave = new StaffInfo();
            string DynamicAlign;
            bool PianoDynamicsWritten = false;
            string WithMark = "";

            for (int i = 0; i < StaffNames.Count; i++)
            {
                if (StaffNames[i].Type != StaffType.Ossia)
                {
                    if (StaffNames[i].Visible)
                    {
                        if (StaffNames[i].Layer == "N")
                        {
                            NonOssiaStaves++;
                        }
                    }
                }
            }
            for (int i = 0; i < StaffNames.Count; i++)
            {
                Console.WriteLine(StaffNames[i].Name + ", " + StaffNames[i].Type + ", " + StaffNames[i].Layer);
            }

            if (ThisVersion > 2.4)
            {
                for (int i = 0; i < StaffNames.Count; i++)
                {
                    if (i == 0 && StaffNames[i].Type == StaffType.NoBracketNext)
                    {
                        StaffNames[i].Type = StaffType.Solo;
                    }
                    else if (StaffNames[i].Type == StaffType.NoBracketNext && StaffNames[i - 1].Type == StaffType.NoBracketNext)
                    {
                        StaffNames[i].Type = StaffType.Solo;
                    }
                }
            }

            Console.WriteLine("After \"fixing\" the staff types");
            for (int i = 0; i < StaffNames.Count; i++)
            {
                Console.WriteLine(StaffNames[i].Name + ", " + StaffNames[i].Type + ", " + StaffNames[i].Layer);
            }

            bool InGrandStaff = false;
            for (int i = 0; i < StaffNames.Count; i++)
            {
                PianoStaff = false;
                if (StaffNames[i].Visible && StaffNames[i].Type != StaffType.Ossia)
                {
                    NewStaveType = StaffNames[i].Type;

                    WithMark = "";
                    if (StaffNames[i].addMark)
                    {
                        WithMark = " \\with { \\consists Mark_engraver } ";
                    }
                    FontSize = "";
                    FurnitureSize = "";
                    if (NewStaveType == StaffType.Solo && chkSmall.Checked == true)
                    {
                        FontSize = " \\tiny ";
                        FurnitureSize = @" \with { \override KeySignature #'font-size = #-2 \override TimeSignature #'font-size = #-2 \override StaffSymbol #'staff-space = #0.8 \override Clef #'font-size = #-2 } ";
                    }
                    if (NewStaveType == StaffType.UpperGrandStaff || NewStaveType == StaffType.LowerGrandStaff) PianoStaff = true; // Pre 2.5
                    if (NewStaveType == StaffType.GrandStaffNext) // 2.5 and later
                    {
                        PianoStaff = true;
                        InGrandStaff = true;
                    }
                    else if (NewStaveType != StaffType.NoBracketNext && InGrandStaff)
                    {
                        InGrandStaff = false;
                    }
                    if (StaveTypeAbove != NewStaveType  || StaveTypeAbove == StaffType.None) // i.e. we have to change the type of bracket we're using
                    {
                        if (StaveTypeAbove != StaffType.BracketNext & NewStaveType != StaffType.NoBracketNext)
                        {
                            if (StaveTypeAbove != StaffType.UpperGrandStaff && NewStaveType != StaffType.LowerGrandStaff) // Old is not upper, new is not lower
                            {
                                if (StavesWritten > 0)
                                {
                                    LilyPondFile.WriteLine("    >> % Staffgroup end");
                                }
                                switch (NewStaveType)
                                {
                                    case StaffType.Solo:
                                        {
                                            LilyPondFile.WriteLine("    <<");
                                            break;
                                        }
                                    case StaffType.Standard:
                                    case StaffType.BracketNext:
                                        {
                                            LilyPondFile.WriteLine("    \\new ChoirStaff <<");
                                            if (NonOssiaStaves != StaffNames.Count())
                                            {
                                                LilyPondFile.Write(@"      \set ChoirStaff.systemStartDelimiterHierarchy = #'(SystemStartBar (SystemStartBracket ");
                                                for (int j = 0; j < NonOssiaStaves; j++)
                                                {
                                                    LilyPondFile.Write(j.ToString() + " ");
                                                }
                                                LilyPondFile.WriteLine(") )");
                                            }
                                            LilyPondFile.WriteLine("      \\override ChoirStaff.SystemStartBracket #'collapse-height = #1");
                                            LilyPondFile.WriteLine("      \\override Score.SystemStartBar #'collapse-height = #1");
                                            break;
                                        }
                                    case StaffType.Orchestral:
                                    case StaffType.OrchestralNext:
                                        {
                                            LilyPondFile.WriteLine("    \\new StaffGroup <<");
                                            break;
                                        }
                                    case StaffType.UpperGrandStaff:
                                    case StaffType.LowerGrandStaff:
                                    case StaffType.GrandStaffNext:
                                        {
                                            LilyPondFile.WriteLine(@"    \new PianoStaff \with { \consists #Span_stem_engraver } <<");
                                            LilyPondFile.WriteLine("      \\set PianoStaff.connectArpeggios = ##t");
                                            if (chkLabel.Checked)
                                            {
                                                LilyPondFile.WriteLine("      \\set PianoStaff.instrumentName = #\"Piano\"");
                                            }
                                            if (chkShort.Checked)
                                            {
                                                LilyPondFile.WriteLine("      \\set PianoStaff.shortInstrumentName = #\"Pno\"");
                                            }
                                            break;
                                        }
                                    default:
                                        {
                                            break;
                                        }

                                }
                            }
                        }
                        StaveTypeAbove = NewStaveType;
                    }
                    ThisVoiceName = "";
                    Layer = StaffNames[i].Layer;
                    string MelodyEngraver = "";
                    string NeutralDirection = "";
                    if (chkMelody.Checked)
                    {
                        if (StaffNames[i].Type == StaffType.Solo || StaffNames[i].Type == StaffType.Standard)
                        {
                            if (!StaffNames[i].isInst)
                            {
                                MelodyEngraver = "\\with { \\consists \"Melody_engraver\" }";
                                NeutralDirection = "\\override Stem #'neutral-direction = #'()";
                            }
                        }
                    }
                    if (Layer == "N" && Layering)  // New voice on existing stave - layering = false - need to end stave
                    {
                        VoiceNumber++;
                        if (chkVoice.Checked)
                        {
                            ThisVoiceName = VoiceNames[VoiceNumber];
                        }
                        LilyPondFile.WriteLine("        \\new Voice = \"" + StaffNames[i].FileName + "\" " + MelodyEngraver + " { " + FontSize + ThisVoiceName + NeutralDirection + " << \\include \"" + StaffNames[i].FileName + ".ly\" >> }");
                        WriteLyricDetails(StaffNames[i], ref LyricName);
                        LilyPondFile.WriteLine("      >> % Staff end");
                        DynamicAlign = "";
                        if (GetDynDir(i) == "Up")
                        {
                            DynamicAlign = " = \"" + ThisStave.Name + "Dyn\" \\with { alignAboveContext = \"" + ThisStave.Name + "\" } ";
                        }
                        if (PianoStaff)
                        {
                            if (!PianoDynamicsWritten)
                            {
                                LilyPondFile.WriteLine("      \\new Dynamics " + DynamicAlign + "{ \\include \"" + ThisStave.FileName + "Dyn.ly\" }");
                                PianoDynamicsWritten = true;
                            }
                        }
                        else
                        {
                            LilyPondFile.WriteLine("      \\new Dynamics " + DynamicAlign + "{ \\include \"" + ThisStave.FileName + "Dyn.ly\" }");
                            PianoDynamicsWritten = false;
                        }
                        Layering = false;
                        Staves++;
                    }
                    else if (Layer == "Y" && Layering) // New voice on existing stave - layering = true
                    {
                        VoiceNumber++;
                        if (chkVoice.Checked)
                        {
                            ThisVoiceName = VoiceNames[VoiceNumber];
                        }
                        LilyPondFile.WriteLine("        \\new Voice = \"" + StaffNames[i].FileName + "\" " + MelodyEngraver + " { " + FontSize + ThisVoiceName + NeutralDirection + " << \\include \"" + StaffNames[i].FileName + ".ly\" >> }");
                        WriteLyricDetails(StaffNames[i], ref LyricName);
                    }
                    else if (Layer == "N" && !Layering) // Only voice on new stave - layering = false
                    {
                        VoiceNumber = 0;
                        LilyPondFile.WriteLine("      \\new Staff = \"" + StaffNames[i].Name + "\"" + WithMark + FurnitureSize);
                        LilyPondFile.WriteLine("      <<");
                        ThisStave = StaffNames[i];

                        if (chkLabel.Checked)
                        {
                            if (!PianoStaff)
                            {
                                LilyPondFile.WriteLine("        \\set Staff.instrumentName = " + MakeStaffName(StaffNames[i].Label));
                            }
                        }
                        if (chkShort.Checked)
                        {
                            if (!PianoStaff)
                            {
                                if (StaffNames[i].Abbrev != "")
                                {
                                    LilyPondFile.WriteLine("        \\set Staff.shortInstrumentName = " + MakeStaffName(StaffNames[i].Abbrev));
                                }
                                else
                                {
                                    LilyPondFile.WriteLine("        \\set Staff.shortInstrumentName = " + MakeStaffName(StaffNames[i].StaffName));
                                }
                            }
                        }
                        LilyPondFile.WriteLine("        \\new Voice = \"" + StaffNames[i].FileName + "\" " + MelodyEngraver + " { " + FontSize + NeutralDirection + " << \\include \"" + StaffNames[i].FileName + ".ly\" >> }");
                        WriteLyricDetails(StaffNames[i], ref LyricName);
                        LilyPondFile.WriteLine("      >> % Staff end");
                        DynamicAlign = "";
                        if (GetDynDir(i) == "Up")
                        {
                            DynamicAlign = " \\with { alignAboveContext = \"" + ThisStave.Name + "\" } ";
                        }
                        if (PianoStaff)
                        {
                            if (!PianoDynamicsWritten)
                            {
                                LilyPondFile.WriteLine("      \\new Dynamics " + DynamicAlign + "{ \\include \"" + ThisStave.FileName + "Dyn.ly\" }");
                                PianoDynamicsWritten = true;
                            }
                        }
                        else
                        {
                            LilyPondFile.WriteLine("      \\new Dynamics " + DynamicAlign + "{ \\include \"" + ThisStave.FileName + "Dyn.ly\" }");
                            PianoDynamicsWritten = false;
                        }
                        Layering = false;
                        Staves++;
                    }
                    else if (Layer == "Y" && !Layering)  // First voice on new stave - layering = true
                    {
                        VoiceNumber = 0;
                        if (chkVoice.Checked)
                        {
                            ThisVoiceName = VoiceNames[VoiceNumber];
                        }
                        LilyPondFile.WriteLine("      \\new Staff = \"" + StaffNames[i].Name + "\"" + WithMark + FurnitureSize);
                        LilyPondFile.WriteLine("      <<");
                        ThisStave = StaffNames[i];

                        if (chkLabel.Checked)
                        {
                            if (!PianoStaff)
                            {
                                LilyPondFile.WriteLine("        \\set Staff.instrumentName = " + MakeStaffName(StaffNames[i].Label));
                            }
                        }
                        if (chkShort.Checked)
                        {
                            if (!PianoStaff)
                            {
                                if (StaffNames[i].Abbrev != "")
                                {
                                    LilyPondFile.WriteLine("        \\set Staff.shortInstrumentName = " + MakeStaffName(StaffNames[i].Abbrev));
                                }
                                else
                                {
                                    LilyPondFile.WriteLine("        \\set Staff.shortInstrumentName = " + MakeStaffName(StaffNames[i].StaffName));
                                }
                            }
                        }
                        LilyPondFile.WriteLine("        \\new Voice = \"" + StaffNames[i].FileName + "\" " + MelodyEngraver + " { " + FontSize + ThisVoiceName + NeutralDirection + " << \\include \"" + StaffNames[i].FileName + ".ly\" >> }");
                        WriteLyricDetails(StaffNames[i], ref LyricName);
                        Layering = true;
                    }
                    else
                    {  // Bizarre - can't happen
                    }
                    Name1++;
                    if (Name1 == 'Z')
                    {
                        Name2++;
                        Name1 = 'A';
                    }
                    StavesWritten++;
                }
            }
            LilyPondFile.WriteLine("    >>  % Pianostaff/staffgroup/choirstaff end");
            txtResult.Text = Staves.ToString() + " staves written with " + StaffNames.Count.ToString() + " voices.";
        }
예제 #3
0
        private void DoLyricSkips(StaffInfo ThisStaffName)
        {
            string NoteFile = ThisStaffName.FileName + ".notes.txt";
            StreamReader NoteData = new StreamReader(CurrentDir + NoteFile);
            string AllNoteData = NoteData.ReadToEnd();
            NoteData.Close();
            string[] AllNotes = AllNoteData.Split(',');

            foreach (string LyricFile in ThisStaffName.LyricFileNames)
            {
                StreamReader LyricFileStream = new StreamReader(CurrentDir + LyricFile);
                string Input = LyricFileStream.ReadToEnd();
                LyricFileStream.Close();

                string AllLyrics = Input;

                Regex FindStanza = new Regex("\\\\set stanza = #\"([0-9]*)\" \\r\\n");
                MatchCollection StanzaMatches = FindStanza.Matches(AllLyrics);
                foreach (Match StanzaMatch in StanzaMatches)
                {
                    AllLyrics = AllLyrics.Replace(StanzaMatch.ToString(), StanzaMatch.ToString().Replace(" ", ""));
                }

                Regex FindConcat = new Regex("\\\\char\\s*##x[0-9|A-F]{4}\\s*[\\w]*");
                MatchCollection ConcatMatches = FindConcat.Matches(AllLyrics);
                foreach (Match ConcatMatch in ConcatMatches)
                {
                    AllLyrics = AllLyrics.Replace(ConcatMatch.ToString(), ConcatMatch.ToString().Replace(" ", ""));
                }

                while (AllLyrics.IndexOf(" --") > -1) AllLyrics = AllLyrics.Replace(" --", "--");
                while (AllLyrics.IndexOf(" __") > -1) AllLyrics = AllLyrics.Replace(" __", "__");
                while (AllLyrics.IndexOf("char ##") > -1) AllLyrics = AllLyrics.Replace("char ##", "char##");
                while (AllLyrics.IndexOf("{ ") > -1) AllLyrics = AllLyrics.Replace("{ ", "{");
                while (AllLyrics.IndexOf(" }") > -1) AllLyrics = AllLyrics.Replace(" }", "}");
                AllLyrics = AllLyrics.Replace("\r\n}", "}");
                while (AllLyrics.IndexOf(" }") > -1) AllLyrics = AllLyrics.Replace(" }", "}");
                for (int ii = 0; ii < LyricReplace.Count; ii++)
                {
                    AllLyrics = AllLyrics.Replace(LyricReplace[ii].Replacement, LyricReplace[ii].Replacement.Replace(" ", ""));
                }
                while (AllLyrics.IndexOf("  ") > -1) AllLyrics = AllLyrics.Replace("  ", " ");
                while (AllLyrics.IndexOf("\r\n ") > -1) AllLyrics = AllLyrics.Replace("\r\n ", "\r\n");
                string[] LyricTokens = AllLyrics.Split(' ');

                int NoteLoc = 0;
                string NewLyrics = "";
                for (int i = 0; i < LyricTokens.Count(); i++)
                {
                    if (i > 0)
                    {
                        if (AllNotes[NoteLoc].IndexOf("Skip") > -1 || LyricTokens[i - 1] == @"\skip1")
                        {
                            if (!(LyricTokens[i - 1].IndexOf("--") > -1 || LyricTokens[i - 1].IndexOf("__") > -1 || LyricTokens[i - 1].IndexOf("\\skip1") > -1))
                            {
                                LyricTokens[i - 1] += "__";
                            }
                        }
                    }
                    while (NoteLoc < AllNotes.Count() && (AllNotes[NoteLoc] == "TieSkip" || AllNotes[NoteLoc] == "SlurSkip" || AllNotes[NoteLoc] == "SkipSkip"))
                    {
                        if (AllNotes[NoteLoc] == "SkipSkip")
                        {
                            LyricTokens[i - 1] += @" \skip1"; // The skip must be attached to the previous note.
                        }
                        NoteLoc++;
                    }
                    NoteLoc++;
                }
                for (int i = 0; i < LyricTokens.Count(); i++)
                {
                    NewLyrics += LyricTokens[i] + " ";
                }
                NewLyrics = NewLyrics.Replace("--", " --");
                NewLyrics = NewLyrics.Replace("__", " __");
                NewLyrics = NewLyrics.Replace("}", " }");
                NewLyrics = NewLyrics.Replace("char##", "char ##");

                int charPos = NewLyrics.IndexOf("char ##");
                while (charPos > -1)
                {
                    NewLyrics = NewLyrics.Insert(charPos + 12, " ");
                    charPos = NewLyrics.IndexOf("char ##", charPos + 1);
                }

                for (int ii = 0; ii < LyricReplace.Count; ii++)
                {
                    NewLyrics = NewLyrics.Replace(LyricReplace[ii].Replacement.Replace(" ", ""), LyricReplace[ii].Replacement);
                }
                NewLyrics = NewLyrics.Replace(@"\setstanza=#", @"\set stanza = #");
                NewLyrics = NewLyrics.Replace("  ", " ");
                NewLyrics = NewLyrics.Replace("  ", " ");

                StreamWriter LyricFileResult = new StreamWriter(CurrentDir + LyricFile, false);
                LyricFileResult.Write(NewLyrics);
                LyricFileResult.Flush();
                LyricFileResult.Close();
            }
        }
예제 #4
0
 private void WriteLyricDetails(StaffInfo StaffName, ref char LyricName)
 {
     string FontSize = "";
     if (StaffName.Type == StaffType.Solo)
     {
         if (chkSmall.Checked == true)
         {
             FontSize = " \\tiny ";
         }
     }
     if (StaffName.LyricLines > 0)
     {
         for (int i = 0; i < StaffName.LyricLines; i++)
         {
             string LyricAlign = "";
             if (StaffName.bLyricsTop)
             {
                 LyricAlign = "\\with { alignAboveContext = " + StaffName.StaffName + " } ";
             }
             LilyPondFile.WriteLine("        \\new Lyrics " + LyricAlign + "\\lyricsto \"" + StaffName.FileName + "\" { " + FontSize + " << \\include \"" + StaffName.LyricFileNames[i] + "\" >> }");
             LyricName++;
         }
     }
 }