Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jmqt/QTPlayer.java


1   /*
2   
3   <This Java Class is part of the jMusic API version 1.4, February 2003.>
4   
5   Copyright (C) 2000 Andrew Sorensen & Andrew Brown
6   
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2 of the License, or any
10  later version.
11  
12  This program is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16  
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  
21  */
22  
23  package jmqt;
24  
25  import java.awt.*;
26  import java.awt.event.*;
27  import jm.music.data.*;
28  import jm.JMC;
29   /**
30   * This class displays a window to control playback of a jMusic score via Apple's QuickTime.
31   * It requires the QTJava classes from Apple to be installed.
32   * Installing QTJava can be done as part of a 'custom' install of QuickTime.
33   * @author Andrew Brown
34   */
35  
36  public class QTPlayer  implements JMC {
37      
38      // constructor  
39      public QTPlayer() {    }
40      
41      /**
42      * Open a visual Player to play the score using Quicktime
43      * This method is called most often, as in QT.play(score);
44      * @param Score
45      */
46      public static void display(Score s) {
47          display(s, 0, 300);
48      }
49      /**
50      * Open a visual Player to Play the score using Quicktime
51      * @param Score
52      * @param int - the left-right location of the window
53      * @param int - the up-down location of the window
54      */
55      public static void display(Score s, int xLoc, int yLoc) {
56          Frame f = new Frame("jMusic Playback");
57          // check if score is empty - if so add a note
58          checkScore(s);
59          QTUtil qtu = new QTUtil(s);
60          QTPanel qtp = new QTPanel(qtu, s);
61          f.add(qtp,"North");
62          
63          f.setLocation(xLoc,yLoc);
64          /*addWindowListener (new java.awt.event.WindowAdapter () {
65              public void windowClosing (java.awt.event.WindowEvent evt) {
66                 f.dispose();
67              }
68          )
69          }; */
70          f.pack();
71          f.show();
72      }
73      
74      /**
75      * put a note in any empty score so we don't crash
76      * - A hack - woops!
77      */
78      private static void checkScore(Score s) {
79          if (s.size() == 0) { // add a note
80              Note n = new Note(REST, 1.0);
81              Phrase phr = new Phrase();
82              phr.addNote(n);
83              Part p = new Part();
84              p.addPhrase(phr);
85              s.addPart(p);
86          }
87      }
88  }