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

Quick Search    Search Deep

Source code: jmqt/QTTrebleStaveActionHandler.java


1   /*
2   
3   <This Java Class is part of the jMusic API version 1.4, February 2003.>
4   
5   Copyright (C) 2000 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  
31  public class QTTrebleStaveActionHandler implements JMC, MouseMotionListener {
32      private int clickedPosY, clickedPosX, selectedNote = -1;
33      private QTTrebleStave theApp;
34      
35      // constructor
36    QTTrebleStaveActionHandler(QTTrebleStave stave) {
37      theApp = stave;
38      // allow for negative rv's as a rest flag
39    }
40  
41      //mouseMotionListener stubs
42    public void mouseMoved(MouseEvent e) {}
43  
44    public void mousePressed(MouseEvent e) { 
45        // no notes yet?
46      Integer lastX;
47      if (theApp.notePositions.size() < 2) {
48        lastX =  new Integer(theApp.getTotalBeatWidth() );
49        
50      } else {
51        lastX = (Integer)theApp.notePositions.elementAt(theApp.notePositions.size() -2);
52        
53      }
54        if(e.getX() > (lastX.intValue() + 15) && e.getX() < theApp.getTotalBeatWidth() + 50) { 
55            theApp.playCurrentNote(selectedNote);
56            Phrase phr = theApp.getPhrase();
57            selectedNote = phr.size()-1;
58            //theApp.playCurrentNote(selectedNote);
59        clickedPosY = e.getY()  + theApp.getStaveDelta();
60        clickedPosX = e.getX();
61        } else {
62        // check for a click on a note  - head?
63        for(int i=0;i< theApp.notePositions.size(); i += 2) {
64            Integer tempX = (Integer)theApp.notePositions.elementAt(i);
65          Integer tempY = (Integer)theApp.notePositions.elementAt(i+1);
66          if(e.getX() > tempX.intValue() && e.getX() < tempX.intValue() + 15 && e.getY() + 
67              theApp.getStaveDelta() > tempY.intValue() + 22 && e.getY() + 
68              theApp.getStaveDelta() < tempY.intValue() + 35) {
69            theApp.playCurrentNote(selectedNote);
70            //theApp.playCurrentNote(selectedNote);
71                clickedPosY = e.getY()  + theApp.getStaveDelta();
72                clickedPosX = e.getX();
73            }
74        }
75          }
76        
77        if (selectedNote < 0) {
78            for(int j=0;j< theApp.notePositions.size() - 2; j += 2) {
79                Integer tempX = (Integer)theApp.notePositions.elementAt(j);
80          Integer nextTempX = (Integer)theApp.notePositions.elementAt(j+2);
81          if(e.getX() > tempX.intValue() + 15 && e.getX() < nextTempX.intValue()) {
82                    theApp.playCurrentNote(selectedNote);
83                    //theApp.playCurrentNote(selectedNote);
84                clickedPosY = e.getY()  + theApp.getStaveDelta();
85                clickedPosX = e.getX();
86                }
87            }
88        }
89    }
90                    
91                    
92    public void mouseDragged(MouseEvent e) {
93      
94      // move note down
95      if(e.getY() + theApp.getStaveDelta() > clickedPosY + 2 && theApp.getPhrase().getNote(selectedNote).getPitch() != REST) { 
96          theApp.playCurrentNote(selectedNote);
97      }
98      
99      // move note up
100     if(e.getY() + theApp.getStaveDelta() < clickedPosY - 2  && theApp.getPhrase().getNote(selectedNote).getPitch() != REST) {
101         theApp.playCurrentNote(selectedNote); 
102     }
103     }
104     
105     public void mouseReleased(MouseEvent e) { }
106 }