~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/song/models/effects/TGEffectBend.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on 26-dic-2005
 
3
 *
 
4
 * TODO To change the template for this generated file go to
 
5
 * Window - Preferences - Java - Code Style - Code Templates
 
6
 */
 
7
package org.herac.tuxguitar.song.models.effects;
 
8
 
 
9
import java.util.ArrayList;
 
10
import java.util.Iterator;
 
11
import java.util.List;
 
12
 
 
13
import org.herac.tuxguitar.song.factory.TGFactory;
 
14
 
 
15
/**
 
16
 * @author julian
 
17
 *
 
18
 * TODO To change the template for this generated type comment go to
 
19
 * Window - Preferences - Java - Code Style - Code Templates
 
20
 */
 
21
public abstract class TGEffectBend {
 
22
        public static final int SEMITONE_LENGTH = 1;
 
23
        public static final int MAX_POSITION_LENGTH = 12;
 
24
        public static final int MAX_VALUE_LENGTH = (SEMITONE_LENGTH * 12);
 
25
        
 
26
        private List points;
 
27
        
 
28
        public TGEffectBend(){
 
29
                this.points = new ArrayList();
 
30
        }
 
31
        
 
32
        public void addPoint(int position,int value){
 
33
                this.points.add(new BendPoint(position,value));
 
34
        }
 
35
        
 
36
        public List getPoints(){
 
37
                return this.points;
 
38
        }
 
39
        
 
40
        public TGEffectBend clone(TGFactory factory){
 
41
                TGEffectBend effect = factory.newEffectBend();
 
42
                Iterator it = getPoints().iterator();
 
43
                while(it.hasNext()){
 
44
                        BendPoint point = (BendPoint)it.next();
 
45
                        effect.addPoint(point.getPosition(),point.getValue());
 
46
                }
 
47
                return effect;
 
48
        }
 
49
        
 
50
        public class BendPoint{
 
51
                private int position;
 
52
                private int value;
 
53
                
 
54
                public BendPoint(int position,int value){
 
55
                        this.position = position;
 
56
                        this.value = value;
 
57
                }
 
58
                
 
59
                public int getPosition() {
 
60
                        return this.position;
 
61
                }
 
62
                
 
63
                public int getValue() {
 
64
                        return this.value;
 
65
                }
 
66
                
 
67
                public long getTime(long duration){
 
68
                        return (duration * getPosition() / MAX_POSITION_LENGTH);
 
69
                }
 
70
                
 
71
                public Object clone(){
 
72
                        return new BendPoint(getPosition(),getValue());
 
73
                }
 
74
        }
 
75
        
 
76
}