Examples of Sequencer


Examples of javax.sound.midi.Sequencer

  public MidiPlayer(File midiFile) {

    // Play once
    try {
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.setSequence(MidiSystem.getSequence(midiFile));
      sequencer.open();
      sequencer.start();
      /*
       while(true) {
       if (sequencer.isRunning()) {
       try {
       Thread.sleep(1000); // Check every second
View Full Code Here

Examples of javax.sound.midi.Sequencer

    }
  }
 
  public void playBackgroundMusic(String id) {
    try {
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
      sequencer.setSequence(getSequence("ff4fores"));
      sequencer.start();
    } catch (MidiUnavailableException e) {
      throw new RuntimeException(e);
    } catch (InvalidMidiDataException e) {
      throw new RuntimeException(e);
    }
View Full Code Here

Examples of javax.sound.midi.Sequencer

  public MidiPlayer(File midiFile) {

    // Play once
    try {
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.setSequence(MidiSystem.getSequence(midiFile));
      sequencer.open();
      sequencer.start();
      /*
       while(true) {
       if(sequencer.isRunning()) {
       try {
       Thread.sleep(1000); // Check every second
View Full Code Here

Examples of javax.sound.midi.Sequencer

   
    setUpGui(); //Call our setUpGui method
   
    try
    {
      Sequencer sequencer = MidiSystem.getSequencer(); //Create a new midi system sequencer
      sequencer.open();    //Open up the sequencer object we created
      sequencer.addControllerEventListener(ml, new int[] {127})
      //Add a control event listener using our ml object
     
      Sequence seq = new Sequence(Sequence.PPQ, 4);   //Create a new sequence with a type and res
      Track track = seq.createTrack();        //Set the track to our new track on seq
     
      int r = 0;
     
      for (int i = 5; i < 61; i += 4)
      {
       
        r = (int) ((Math.random() * 50) + 1);
       
        //Picking up the beats and adding our events to the track
        //Helps to add our rectangles along with the beat itself
        track.add(makeEvent(144, 1, r, 100,i));
        track.add(makeEvent(176, 1, 127, 0, i));
        track.add(makeEvent(128, 1, r, 100, i + 2));
       
      }
     
      //Set the sequencer's sequence to the Sequence object we created
      sequencer.setSequence(seq);
      //Set the tempo to beats per minute
      sequencer.setTempoInBPM(220);
      //Start our sequencer
      sequencer.start();
     
     
    }
    catch (Exception ex) //Catch any exceptions and print the stack trace
    {
View Full Code Here

Examples of javax.sound.midi.Sequencer

    // Note: we won't try to play more than one MIDI at a time.
    private synchronized void play(final InputStream is)
            throws RippleException {
        // Play once
        try {
            Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.setSequence(MidiSystem.getSequence(is));
            sequencer.open();
            sequencer.start();

            // Break out when playback is finished.
            while (true) {
                if (sequencer.isRunning()) {
                    try {
                        Thread.sleep(1000); // Check every second
                    } catch (InterruptedException ignore) {
                        break;
                    }
                } else
                    break;
            }

            // Close the MidiDevice & free resources
            sequencer.stop();
            sequencer.close();

            is.close();
        } catch (javax.sound.midi.MidiUnavailableException e) {
            throw new RippleException(e);
        } catch (javax.sound.midi.InvalidMidiDataException e) {
View Full Code Here

Examples of javax.sound.midi.Sequencer

public class MidiUtil
{
  private static void playMidi(Sequence seq, float tempo, Set<Player> listeners)
    throws InvalidMidiDataException, IOException, MidiUnavailableException
  {
    Sequencer sequencer = MidiSystem.getSequencer(false);
    sequencer.setSequence(seq);
    sequencer.open();

    // slow it down just a bit
    sequencer.setTempoFactor(tempo);

    NoteBlockReceiver noteblockRecv = new NoteBlockReceiver(listeners);
    sequencer.getTransmitter().setReceiver(noteblockRecv);
    sequencer.start();
  }
View Full Code Here

Examples of javax.sound.midi.Sequencer

     
      Thread thread = new Thread() {
       
        public final void run() {
          try {
            Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.open();
            MidiRenderer.volumeSupported = (sequencer instanceof Synthesizer);
            sequencer.close();
           
            MidiRenderer.available = true;
          }
          catch (Throwable e) {
            System.err
View Full Code Here

Examples of net.helipilot50.stocktrade.services.Sequencer

        super();

        this.orderList = new Array_Of_Order<Order>();
        //self.NextOrderID = 1;

        this.orderSequencer = new Sequencer();

    }
View Full Code Here

Examples of org.modeshape.jcr.api.sequencer.Sequencer

    public boolean sequence( String sequencerName,
                             Property inputProperty,
                             Node outputNode ) throws RepositoryException {
        CheckArg.isSame(inputProperty.getSession(), "inputProperty", this, "this session");
        CheckArg.isSame(outputNode.getSession(), "outputNode", this, "this session");
        Sequencer sequencer = repository().runningState().sequencers().getSequencer(sequencerName);
        if (sequencer == null) return false;

        final ValueFactory values = getValueFactory();
        final DateTime now = dateFactory().create();
        final Sequencer.Context context = new Sequencer.Context() {

            @Override
            public ValueFactory valueFactory() {
                return values;
            }

            @Override
            public Calendar getTimestamp() {
                return now.toCalendar();
            }
        };
        try {
            if (sequencer.hasAcceptedMimeTypes()) {
                // Get the MIME type, first by looking at the changed property's parent node
                // (or grand-parent node if parent is 'jcr:content') ...
                String mimeType = SequencingRunner.getInputMimeType(inputProperty);

                // See if the sequencer accepts the MIME type ...
                if (mimeType != null && !sequencer.isAccepted(mimeType)) {
                    Logger.getLogger(getClass())
                          .debug("Skipping sequencing because input's MIME type '{0}' is not accepted by the '{1}' sequencer",
                                 mimeType, sequencerName);
                    return false;
                }
            }
            return sequencer.execute(inputProperty, outputNode, context);
        } catch (RepositoryException e) {
            throw e;
        } catch (Exception e) {
            throw new RepositoryException(e);
        }
View Full Code Here

Examples of org.modeshape.jcr.api.sequencer.Sequencer

    @Override
    public void run() {
        JcrSession inputSession = null;
        JcrSession outputSession = null;
        final RepositoryStatistics stats = repository.statistics();
        Sequencer sequencer = null;
        String sequencerName = null;
        try {
            // Create the required session(s) ...
            inputSession = repository.loginInternalSession(work.getInputWorkspaceName());
            if (work.getOutputWorkspaceName() != null && !work.getOutputWorkspaceName().equals(work.getInputWorkspaceName())) {
                outputSession = repository.loginInternalSession(work.getOutputWorkspaceName());
            } else {
                outputSession = inputSession;
            }

            // Get the sequencer ...
            sequencer = repository.sequencers().getSequencer(work.getSequencerId());
            if (sequencer == null) {
                if (DEBUG) {
                    LOGGER.debug("Unable to find sequencer with ID '{0}' in repository '{1}'; skipping input '{3}:{2}' and output '{5}:{4}'",
                                 work.getSequencerId(), repository.name(), work.getInputPath(), work.getInputWorkspaceName(),
                                 work.getOutputPath(), work.getOutputWorkspaceName());
                }
                return;
            }
            sequencerName = sequencer.getName();

            String logMsg = null;
            if (TRACE || DEBUG) {
                logMsg = StringUtil.createString("sequencer '{0}' in repository '{1}' with input '{3}:{2}' to produce '{5}:{4}'",
                                                 sequencerName,
                                                 repository.name(),
                                                 work.getInputPath(),
                                                 work.getInputWorkspaceName(),
                                                 work.getOutputPath(),
                                                 work.getOutputWorkspaceName() != null ? work.getOutputWorkspaceName() : work.getInputWorkspaceName());
                LOGGER.debug("Running {0}", logMsg);
            }

            // Find the selected node ...
            AbstractJcrNode selectedNode = inputSession.getNode(work.getSelectedPath());

            // Find the input that has changed and is to be sequenced ...
            Item inputItem = inputSession.getItem(work.getInputPath());
            Property changedProperty = null;
            if (inputItem instanceof Property) {
                changedProperty = (Property)inputItem;
            } else {
                Node changedNode = (Node)inputItem;
                // now look for a property that was changed or added ...
                changedProperty = changedNode.getProperty(work.getChangedPropertyName());
            }
            assert changedProperty != null;

            if (sequencer.hasAcceptedMimeTypes()) {
                // Get the MIME type, first by looking at the changed property's parent node
                // (or grand-parent node if parent is 'jcr:content') ...
                String mimeType = getInputMimeType(changedProperty);

                // See if the sequencer accepts the MIME type ...
                if (mimeType != null && !sequencer.isAccepted(mimeType)) {
                    LOGGER.debug("Skipping sequencing because MIME type of input doesn't match expectations for {0}", logMsg);
                    return; // nope
                }
            }

            AbstractJcrNode outputNode = null;
            String primaryType = null;
            if (work.getSelectedPath().equals(work.getOutputPath())) {
                // The output is to go directly under the sequenced node ...
                outputNode = selectedNode.getName().equals(JcrConstants.JCR_CONTENT) ? selectedNode.getParent() : selectedNode;
                primaryType = selectedNode.getPrimaryNodeType().getName();
            } else {
                // Find the parent of the output if it exists, or create the node(s) along the path if not ...
                AbstractJcrNode parentOfOutput = null;
                try {
                    parentOfOutput = outputSession.getNode(work.getOutputPath());
                } catch (PathNotFoundException e) {
                    LOGGER.trace("Creating missing output path for {0}", logMsg);
                    JcrTools tools = new JcrTools();
                    parentOfOutput = (AbstractJcrNode)tools.findOrCreateNode(outputSession, work.getOutputPath());
                }

                // Now determine the name of top node in the output, using the last segment of the selected path ...
                String outputNodeName = computeOutputNodeName(selectedNode);

                // Remove any existing output (from a prior sequencing run on this same input) ...
                removeExistingOutputNodes(parentOfOutput, outputNodeName, work.getSelectedPath(), logMsg);

                // Create the output node
                if (parentOfOutput.isNew() && parentOfOutput.getName().equals(outputNodeName)) {
                    // avoid creating a duplicate path with the same name
                    outputNode = parentOfOutput;
                } else {
                    if (TRACE) {
                        LOGGER.trace("Creating output node '{0}' under parent '{1}' for {2}", outputNodeName,
                                     parentOfOutput.getPath(), logMsg);
                    }
                    outputNode = parentOfOutput.addNode(outputNodeName, JcrConstants.NT_UNSTRUCTURED);
                }

                // and make sure the output node has the 'mode:derived' mixin ...
                outputNode.addMixin(DERIVED_NODE_TYPE_NAME);
                outputNode.setProperty(DERIVED_FROM_PROPERTY_NAME, work.getSelectedPath());
            }

            // Execute the sequencer ...
            DateTime now = outputSession.dateFactory().create();
            Sequencer.Context context = new SequencingContext(now, outputSession.getValueFactory());
            if (inputSession.isLive() && (inputSession == outputSession || outputSession.isLive())) {
                final long start = System.nanoTime();

                try {
                    LOGGER.trace("Executing {0}", logMsg);
                    if (sequencer.execute(changedProperty, outputNode, context)) {
                        LOGGER.trace("Completed executing {0}", logMsg);

                        // Make sure that the sequencer did not change the primary type of the selected node ..
                        if (selectedNode == outputNode && !selectedNode.getPrimaryNodeType().getName().equals(primaryType)) {
                            String msg = RepositoryI18n.sequencersMayNotChangeThePrimaryTypeOfTheSelectedNode.text();
                            throw new RepositoryException(msg);
                        }

                        // find the new nodes created by the sequencing before saving, so we can properly fire the events
                        List<AbstractJcrNode> outputNodes = findOutputNodes(outputNode);

                        // set the createdBy property (if it applies) to the user which triggered the sequencing, not the context
                        // of the saving session
                        setCreatedByIfNecessary(outputSession, outputNodes);

                        // outputSession
                        LOGGER.trace("Saving session used by {0}", logMsg);
                        outputSession.save();

                        // fire the sequencing event after save (hopefully by this time the transaction has been committed)
                        LOGGER.trace("Firing events resulting from {0}", logMsg);
                        fireSequencingEvent(selectedNode, outputNodes, outputSession, sequencerName);

                        long durationInNanos = Math.abs(System.nanoTime() - start);
                        Map<String, String> payload = new HashMap<String, String>();
                        payload.put("sequencerName", sequencer.getClass().getName());
                        payload.put("sequencedPath", changedProperty.getPath());
                        payload.put("outputPath", outputNode.getPath());
                        stats.recordDuration(DurationMetric.SEQUENCER_EXECUTION_TIME, durationInNanos, TimeUnit.NANOSECONDS,
                                             payload);
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.