Example #1
0
        public static void getMusicSymbols(Staff staff, List <MusicalSymbol> WPFStaffs)
        {
            Clef clef = new Clef(ClefType.GClef, 2);

            if (staff.GetClef() == "bass")
            {
                clef = new Clef(ClefType.CClef, 4);
            }
            WPFStaffs.Add(clef);
            int[] time = staff.GetTime();
            WPFStaffs.Add(new TimeSignature(TimeSignatureType.Numbers, (UInt32)time[0], (UInt32)time[1]));
            List <Bar> bars = staff.GetBars();

            foreach (Bar bar in bars)
            {
                List <NoteRest> notes = bar.GetNotes();
                foreach (NoteRest note in notes)
                {
                    string pitch  = "";
                    int    octave = 0;
                    int    length = 0;
                    int    dots   = 0;
                    note.GetInfo(ref pitch, ref octave, ref length, ref dots);
                    if (pitch.Equals("r"))
                    {
                        var rest = new PSAMControlLibrary.Rest((MusicalSymbolDuration)length);
                        WPFStaffs.Add(rest);
                    }
                    else
                    {
                        int alter = 0;
                        alter += Regex.Matches(pitch, "is").Count;
                        alter -= Regex.Matches(pitch, "es|as").Count;
                        var WPFNote = new PSAMControlLibrary.Note(pitch[0].ToString().ToUpper(), alter, octave,
                                                                  (MusicalSymbolDuration)length, NoteStemDirection.Up, NoteTieType.None,
                                                                  new List <NoteBeamType>()
                        {
                            NoteBeamType.Single
                        })
                        {
                            NumberOfDots = dots
                        };
                        WPFStaffs.Add(WPFNote);
                    }
                }
                WPFStaffs.Add(new Barline());
            }
        }
Example #2
0
        private void AddRest(Rest rest)
        {
            var psamRest = new PSAMRest((MusicalSymbolDuration)rest.Duration);

            _notes.Add(psamRest);
        }
Example #3
0
        public Sequence GetSequenceFromStaff(Staff staff)
        {
            List <string> notesOrderWithCrosses = new List <string>()
            {
                "c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais", "b"
            };
            int      absoluteTicks = 0;
            Sequence sequence      = new Sequence();
            Track    metaTrack     = new Track();

            sequence.Add(metaTrack);
            Track notesTrack = new Track();

            sequence.Add(notesTrack);

            int speed = 60000000 / staff.GetTempo();

            byte[] tempo = new byte[3];
            tempo[0] = (byte)((speed >> 16) & 0xff);
            tempo[1] = (byte)((speed >> 8) & 0xff);
            tempo[2] = (byte)(speed & 0xff);
            metaTrack.Insert(0 /* Insert at 0 ticks*/, new MetaMessage(MetaType.Tempo, tempo));

            List <MusicalSymbol> WPFStaffs = new List <MusicalSymbol>();

            WPFManager.getMusicSymbols(staff, WPFStaffs);
            foreach (MusicalSymbol musicalSymbol in WPFStaffs)
            {
                int[]  time;
                double absoluteLength;
                double relationToQuartNote;
                double percentageOfBeatNote;
                double deltaTicks;
                switch (musicalSymbol.Type)
                {
                case MusicalSymbolType.Note:
                    Note note = musicalSymbol as Note;

                    absoluteLength  = 1.0 / (double)note.Duration;
                    absoluteLength += (absoluteLength / 2.0) * note.NumberOfDots;

                    time = staff.GetTime();
                    relationToQuartNote  = time[1] / 4.0;
                    percentageOfBeatNote = (1.0 / time[1]) / absoluteLength;
                    deltaTicks           = (sequence.Division / relationToQuartNote) / percentageOfBeatNote;

                    // Calculate height
                    int noteHeight = notesOrderWithCrosses.IndexOf(note.Step.ToLower()) + ((note.Octave + 1) * 12);
                    noteHeight += note.Alter;
                    notesTrack.Insert(absoluteTicks, new ChannelMessage(ChannelCommand.NoteOn, 1, noteHeight, 90));     // Data2 = volume

                    absoluteTicks += (int)deltaTicks;
                    notesTrack.Insert(absoluteTicks, new ChannelMessage(ChannelCommand.NoteOn, 1, noteHeight, 0));     // Data2 = volume
                    break;

                case MusicalSymbolType.Rest:
                    Rest rest = musicalSymbol as Rest;

                    absoluteLength  = 1.0 / (double)rest.Duration;
                    absoluteLength += (absoluteLength / 2.0) * rest.NumberOfDots;

                    time = staff.GetTime();
                    relationToQuartNote  = time[1] / 4.0;
                    percentageOfBeatNote = (1.0 / time[1]) / absoluteLength;
                    deltaTicks           = (sequence.Division / relationToQuartNote) / percentageOfBeatNote;
                    absoluteTicks       += (int)deltaTicks;
                    break;

                case MusicalSymbolType.TimeSignature:
                    time = staff.GetTime();
                    byte[] timeSignature = new byte[4];
                    timeSignature[0] = (byte)time[0];
                    timeSignature[1] = (byte)(Math.Log(time[1]) / Math.Log(2));
                    metaTrack.Insert(absoluteTicks, new MetaMessage(MetaType.TimeSignature, timeSignature));
                    break;

                default:
                    break;
                }
            }
            notesTrack.Insert(absoluteTicks, MetaMessage.EndOfTrackMessage);
            metaTrack.Insert(absoluteTicks, MetaMessage.EndOfTrackMessage);
            return(sequence);
        }