Beispiel #1
0
        public StackPanel GetSheetVisualisation(ADPTrack _adpTrack) //updates the barlines in the mainwindow to look like the ADPsheet that is given as the parameter
        {
            StackPanel resultStackPanel        = new StackPanel();
            int        barCount                = 0;
            bool       barlineHasTimeSignature = false;

            int[] currentTimeSignature = new int[2];

            IncipitViewerWPF barLine = createNewBarline();

            foreach (ADPBar tempBar in _adpTrack.Bars)
            {
                if (!barlineHasTimeSignature)
                {
                    currentTimeSignature[0] = tempBar.TimeSignature[0];
                    currentTimeSignature[1] = tempBar.TimeSignature[1];
                    barLine.AddMusicalSymbol(new TimeSignature(TimeSignatureType.Numbers, (uint)tempBar.TimeSignature[0], (uint)tempBar.TimeSignature[1]));
                    barLine.AddMusicalSymbol(new Barline());
                    barlineHasTimeSignature = true;
                }
                else if (currentTimeSignature[0] != tempBar.TimeSignature[0] && currentTimeSignature[1] != tempBar.TimeSignature[1])
                {
                    currentTimeSignature[0] = tempBar.TimeSignature[0];
                    currentTimeSignature[1] = tempBar.TimeSignature[1];
                    barLine.AddMusicalSymbol(new TimeSignature(TimeSignatureType.Numbers, (uint)tempBar.TimeSignature[0], (uint)tempBar.TimeSignature[1]));
                }

                // add symbols
                foreach (ADPMusicalSymbol tempSymbol in tempBar.MusicalSymbols)
                {
                    if (tempSymbol != null)
                    {
                        if (tempSymbol.GetType() == typeof(ADPRest))
                        {
                            //rest
                            barLine.AddMusicalSymbol(new Rest(convertDuration(tempSymbol.Duration)));
                        }
                        else
                        {
                            ADPNote tempNote = (ADPNote)tempSymbol;
                            //note
                            if (tempNote.AmountOfDots > 0)
                            {
                                barLine.AddMusicalSymbol(new Note(tempNote.Key, tempNote.Alter, tempNote.Octave, convertDuration(tempNote.Duration), NoteStemDirection.Down, NoteTieType.None, new List <NoteBeamType>()
                                {
                                    NoteBeamType.Single
                                })
                                {
                                    NumberOfDots = tempNote.AmountOfDots
                                });
                            }
                            else
                            {
                                barLine.AddMusicalSymbol(new Note(tempNote.Key, tempNote.Alter, tempNote.Octave, convertDuration(tempNote.Duration), NoteStemDirection.Down, NoteTieType.None, new List <NoteBeamType>()
                                {
                                    NoteBeamType.Single
                                }));
                            }
                        }
                    }
                }

                // add endOfBarLine

                barCount++;
                barLine.AddMusicalSymbol(new Barline());
                if (barCount == 3)
                {
                    resultStackPanel.Children.Add(barLine);
                    barLine  = createNewBarline();
                    barCount = 0;
                    barlineHasTimeSignature = false;
                }
            }
            if (barCount > 0)
            {
                resultStackPanel.Children.Add(barLine);
            }

            return(resultStackPanel);
        }
Beispiel #2
0
 private void showSheetVisualisation(ADPTrack _adpTrack) //ChannelCommand to show the Sheet in the MainWindow via the PSAMAdapter, takes a ADPTrack as parameter
 {
     barlinesScrollViewer.Content = psamAdapter.GetSheetVisualisation(_adpTrack);
 }
Beispiel #3
0
        public override ADPSheet ReadFile(String _path) //Reads the path name and converts it to an ADPSheet and returns it as such.
        {
            var sequence = new Sequence();

            sequence.Load(_path);

            ADPSheet         returnSheet = new ADPSheet();
            ADPTrack         tempADPTrack;
            ADPMusicalSymbol tempADPMusicalSymbol;

            int[] timeSignature      = new int[2];
            bool  timeSignatureIsSet = false;

            double wholeNoteLength = sequence.Division * 4;
            int    barAbsoluteTime = (int)wholeNoteLength;


            List <Track> tracks = new List <Track>();

            for (int i = 0; i < sequence.Count; i++)
            {
                tracks.Add(sequence[i]);
            }

            foreach (Track t in tracks)
            {
                tempADPTrack = new ADPTrack();
                ADPBar tempADPBar = new ADPBar();
                tempADPBar.TimeSignature = timeSignature;
                foreach (MidiEvent midiEvent in t.Iterator())
                {
                    // musical symbol
                    if (midiEvent.MidiMessage.MessageType == MessageType.Channel)
                    {
                        var channelMessage = midiEvent.MidiMessage as ChannelMessage;

                        if (channelMessage.Command == ChannelCommand.NoteOn || channelMessage.Command == ChannelCommand.NoteOff)
                        {
                            string[] inputStrings = convertToInputStrings(channelMessage, midiEvent, wholeNoteLength);
                            if (inputStrings != null)
                            {
                                tempADPMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings);
                                if (tempADPMusicalSymbol != null)
                                {
                                    tempADPBar.MusicalSymbols.Add(tempADPMusicalSymbol);
                                    if (midiEvent.AbsoluteTicks % (barAbsoluteTime) == 0)
                                    {
                                        //last musical symbol in bar
                                        tempADPTrack.Bars.Add(tempADPBar);
                                        tempADPBar = new ADPBar();
                                        tempADPBar.TimeSignature = timeSignature;
                                    }
                                }
                            }
                        }
                    }

                    // info over track
                    if (midiEvent.MidiMessage.MessageType == MessageType.Meta)
                    {
                        var metaMessage = midiEvent.MidiMessage as MetaMessage;
                        if (metaMessage.MetaType == MetaType.TrackName)
                        {
                            tempADPTrack.Name = MidiReader.GetMetaString(metaMessage);
                        }
                        if (metaMessage.MetaType == MetaType.TimeSignature)
                        {
                            if (!timeSignatureIsSet)
                            {
                                byte[] bytes = metaMessage.GetBytes();
                                timeSignature[0] = bytes[0];
                                timeSignature[1] = (int)Math.Pow(2, bytes[1]);

                                barAbsoluteTime = calculateBarLength(timeSignature, wholeNoteLength);

                                timeSignatureIsSet = true;
                            }
                        }
                    }
                }
                returnSheet.Tracks.Add(tempADPTrack);
            }
            return(returnSheet);
        }
Beispiel #4
0
        public ADPSheet ConvertContent(string[] _content) //Takes a string array and converts it to an ADPSheet, then returns it
        {
            int[]   timeSignature = new int[2];
            ADPNote latestNote    = new ADPNote();

            latestNote.Key    = "C";
            latestNote.Octave = 4;

            ADPMusicalSymbol tempMusicalSymbol;

            ADPBar tempBar;
            int    alternativeNr = 0;

            string tempo = "error";
            string key   = "error";

            contentType type = contentType.none;

            ADPSheet adps = new ADPSheet();
            ADPTrack adpt = new ADPTrack();

            adpt.Name = "LilypondTrack";

            List <ADPMusicalSymbol>         notes        = new List <ADPMusicalSymbol>();
            List <List <ADPMusicalSymbol> > alternatives = new List <List <ADPMusicalSymbol> >();

            for (int i = 2; i < _content.Length; i++)
            {
                string temp = _content[i];
                switch (_content[i])
                {
                case "":
                    break;

                case "\\tempo":
                    tempo = _content[i + 1];
                    i++;
                    break;

                case "\\time":
                    string str = _content[i + 1];
                    timeSignature[0] = (int)Char.GetNumericValue(str[0]);
                    timeSignature[1] = (int)Char.GetNumericValue(str[2]);
                    i++;
                    break;

                case "\\repeat":
                    tempBar = new ADPBar();
                    tempBar.MusicalSymbols = notes;
                    int[] tempTimeSignature = new int[2];
                    tempTimeSignature[0]  = timeSignature[0];
                    tempTimeSignature[1]  = timeSignature[1];
                    tempBar.TimeSignature = tempTimeSignature;
                    //adpt.Bars.Add(tempBar);
                    notes = new List <ADPMusicalSymbol>();
                    i++;
                    i++;
                    break;

                case "\\alternative":
                    //type = contentType.alternativeBlok;
                    break;

                case "\\clef":
                    key = _content[i + 1];
                    i++;
                    break;

                case "|":     //add maatstreep / new bar?
                    if (type == contentType.alternative)
                    {
                        //Had een Alternative maatstreep gemaakt
                    }
                    else
                    {
                        tempBar = new ADPBar();
                        tempBar.MusicalSymbols = notes;
                        tempTimeSignature      = new int[2];
                        tempTimeSignature[0]   = timeSignature[0];
                        tempTimeSignature[1]   = timeSignature[1];
                        tempBar.TimeSignature  = tempTimeSignature;
                        adpt.Bars.Add(tempBar);
                        notes = new List <ADPMusicalSymbol>();
                    }
                    break;

                case "{":     //add alternative if alternativeblock
                    if (type == contentType.alternativeBlok)
                    {
                        type = contentType.alternative;
                        alternatives.Add(new List <ADPMusicalSymbol>());
                    }
                    break;

                case "}":
                    //close alternative if alternativeblock
                    //if (type == contentType.alternative)
                    //{
                    //    type = contentType.alternativeBlok;
                    //    alternativeNr++;
                    //}

                    //else
                    //{
                    //    type = contentType.none;
                    //}
                    if (notes.Count > 0)
                    {
                        ADPBar tempBar2 = new ADPBar();
                        tempBar2.MusicalSymbols = notes;
                        tempBar2.TimeSignature  = timeSignature;
                        adpt.Bars.Add(tempBar2);
                        notes = new List <ADPMusicalSymbol>();
                    }
                    break;

                case "}}":      //End of File
                    break;

                case "~":
                    break;

                default:

                    if (type == contentType.alternative)
                    {
                        //add alternative note
                        string[] inputStrings = convertToInputStrings(_content[i], latestNote);
                        if (inputStrings != null)
                        {
                            tempMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings);
                            if (tempMusicalSymbol is ADPNote)
                            {
                                latestNote = (ADPNote)tempMusicalSymbol;
                            }
                            alternatives[alternativeNr].Add(tempMusicalSymbol);
                        }
                    }
                    else
                    {
                        //add normal note
                        string[] inputStrings = convertToInputStrings(_content[i], latestNote);
                        if (inputStrings != null)
                        {
                            tempMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings);
                            if (tempMusicalSymbol is ADPNote)
                            {
                                latestNote = (ADPNote)tempMusicalSymbol;
                            }
                            notes.Add(tempMusicalSymbol);
                        }
                    }
                    break;
                }
            }
            adps.Tracks.Add(adpt); //Only need to add one track
            return(adps);
        }