-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFiducial.pde
114 lines (96 loc) · 3.05 KB
/
Fiducial.pde
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import themidibus.*;
public class Fiducial {
private int id, channel;
private float rotation;
private int[] scale;
private MidiBus midiBus;
private Note midiBusNote;
private int note;
private PVector position;
private int lastUpdatedTick;
public boolean readyToProduceSound;
private int channelOfDrums = 5;
public Fiducial(int id){
this.id = id;
}
public Fiducial(int id, PVector position, float rotation, int tick, MidiBus midiBus) {
this.id = id;
this.note = 60;
this.midiBusNote = new Note(0, 60, 127);
this.scale = ScalesEnum.MAJOR.scale;
this.rotation = rotation;
this.mapNoteFromRotation(true, 0);
this.extraSettings(position, tick);
this.midiBus = midiBus;
}
public void extraSettings(PVector position, int tick) {
this.position = position;
this.lastUpdatedTick = tick;
this.readyToProduceSound = false;
}
public int getId() {
return this.id;
}
public void play() {
this.midiBus.sendNoteOn(this.channel, this.note, 127);
this.midiBus.sendNoteOff(this.channel, this.note, 127);
}
private void mapNoteFromRotation(boolean first, float rotation) {
if ( this.channel < this.channelOfDrums ) {
this.mapNoteForSynth(first, rotation);
} else {
this.mapNoteForDrums(rotation);
}
}
private void mapNoteForDrums(float rotation) {
int mapRotation = (int)map(this.rotation, 0, 360, 0, this.scale.length);
this.note = scale[mapRotation];
this.midiBusNote.setPitch(this.note);
}
private void mapNoteForSynth(boolean first, float rotation) {
if ( first ) {
int mapRotation = (int)map(this.rotation, 0, 360, 0, this.scale.length);
this.note = 60 + scale[mapRotation];
this.midiBusNote.setPitch(this.note);
}
if ( rotation < this.rotation ) {
int mapRotation = (int)map(this.rotation, 0, 360, 0, this.scale.length);
this.midiBusNote.setPitch(this.note);
this.note = 60 - scale[mapRotation];
} else {
int mapRotation = (int)map(this.rotation, 0, 360, 0, this.scale.length);
this.midiBusNote.setPitch(this.note);
this.note = 60 + scale[mapRotation];
}
}
public void updatePosition( PVector newPosition, int newTick ) {
if ( this.lastUpdatedTick != newTick ) {
if ( newPosition.x == this.position.x && newPosition.y == this.position.y ) {
this.position = newPosition;
this.readyToProduceSound = true;
this.lastUpdatedTick = newTick;
} else {
extraSettings(newPosition, newTick);
}
}
}
public void updateRotation( float rotation ) {
this.rotation = rotation;
this.mapNoteFromRotation(false, this.rotation);
}
public void setChannel(int channel) {
this.channel = channel;
if ( this.channel > this.channelOfDrums ) {
this.scale = ScalesEnum.DRUMS.scale;
}
}
@Override
public boolean equals( Object o ) {
Fiducial other = (Fiducial)o;
return other.getId() == this.id;
}
@Override
public String toString() {
return this.midiBusNote.name();
}
}