summaryrefslogtreecommitdiffstats
path: root/Processing-js/Draw.pde
blob: c0fb6852a25bf28f1b2791ba63ee03d2a835510b (plain)
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
/* Redéfinition de fonctions pour transformer les coordonnées relatives en coordonnées absolues */
void drect(float i, float j, float k, float l)
{
  rect(i*windowSize[0], j*windowSize[1], k*windowSize[0], l*windowSize[1]);
}

void dtriangle(float i, float j, float k, float l, float m, float n)
{
  triangle(i*windowSize[0], j*windowSize[1], k*windowSize[0], l*windowSize[1], m*windowSize[0], n*windowSize[1]);
}

void dellipse(float i, float j, float k, float l)
{
  ellipse(i*windowSize[0], j*windowSize[1], k*windowSize[0], l*windowSize[0]);
}

void dtext(String t, float x, float y)
{
  text(t, x*windowSize[0], y*windowSize[1]);
}

void dimage(PImage p, float i, float j, float k, float l)
{
  image(p, i*windowSize[0], j*windowSize[1], k*windowSize[0], l*windowSize[1]);
}
/* Fin de redéfinition des fonctions */

void drawKeyboard()
{
  stroke(0);
  // Dessine chaque octaves
  for (int j=0; j<numOctaves; j++) {
    fill(255);
    // Dessine les touches blanches
    for (int i=0; i<7; i++) {
      if (keysPressed[1][(j*7)+i] != 0) fill(0, 255, 0);
      drect((keyWidth[1]/numOctaves)*i+(float)j/numOctaves, keyboardYCoordinate, keyWidth[1]/(numOctaves), keyHeight[1]);
      fill(255,0,255);
      dtext(nomTouchesBlanches[i+(j*7)], 0.01+(keyWidth[1]/numOctaves)*i+(float)j/numOctaves, 0.962);
      fill(255);
    }
    fill(0);
    // Dessine les touches noires
    for (int i=0; i<keyXCoordinates.length; i++) {
      if (keysPressed[0][(j*5)+i] != 0) fill(255, 255, 0);
      drect((keyXCoordinates[i]/numOctaves)+(float)j/numOctaves, keyboardYCoordinate, keyWidth[0]/(numOctaves), keyHeight[0]);
      fill(255,0,255);
      dtext(nomTouchesNoires[i+(j*5)], 0.01+(keyXCoordinates[i]/numOctaves)+(float)j/numOctaves, keyboardYCoordinate+0.32);
      fill(0);
    }
  }
}

void drawDisplay() // Dessine l'affichage, appelé lors du lancement et après chaque clic.
{
  stroke(0);

 /* Bouton lecture */
  if (events[MUSICSTARTED]) fill(0, 0, 255); // Colorisation du bouton lecture si activé
  else fill(255);
  dellipse(playButtonCoordinates[0], playButtonCoordinates[1], buttonRadius*2, buttonRadius*2); // Contour
  fill(0);
  dtriangle(playButtonCoordinates[0]-0.01, playButtonCoordinates[1]-0.02, playButtonCoordinates[0]+0.02, playButtonCoordinates[1], playButtonCoordinates[0]-0.01, playButtonCoordinates[1]+0.02); // Logo lecture
  
   /* Bouton enregistrer */
  if(events[MUSICPLAYED])
  {
    if (events[RECORDINGSTARTED]) fill(255, 0, 0); // Colorisation du bouton enregistrer si activé
    else fill(255);
    dellipse(recordButtonCoordinates[0], recordButtonCoordinates[1], buttonRadius*2, buttonRadius*2); // Contour
    fill(0);
    dellipse(recordButtonCoordinates[0], recordButtonCoordinates[1], buttonRadius, buttonRadius); // Logo
  }

  if (!events[RECORDINGSTARTED] && events[RECORDINGSTOPPED] && score != -1)
  {
    fill(255,0,255);
    dtext("Score :" + Integer.toString(score), 0.86, 0.32); // Affichage du score
  }
  else
  {
    fill(255);
    stroke(255);
    drect(0.85, 0.25, 0.15, 0.10);
  }
}