Package jm.music.data

Examples of jm.music.data.Part


     *
     * @param phrase The phrase to be played.
     * @param inst   An instrument to play the phrase with
     */
    public static void audio(Phrase phrase, Instrument inst) {
        Part part = new Part(phrase);
        if (phrase.getTempo() != Phrase.DEFAULT_TEMPO) part.setTempo(phrase.getTempo());
        audio(part, new Instrument[]{inst});
    }
View Full Code Here


            insts[i].setOutput(Instrument.REALTIME);
        }
        // get all the phrases in a vector
        java.util.Vector v = new java.util.Vector();
        for (int i = 0; i < score.size(); i++) {
            Part p = score.getPart(i);
            for (int j = 0; j < p.size(); j++) {
                Phrase phr = p.getPhrase(j);
                if (phr.getInstrument() == Phrase.DEFAULT_INSTRUMENT)
                    phr.setInstrument(p.getInstrument());
                if (phr.getTempo() == Phrase.DEFAULT_TEMPO)
                    phr.setTempo(p.getTempo());
                v.addElement(phr);
            }
        }
        // create RTPhrases for each phrase
        jm.music.rt.RTLine[] lines = new jm.music.rt.RTLine[v.size()];
View Full Code Here

        double longestTime = 0.0;
        double longestRatio = 1.0;

        Enumeration parts = score.getPartList().elements();
        while (parts.hasMoreElements()) {
            Part inst = (Part) parts.nextElement();

            int currChannel = inst.getChannel();
            if (currChannel > 16) {
                throw new
                        InvalidMidiDataException(inst.getTitle() +
                        " - Invalid Channel Number: " +
                        currChannel);
            }

            m_tempoHistory.push(new Float(m_currentTempo));

            float tempo = new Float(inst.getTempo()).floatValue();
            //System.out.println("jMusic MidiSynth notification: Part TempoEvent (BPM) = " + tempo);
            if (tempo != Part.DEFAULT_TEMPO) {
                m_currentTempo = tempo;
            } else if (tempo < Part.DEFAULT_TEMPO)
                System.out.println("jMusic MidiSynth error: Part TempoEvent (BPM) too low = " + tempo);

            trackTempoRatio = m_masterTempo / m_currentTempo;

            int instrument = inst.getInstrument();
            if (instrument == NO_INSTRUMENT) instrument = 0;

            Enumeration phrases = inst.getPhraseList().elements();
            double max = 0;
            double currentTime = 0.0;

            //
            // One track per Part
View Full Code Here

        if (XMLStyles.isValidScoreTag(elements[0].getName())) {          
                return elementToScore(elements[0]);
        } else if (XMLStyles.isValidPartTag(elements[0].getName())) {
                return new Score(elementToPart(elements[0]));
        } else if (XMLStyles.isValidPhraseTag(elements[0].getName())) {
                return new Score(new Part(elementToPhrase(elements[0])));
        } else if (XMLStyles.isValidNoteTag(elements[0].getName())) {
                return new Score(new Part(
                                new Phrase(elementToNote(elements[0]))));
        }
        throw new ConversionException("Unrecognised root element: "
                                      + elements[0].getName());
    }
View Full Code Here

                                "This XML string represents a Score, use the "
                                + "xmlStringToScore(String) method instead.");
        } else if (XMLStyles.isValidPartTag(elements[0].getName())) {
                return elementToPart(elements[0]);
        } else if (XMLStyles.isValidPhraseTag(elements[0].getName())) {
                return new Part(elementToPhrase(elements[0]));
        } else if (XMLStyles.isValidNoteTag(elements[0].getName())) {
                return new Part(new Phrase(elementToNote(elements[0])));
        }
        throw new ConversionException("Unrecognised root element: "
                                      + elements[0].getName());
    }
View Full Code Here

        if (! XMLStyles.isValidPartTag(element.getName())) {
            throw new ConversionException(
                    "Invalid element: " + element.getName() + ".  The only "
                    + "accepted tag name is '" + xmlStyle.getPartTagName() + "'.");
        }
        Part returnPart = new Part();
        String attributeValue;

        attributeValue = XMLStyles.getTitleAttributeValue(element);
        if (! attributeValue.equals("")) {
            returnPart.setTitle(attributeValue);
        }
        attributeValue = XMLStyles.getChannelAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setChannel(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getChannelAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getInstrumentAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setInstrument(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getInstrumentAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getTempoAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setTempo(
                        Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getTempoAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java double.");
            }
        }
        attributeValue = XMLStyles.getKeySignatureAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setKeySignature(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getKeySignatureAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getKeyQualityAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setKeyQuality(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getKeyQualityAttributeName() + "' of element '"
                        + xmlStyle.getScoreTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getNumeratorAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setNumerator(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getNumeratorAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getDenominatorAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setDenominator(Integer.parseInt(attributeValue));
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getDenominatorAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java integer.");
            }
        }
        attributeValue = XMLStyles.getPanAttributeValue(element);
        if (! attributeValue.equals("")) {
            try {
                returnPart.setPan(Double.valueOf(attributeValue).doubleValue());
            } catch (NumberFormatException e) {
                throw new ConversionException(
                        "Invalid attribute value: " + attributeValue + ".  The "
                        + "attribute '" + xmlStyle.getPanAttributeName() + "' of element '"
                        + xmlStyle.getPartTagName() + "' must represent a Java double.");
            }
        }
        Element[] elements = element.getChildren();
        for (int i = 0; i < elements.length; i++) {
            if (XMLStyles.isValidPhraseTag(elements[i].getName())) {
                returnPart.addPhrase(elementToPhrase(elements[i]));
            }
        }
        return returnPart;
    }
View Full Code Here

        double longestTime = 0.0;
        double longestRatio = 1.0;

        Enumeration parts = score.getPartList().elements();
        while(parts.hasMoreElements()) {
            Part inst = (Part) parts.nextElement();

            int currChannel = inst.getChannel();
            if (currChannel > 16) {
                throw new
                    InvalidMidiDataException(inst.getTitle() +
                                            " - Invalid Channel Number: " +
                                            currChannel);
            }

            m_tempoHistory.push(new Float(m_currentTempo));

            float tempo = new Float(inst.getTempo()).floatValue();
      //System.out.println("jMusic MidiSynth notification: Part TempoEvent (BPM) = " + tempo);
            if (tempo != Part.DEFAULT_TEMPO) {
                m_currentTempo = tempo;
            } else if (tempo < Part.DEFAULT_TEMPO)
                System.out.println("jMusic MidiSynth error: Part TempoEvent (BPM) too low = " + tempo);

            trackTempoRatio = m_masterTempo/m_currentTempo;

            int instrument = inst.getInstrument();
            if (instrument == NO_INSTRUMENT) instrument = 0;

            Enumeration phrases = inst.getPhraseList().elements();
            double max = 0;
            double currentTime = 0.0;
     
      //
      // One track per Part
View Full Code Here

  public static void SMFToScore(Score score, SMF smf){
    System.out.println("Convert SMF to JM");
    Enumeration aEnum = smf.getTrackList().elements();
    //Go through tracks
    while(aEnum.hasMoreElements()){
      Part part = new Part();
      Track smfTrack = (Track) aEnum.nextElement();
      Vector evtList = smfTrack.getEvtList();
      Vector phrVct = new Vector();
      sortEvents(score,evtList,phrVct,smf,part);
      for(int i=0;i<phrVct.size();i++){
          part.addPhrase((Phrase)phrVct.elementAt(i));
      }
      score.addPart(part);
      score.clean();
    }
  }
View Full Code Here

    //---------------------------------------------------
    int partCount = 0;
    Enumeration aEnum = score.getPartList().elements();
    while(aEnum.hasMoreElements()){
      Track smfTrack = new Track();
      Part inst = (Part) aEnum.nextElement();
      System.out.print("    Part "+ partCount + " '" + inst.getTitle() +
          "' to SMF Track on Ch. " + inst.getChannel() + ": ");
      partCount++;

      // set up tempo difference between score and track - if any
      if(inst.getTempo() != Part.DEFAULT_TEMPO) partTempoMultiplier =
        scoreTempo / inst.getTempo();
      else partTempoMultiplier = 1.0;
      //System.out.println("partTempoMultiplier = " + partTempoMultiplier);

      //order phrases based on their startTimes
      phraseNumb = inst.getPhraseList().size();
      for(int i=0; i< phraseNumb; i++){
        phrase1 = (Phrase) inst.getPhraseList().elementAt(i);
        for(int j=0; j<phraseNumb; j++){
          phrase2 = (Phrase)inst.getPhraseList().elementAt(j);
          if(phrase2.getStartTime() > phrase1.getStartTime()){
            inst.getPhraseList().setElementAt( phrase2, i );
            inst.getPhraseList().setElementAt( phrase1, j );
            break;
          }
        }
      }
      //break Note objects into NoteStart's and NoteEnd's
      //as well as combining all phrases into one list
//      HashMap midiEvents = new HashMap();

      class EventPair{public double time; public Event ev; public EventPair(double t, Event e){time = t; ev = e;}};
      LinkedList<EventPair> midiEvents = new LinkedList<EventPair>();
     
      /*if(inst.getTempo() != Part.DEFAULT_TEMPO){
        //System.out.println("Adding part tempo");
        midiEvents.add(new EventPair(0, new TempoEvent(inst.getTempo())));
      } */
      //if this part has a Program Change value then set it     
      if(inst.getInstrument() != NO_INSTRUMENT){
        //System.out.println("Instrument change no. " + inst.getInstrument());
        midiEvents.add(new EventPair(0, new PChange((short) inst.getInstrument(),(short) inst.getChannel(),0)));
      }

      if(inst.getNumerator() != NO_NUMERATOR){
        midiEvents.add(new EventPair(0, new TimeSig(inst.getNumerator(),inst.getDenominator())));
      }

      if(inst.getKeySignature() != NO_KEY_SIGNATURE){
        midiEvents.add(new EventPair(0, new KeySig(inst.getKeySignature(),inst.getKeyQuality())));
      }

      Enumeration partEnum = inst.getPhraseList().elements();
      double max = 0;
      double startTime = 0.0;
      double offsetValue = 0.0;
      int phraseCounter = 0;
      while(partEnum.hasMoreElements()) {
        Phrase phrase = (Phrase) partEnum.nextElement();
        Enumeration phraseEnum = phrase.getNoteList().elements();
        startTime = phrase.getStartTime() * partTempoMultiplier; 
        if(phrase.getInstrument() != NO_INSTRUMENT){
          midiEvents.add(new EventPair(0, new PChange((short)phrase.getInstrument(),(short)inst.getChannel(),0)));
        }
        if(phrase.getTempo() != Phrase.DEFAULT_TEMPO) {
          phraseTempoMultiplier = scoreTempo / phrase.getTempo(); //(scoreTempo * partTempoMultiplier) / phrase.getTempo();
        } else {
          phraseTempoMultiplier = partTempoMultiplier;
        }

        ////////////////////////////////////////////////
        int noteCounter = 0;
        //System.out.println();
        System.out.print(" Phrase " + phraseCounter++ +":");
        // set a silly starting value to force and initial pan cc event
        double pan = -1.0;
        resetTicker(); // zero the ppqn error calculator
        while(phraseEnum.hasMoreElements()){
          Note note = (Note) phraseEnum.nextElement();
          offsetValue = note.getOffset();
          // add a pan control change if required
          if(note.getPan() != pan) {
            pan = note.getPan();
            midiEvents.add(new EventPair(startTime + offsetValue, new CChange((short)10,(short)(pan * 127), (short)inst.getChannel(),0)));
          }
          //check for frequency rather than MIDI notes
          int pitch = 0;
          if (note.getPitchType() == Note.FREQUENCY) {
            System.err.println("jMusic warning: converting note frequency to the closest MIDI pitch for SMF.");
            //System.exit(1);
            pitch = Note.freqToMidiPitch(note.getFrequency());
          } else pitch = note.getPitch();
          if(pitch != REST) {
            midiEvents.add(new EventPair(new Double(startTime + offsetValue),new NoteOn((short)pitch,(short)note.getDynamic(),(short)inst.getChannel(),0)));

            // Add a NoteOn for the END of the note with 0 dynamic, as recommended.
            //create a timing event at the end of the notes duration
            double endTime = startTime + (note.getDuration() * phraseTempoMultiplier);
            // Add the note-off time to the list
            midiEvents.add(new EventPair(new Double(endTime + offsetValue),new NoteOn((short)pitch, (short)0, (short)inst.getChannel(),0)));
          }
          // move the note-on time forward by the rhythmic value
          startTime += tickRounder(note.getRhythmValue() * phraseTempoMultiplier); //time between start times
          System.out.print("."); // completed a note
        }
View Full Code Here

                new Double(getProperty(OTHER_NOTES_TOTAL_DUR))
                    .doubleValue()
        );

        Score   s = new Score();
        Part    p = new Part();
        s.addPart(p);
        p.addPhrase(phrase);                    
    }               
View Full Code Here

TOP

Related Classes of jm.music.data.Part

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.