//Reads the top level score
        static public ScoreProperties ReadScore(ScorePartwise scorePartwise)
        {
            //get the top level properties of the score
            ScoreProperties i = new ScoreProperties();

            if (scorePartwise.getWork() != null)
            {
                i.WorkTitle = scorePartwise.getWork().getWorkTitle();
            }
            if (scorePartwise.getMovementTitle() != null)
            {
                i.MovementTitle = scorePartwise.getMovementTitle();
            }

            if (scorePartwise.getIdentification().getEncoding().getEncodingDateOrEncoderOrSoftware().get(0) != null)
            {
                javax.xml.bind.JAXBElement x = (javax.xml.bind.JAXBElement)scorePartwise.getIdentification().getEncoding().getEncodingDateOrEncoderOrSoftware().get(0);
                i.EncodingSoftware = x.getValue().ToString();
            }
            if (scorePartwise.getCredit().size() > 0)
            {
                Credit credit = (Credit)scorePartwise.getCredit().get(0);
                if (credit.getCreditTypeOrLinkOrBookmark().get(0) is FormattedText)
                {
                    FormattedText ft = (FormattedText)credit.getCreditTypeOrLinkOrBookmark().get(0);
                    i.CreditWords = ft.getValue();
                }
            }
            PartList partlist = scorePartwise.getPartList();

            if (partlist.getPartGroupOrScorePart().get(0) is ScorePart)
            {
                ScorePart scorepart = (ScorePart)partlist.getPartGroupOrScorePart().get(0);
                i.ScorePartID      = scorepart.getId();
                i.PartDisplayName  = scorepart.getPartName().getValue();
                i.PartAbbreviation = scorepart.getPartAbbreviation() is PartName?scorepart.getPartAbbreviation().getValue() : "";

                ScoreInstrument scoreinstrument = (ScoreInstrument)scorepart.getScoreInstrument().get(0);
                i.InstrumentID   = scoreinstrument.getId();
                i.InstrumentName = scoreinstrument.getInstrumentName();
                if (scorepart.getMidiDeviceAndMidiInstrument().get(0) is MidiInstrument)
                {
                    MidiInstrument midiinstrument = (MidiInstrument)scorepart.getMidiDeviceAndMidiInstrument().get(0);
                    i.MidiChannel = midiinstrument.getMidiChannel();
                    i.MidiProgram = midiinstrument.getMidiProgram();
                }
            }
            if (scorePartwise.getPart().size() > 0)
            {
                i.Part = (ScorePartwise.Part)scorePartwise.getPart().get(0);
            }
            return(i);
        }
Exemple #2
0
        //***************************************** Create Object Factory *******************************************//
        //The Object Factory, Used to create the elements of the score as required

        //***************************************** ScorePartwise *******************************************//
        // Create the top level Partwise Score Element


        public static ScorePartwise CreateScorePartwise(ScoreProperties i)
        {
            ObjectFactory factory = new ObjectFactory();

            //Create a scorepart
            ScorePartwise.Part part;
            Marshalling.getContext();
            ///////////////////// Following are the main components required for the Score in Phase 1


            //***************************************** ScorePartwise *******************************************//
            ScorePartwise scorePartwise = factory.createScorePartwise();

            // Set the version of MusicXML
            scorePartwise.setVersion("3.0");

            //***************************************** Set Work and Movement Titles *******************************************//
            // Create the work element and set its title
            Work work = factory.createWork();

            work.setWorkTitle(i.WorkTitle);


            //Setting some properties of the root element.
            scorePartwise.setMovementTitle(i.MovementTitle);

            //Set the work title of the scorepartwise
            scorePartwise.setWork(work);

            //***************************************** Create and set Identification Element *******************************************//

            //Create identification and set its properties
            Identification identification = factory.createIdentification();

            com.audiveris.proxymusic.Encoding encoding = factory.createEncoding();

            //set the software used for encoding
            encoding.getEncodingDateOrEncoderOrSoftware().add(factory.createEncodingSoftware(i.EncodingSoftware));

            // set the encoding
            identification.setEncoding(encoding);
            scorePartwise.setIdentification(identification);


            //***************************************** Set the Credit words *******************************************//

            Credit        credit         = factory.createCredit();
            FormattedText creditwordtext = new FormattedText();

            creditwordtext.setValue(i.CreditWords);
            credit.getCreditTypeOrLinkOrBookmark().add(creditwordtext);

            scorePartwise.getCredit().add(credit);
            //***************************************** Create a PartList *******************************************//

            PartList partlist = factory.createPartList();

            // create a scorepart
            ScorePart scorepart = factory.createScorePart();

            ////////////////////////Some Properties of the scorepart
            PartName partname = factory.createPartName();

            partname.setValue(i.PartDisplayName);
            scorepart.setPartName(partname);

            //set part abbreviation
            partname.setValue(i.PartAbbreviation);
            scorepart.setPartAbbreviation(partname);

            //set the scorepart id
            scorepart.setId(i.ScorePartID);

            // set the scorepart instrument
            ScoreInstrument scoreinstrument = factory.createScoreInstrument();

            scoreinstrument.setId(i.InstrumentID);
            scoreinstrument.setInstrumentName(i.InstrumentName);

            scorepart.getScoreInstrument().add(scoreinstrument);

            //set the midi device parameters
            MidiInstrument midiinstrument = factory.createMidiInstrument();

            //set midi instrument Id
            midiinstrument.setId(scoreinstrument);

            //set midi channel
            java.lang.Integer midichannel = i.MidiChannel; //channel number
            midiinstrument.setMidiChannel(midichannel);

            //set midi program
            java.lang.Integer midiprogram = i.MidiProgram; //program number
            midiinstrument.setMidiProgram(midiprogram);


            scorepart.getMidiDeviceAndMidiInstrument().add(midiinstrument);

            // add the scorepart to the partlist
            partlist.getPartGroupOrScorePart().add(scorepart); //Ambiguity

            scorePartwise.setPartList(partlist);

            //***************************************** Create a Part *******************************************//
            if (i.Part == null)
            {
                part = factory.createScorePartwisePart();
            }
            else
            {
                part = i.Part;
            }
            //set part id
            part.setId(scorepart);

            // Add the part to the score
            scorePartwise.getPart().add(part);

            return(scorePartwise);
        }