~ubuntu-branches/ubuntu/lucid/tuxguitar/lucid-security

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.herac.tuxguitar.player.impl.sequencer;

import java.util.ArrayList;
import java.util.List;

import org.herac.tuxguitar.player.base.MidiPlayerException;

public class MidiTrackController {
	
	
	private List tracks;
	private MidiSequencerImpl sequencer;
	private boolean anySolo;
	
	public MidiTrackController(MidiSequencerImpl sequencer){
		this.sequencer = sequencer;
		this.tracks = new ArrayList();
		this.anySolo = false;
	}
	
	public void init(int count){
		this.tracks.clear();
		for(int i = 0; i < count; i ++){
			this.tracks.add(new MidiTrack());
		}
	}
	
	public void clearTracks(){
		this.tracks.clear();
	}
	
	public void checkAnySolo(){
		this.anySolo = false;
		for(int i = 0; i < this.tracks.size(); i ++){
			MidiTrack track = (MidiTrack)this.tracks.get(i);
			if(track.isSolo()){
				this.anySolo = true;
				break;
			}
		}
	}
	
	public void setSolo(int index,boolean solo) throws MidiPlayerException{
		if(index >= 0 && index < this.tracks.size()){
			MidiTrack track = (MidiTrack)this.tracks.get(index);
			track.setSolo(solo);
			checkAnySolo();
			if(track.isSolo()){
				setMute(index,false);
				this.sequencer.getMidiPort().out().sendAllNotesOff();
			}
		}
	}
	
	public void setMute(int index,boolean mute) throws MidiPlayerException{
		if(index >= 0 && index < this.tracks.size()){
			MidiTrack track = (MidiTrack)this.tracks.get(index);
			track.setMute(mute);
			if(track.isMute()){
				setSolo(index,false);
				this.sequencer.getMidiPort().out().sendAllNotesOff();
			}
		}
	}
	
	public boolean isSolo(int index){
		if(index >= 0 && index < this.tracks.size()){
			MidiTrack track = (MidiTrack)this.tracks.get(index);
			return track.isSolo();
		}
		return false;
	}
	
	public boolean isMute(int index){
		if(index >= 0 && index < this.tracks.size()){
			MidiTrack track = (MidiTrack)this.tracks.get(index);
			return track.isMute();
		}
		return false;
	}
	
	public boolean isAnySolo(){
		return this.anySolo;
	}
}