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

Quick Search    Search Deep

Source code: qt/QTPanel.java


1   /*
2   
3   < This Java Class is part of the jMusic API Version 2000.10>
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  
29  /**
30   * A class which plays a jMusic score via Apple's QuickTime.
31   * It requires the QTJava classes.
32   * @author Andrew Brown
33   */
34  
35  //send class
36  public class QTPanel extends Panel implements ActionListener, AdjustmentListener {  
37      private QTUtil qtu;
38      private Button b, b2;
39      private Scrollbar tempoScroll;
40      //private Label tempoReadout;
41      private Label tempoTitle;
42      private Score s;
43      
44      //-------------
45      //constructors
46      //-------------
47    public QTPanel(QTUtil qtu, Score score) { 
48        this.qtu = qtu;
49        this.s = score;
50        this.setLayout(new BorderLayout());
51        //title
52        Label text = new Label("QT Controls");
53        text.setAlignment(1);
54        this.add(text, "North");
55        // button panel
56        Panel bp = new Panel();
57        //create a button to start the tune playing
58        b = new Button ("Play");
59        b.addActionListener(this); //(new ActionListener () {
60        bp.add(b);
61        
62        //create a button to stop the tune playing
63        b2 = new Button ("Stop");
64        b2.addActionListener(this);
65        bp.add (b2);
66        
67        this.add(bp, "Center");
68        // tempo panel
69        Panel tp = new Panel();
70        tp.setLayout(new BorderLayout());
71        tempoTitle = new Label("Tempo: "+(int)(60*qtu.getSpeed())+ " bpm");
72        tempoTitle.setAlignment(1);
73        tp.add(tempoTitle, "North");
74        // tempo slider
75        tempoScroll = new Scrollbar(0, (int)(60*qtu.getSpeed()), 1, 20, 301);
76        tempoScroll.addAdjustmentListener(this);
77        tp.add(tempoScroll, "Center");
78        // tempo readout
79        //tempoReadout = new Label("120");
80        //tempoReadout.setAlignment(1);
81        //tp.add( tempoReadout, "South");
82        this.add(tp, "South");
83      }
84          
85    //-------------------
86    // Auxillary methods
87    //-------------------
88      public void setQTUtil(QTUtil qtu) {
89          this.qtu = qtu;
90      }
91    
92    //--------------------------------------
93      public void actionPerformed(ActionEvent e){
94          Object obj = e.getSource();
95        
96          if (obj == b) {
97             qtu.playback(s);
98          }
99          if (obj == b2) {
100             qtu.stopPlayback();
101         }
102     }
103     
104     //--------------------------------------
105     public void adjustmentValueChanged(AdjustmentEvent e) {
106         tempoTitle.setText( "Tempo: " + Integer.toString(tempoScroll.getValue())+ " bpm");
107         qtu.setSpeed( (double)tempoScroll.getValue()/60.0);
108         s.setTempo( tempoScroll.getValue());
109     }
110 
111 }