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

Quick Search    Search Deep

Source code: qt/QTPlayer.java


1   /*
2   
3   < This Java Class is part of the jMusic API Version 2000.11>
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 qt;
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      private static QTUtil qtu;
38      
39      // constructor  
40      public QTPlayer() {}
41      
42      /**
43      * Open a visual Player to play the score using Quicktime
44      * This method is called most often, as in QT.play(score);
45      * @param Score
46      */
47      public static void display(Score s) {
48          display(s, 0, 300);
49      }
50      /**
51      * Open a visual Player to Play the score using Quicktime
52      * @param Score
53      * @param int - the left-right location of the window
54      * @param int - the up-down location of the window
55      */
56      public static void display(Score s, int xLoc, int yLoc) {
57          Frame f = new Frame("jMusic Playback");
58          // check if score is empty - if so add a note
59          checkScore(s);
60          qtu = new QTUtil(s);
61          QTPanel qtp = new QTPanel(qtu, s);
62          f.add(qtp,"North");
63          
64          f.setLocation(xLoc,yLoc);
65          /*addWindowListener (new java.awt.event.WindowAdapter () {
66              public void windowClosing (java.awt.event.WindowEvent evt) {
67                 f.dispose();
68              }
69          )
70          }; */
71          f.pack();
72          f.show();
73      }
74      
75      /**
76      * Open a visual Player to Play the score using Quicktime
77      */
78      public static void play(Score s) {
79          QTUtil qtu = new QTUtil(s);
80          qtu.playback(s);
81      }
82      
83      /**
84      * put a note in any empty score so we don't crash
85      * - A hack - woops!
86      */
87      private static void checkScore(Score s) {
88          if (s.size() == 0) { // add a note
89              Note n = new Note(0, 1.0, 0);
90              Phrase phr = new Phrase();
91              phr.addNote(n);
92              Part p = new Part();
93              p.addPhrase(phr);
94              s.addPart(p);
95          }
96      }
97  }