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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/song/util/NoteMaker.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.3 hardy)
  • Revision ID: james.westby@ubuntu.com-20080619003030-agens2gvd5m4dacu
New upstream release (Closes: #481728) also (LP: #176979, #212207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.herac.tuxguitar.song.util;
2
 
 
3
 
import java.util.ArrayList;
4
 
import java.util.List;
5
 
 
6
 
import org.herac.tuxguitar.song.managers.SongManager;
7
 
import org.herac.tuxguitar.song.models.InstrumentString;
8
 
 
9
 
public class NoteMaker {
10
 
        private static final int MAX_DISTANCE = 4;
11
 
        
12
 
        public static void main(String[] s){
13
 
                new NoteMaker();
14
 
                System.exit(0);
15
 
        }
16
 
        
17
 
        public NoteMaker(){             
18
 
                int[] values = new int[]{69,79,56,52,47,40};    
19
 
                getStringsForValues(SongManager.createDefaultInstrumentStrings(),values);               
20
 
        }
21
 
        
22
 
        
23
 
        public void getStringsForValues(List strings,int[] values){
24
 
                List tempStrings = new ArrayList();
25
 
                tempStrings.addAll(strings);
26
 
                                        
27
 
                for(int i = 0;i < values.length;i ++){
28
 
                        int string = getStringForValue(tempStrings,values[i]);
29
 
                        for(int j = 0;j < tempStrings.size();j ++){
30
 
                                InstrumentString tempString = (InstrumentString)tempStrings.get(j);     
31
 
                                if(tempString.getNumber() == string){
32
 
                                        tempStrings.remove(j);
33
 
                                        break;
34
 
                                }
35
 
                        }
36
 
                }
37
 
                
38
 
        }
39
 
 
40
 
        public int getStringForValue(List strings,int value){
41
 
                int minFret = -1;
42
 
                int stringForValue = 0;
43
 
                for(int i = 0;i < strings.size();i++){
44
 
                        InstrumentString string = (InstrumentString)strings.get(i);                                             
45
 
                        int fret = value - string.getValue();                   
46
 
                        if(minFret < 0 || (fret >= 0 && fret < minFret)){
47
 
                                stringForValue = string.getNumber();
48
 
                                minFret = fret;                         
49
 
                        }
50
 
                }               
51
 
                
52
 
                System.out.println("String: " + stringForValue + " Fret: " + minFret + " ");            
53
 
                
54
 
                
55
 
                return stringForValue;
56
 
        }
57
 
}
58
 
 
59