PonyTracker
Un projet de tracker de musique
 Tout Structures de données Espaces de nommage Fichiers Fonctions Variables Définitions de type Énumérations Valeurs énumérées Macros Pages
main.c
Aller à la documentation de ce fichier.
1 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <gtk/gtk.h>
24 #include <string.h>
25 
26 #include "motifs/motifs.h"
27 #include "melodie/melodie.h"
28 #include "samples/samples.h"
30 #include "lecture/lecture.h"
31 //#include <SDL2/SDL.h>
32 //#include <SDL2/SDL_mixer.h>
33 //#include <SDL2/SDL_main.h>
34 
35 #define DEF_NBR_TMP 16
36 #define MAX_PATTERNS 256
37 #define NBR_INST 10
38 #define NBR_SMPL 5
39 
40 // Variables globales
42 Motif* liste = NULL;
44 Sample* smpl[NBR_SMPL] = {NULL};
45 int nbrPortees = 1;
46 int taille;
47 
48 GtkBuilder *monBuilder;
49 char *Do="Do";
50 char *DoD="Do#";
51 char *Re="Re";
52 char *ReD="Re#";
53 char *Mi="Mi";
54 char *Fa="Fa";
55 char *FaD="Fa#";
56 char *Sol="Sol";
57 char *SolD="Sol#";
58 char *La="La";
59 char *LaD="La#";
60 char *Si="Si";
61 char *N1="1";
62 char *N2="2";
63 char *N3="3";
64 char *N4="4";
65 char *N5="5";
66 
67 
68 // Fonctions de débug
69 
71  printf("%s :\n",m->nom);
72  for (int tmp = 0; tmp < m->nbrTmp; tmp++){
73  for (int portee = 0; portee < nbrPortees; portee++){
74  printf("%d ",getNote(m,portee,tmp));
75  }
76  printf("\n");
77  }
78 }
79 
80 // Fin des fonctions de débug
81 
82 void debut(Motif* melodie[], Instrument* inst[], Sample* smpl[], Motif* liste, int nbrPortees){
83  ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
84  Motif* m = liste;
85 
86  int i;
87 
88  // En guise d'exemple, voici la mélodie du générique de My Little Pony : Friendship is Magic.
89 
90  // My Little Pony.
91 
92  for (i = 0; i < DEF_NBR_TMP; i++) {
93  definirNote(m,0,i,-1);
94  definirOctave(m,0,i,3);
95  }
96 
97  definirNote(m,0,0,1);
98  definirInstrument(m,0,0,0);
99  definirInstrument(m,0,2,-1);
100  definirNote(m,0,4,0);
101  definirInstrument(m,0,4,0);
102  definirNote(m,0,5,1);
103  definirInstrument(m,0,5,0);
104  definirInstrument(m,0,6,-1);
105  definirNote(m,0,7,3);
106  definirInstrument(m,0,7,0);
107  definirInstrument(m,0,8,-1);
108  definirNote(m,0,9,1);
109  definirInstrument(m,0,9,0);
110  definirInstrument(m,0,12,-1);
111 
112  ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
113  Motif* n = liste;
114 
115  // I used to wonder what friendship could be.
116 
117  for (i = 0; i < DEF_NBR_TMP; i++) {
118  definirNote(n,0,i,-1);
119  definirOctave(n,0,i,3);
120  }
121 
122  definirNote(n,0,1,5);
123  definirInstrument(n,0,1,0);
124  definirNote(n,0,2,5);
125  definirInstrument(n,0,2,0);
126  definirNote(n,0,3,5);
127  definirInstrument(n,0,3,0);
128  definirNote(n,0,4,5);
129  definirInstrument(n,0,4,0);
130  definirInstrument(n,0,5,-1);
131  definirNote(n,0,6,1);
132  definirInstrument(n,0,6,0);
133  definirNote(n,0,7,3);
134  definirInstrument(n,0,7,0);
135  definirInstrument(n,0,8,-1);
136  definirNote(n,0,9,1);
137  definirInstrument(n,0,9,0);
138  definirInstrument(n,0,10,-1);
139  definirNote(n,0,11,5);
140  definirInstrument(n,0,11,0);
141  definirInstrument(n,0,12,-1);
142  definirNote(n,0,13,3);
143  definirInstrument(n,0,13,0);
144  definirInstrument(n,0,14,-1);
145  definirNote(n,0,15,1);
146  definirInstrument(n,0,15,0);
147 
148  ajouterMotif(&liste, DEF_NBR_TMP, nbrPortees);
149  Motif* p = liste;
150 
151  // Until you all shared its magic with me.
152 
153  for (i = 0; i < DEF_NBR_TMP; i++) {
154  definirNote(p,0,i,-1);
155  definirOctave(p,0,i,3);
156  }
157 
158  definirNote(p,0,0,5);
159  definirInstrument(p,0,0,0);
160  definirNote(p,0,1,8);
161  definirInstrument(p,0,1,0);
162  definirInstrument(p,0,2,-1);
163  definirNote(p,0,3,8);
164  definirInstrument(p,0,3,0);
165  definirInstrument(p,0,4,-1);
166  definirNote(p,0,5,5);
167  definirInstrument(p,0,5,0);
168  definirInstrument(p,0,6,-1);
169  definirNote(p,0,7,3);
170  definirInstrument(p,0,7,0);
171  definirInstrument(p,0,8,-1);
172  definirNote(p,0,9,1);
173  definirInstrument(p,0,9,0);
174  definirNote(p,0,10,5);
175  definirInstrument(p,0,10,0);
176  definirInstrument(p,0,11,-1);
177  definirNote(p,0,12,3);
178  definirInstrument(p,0,12,0);
179  definirInstrument(p,0,14,-1);
180 
181  ajouterMotifVirtuel(melodie,0,m);
182  ajouterMotifVirtuel(melodie,1,n);
183  ajouterMotifVirtuel(melodie,2,m);
184  ajouterMotifVirtuel(melodie,3,p);
185 
186  // Définir les instruments les samples
187 
188  ajouterSample(smpl,0,"lecture/0.wav");
189  setHauteur(smpl[0],440.0);
190 
191  ajouterInstrument(inst,0);
192  setSample(inst[0],smpl[0]);
193 }
194 
195 int main( int argc, char *argv[] ){
196  debut(melodie, inst, smpl, liste, nbrPortees);
197  Motif* m = melodie[0];
198  GtkWidget *maFenetre;
199  char str[20];
200  gtk_init( &argc, &argv );
201 
202  monBuilder = gtk_builder_new();
203 
204  gtk_builder_add_from_file( monBuilder, "GUI/ponytrackertest.glade", NULL);
205  gtk_builder_connect_signals( monBuilder, NULL);
206 
207  maFenetre = GTK_WIDGET( gtk_builder_get_object( monBuilder, "fenetreprincipale"));
208 
209  GtkButton *button = (GtkButton*) gtk_builder_get_object(monBuilder, "button16");
210  switch (getNote(m,0,0)) {
211  case 0 :
212  strcpy(str,"Do ");
213  break;
214  case 1 :
215  strcpy(str,"Do# ");
216  break;
217  case 2 :
218  strcpy(str,"Re ");
219  break;
220  case 3 :
221  strcpy(str,"Re# ");
222  break;
223  case 4 :
224  strcpy(str,"Mi ");
225  break;
226  case 5 :
227  strcpy(str,"Fa ");
228  break;
229  case 6 :
230  strcpy(str,"Fa# ");
231  break;
232  case 7 :
233  strcpy(str,"Sol ");
234  break;
235  case 8 :
236  strcpy(str,"Sol# ");
237  break;
238  case 9 :
239  strcpy(str,"La ");
240  break;
241  case 10 :
242  strcpy(str,"La# ");
243  break;
244  case 11 :
245  strcpy(str,"Si ");
246  break;
247  default :
248  break;
249  }
250 
251  printf("%d\n",getOctave(m,0,0));
252 
253  switch (getOctave(m,0,0)) {
254  case 0 :
255  strcat(str, "0 ");
256  break;
257  case 1 :
258  strcat(str, "1 ");
259  break;
260  case 2 :
261  strcat(str, "2 ");
262  break;
263  case 3 :
264  strcat(str, "3 ");
265  break;
266  case 4 :
267  strcat(str, "4 ");
268  break;
269  default :
270  break;
271  }
272 
273  switch (getInstrument(m,0,0)) {
274  case 0 :
275  strcat(str, "0 ");
276  break;
277  case 1 :
278  strcat(str, "1 ");
279  break;
280  case 2 :
281  strcat(str, "2 ");
282  break;
283  case 3 :
284  strcat(str, "3 ");
285  break;
286  case 4 :
287  strcat(str, "4 ");
288  break;
289  default :
290  break;
291  }
292 
293  switch (getVolume(m,0,0)) {
294  case 0 :
295  strcat(str, "0 ");
296  break;
297  case 1 :
298  strcat(str, "1 ");
299  break;
300  case 2 :
301  strcat(str, "2 ");
302  break;
303  case 3 :
304  strcat(str, "3 ");
305  break;
306  case 4 :
307  strcat(str, "4 ");
308  break;
309  default :
310  break;
311  }
312 
313  switch (getEffet(m,0,0)) {
314  case 0 :
315  strcat(str, "0 ");
316  break;
317  case 1 :
318  strcat(str, "1 ");
319  break;
320  case 2 :
321  strcat(str, "2 ");
322  break;
323  case 3 :
324  strcat(str, "3 ");
325  break;
326  case 4 :
327  strcat(str, "4 ");
328  break;
329  default :
330  break;
331  }
332 
333  gtk_button_set_label(button, str);
334 
335  gtk_widget_show_all (maFenetre);
336  gtk_main();
337  return EXIT_SUCCESS;
338 }
339 
340 void fenetreSample ( int argc, char *argv[] )
341 {
342 
343  GtkWidget *maFenetreSample = GTK_WIDGET( gtk_builder_get_object( monBuilder, "ajoutsample"));
344 
345  gtk_widget_show_all (maFenetreSample);
346 }
347 
348 void fenetreInstrument ( int argc, char *argv[] )
349 {
350  GtkWidget *maFenetreInstrument = GTK_WIDGET( gtk_builder_get_object( monBuilder, "ajoutinstrument"));
351 
352  gtk_widget_show_all (maFenetreInstrument);
353 }
354 
355 void fenetreMotif ( int argc, char *argv[] )
356 {
357  GtkWidget *maFenetreMotif = GTK_WIDGET( gtk_builder_get_object( monBuilder, "ajoutmotif"));
358 
359  gtk_widget_show_all (maFenetreMotif);
360 }
361 
362 void fenetreNote ( int argc, char *argv[] )
363 {
364  GtkWidget *maFenetreNote = GTK_WIDGET( gtk_builder_get_object( monBuilder, "ajoutnote"));
365 
366  gtk_widget_show_all (maFenetreNote);
367 }
368 
369 void remplissageNote (GtkWidget *widget, gpointer *data){
370 
371  Motif* m = melodie[0];
372 
373  GtkEntry *entryNote = (GtkEntry*) gtk_builder_get_object(monBuilder,"combonote");
374  GtkEntry *entryOctave = (GtkEntry*) gtk_builder_get_object(monBuilder,"combooctave");
375  GtkEntry *entryInstrument = (GtkEntry*) gtk_builder_get_object(monBuilder,"comboinstrument");
376  GtkEntry *entryVolume = (GtkEntry*) gtk_builder_get_object(monBuilder,"combovolume");
377  GtkEntry *entryEffet = (GtkEntry*) gtk_builder_get_object(monBuilder,"comboeffet");
378 
379  const char *strnote = gtk_entry_get_text(GTK_ENTRY(entryNote));
380  const char *stroctave = gtk_entry_get_text(GTK_ENTRY(entryOctave));
381  const char *strinstrument = gtk_entry_get_text(GTK_ENTRY(entryInstrument));
382  const char *strvolume = gtk_entry_get_text(GTK_ENTRY(entryVolume));
383  const char *streffet = gtk_entry_get_text(GTK_ENTRY(entryEffet));
384 
385  if (strcmp(Do,strnote)==0) definirNote(m,0,0,1);
386  else
387  if (strcmp(DoD,strnote)==0) definirNote(m,0,0,2);
388  else
389  if (strcmp(Re,strnote)==0) definirNote(m,0,0,3);
390  else
391  if (strcmp(ReD,strnote)==0) definirNote(m,0,0,4);
392  else
393  if (strcmp(Mi,strnote)==0) definirNote(m,0,0,5);
394  else
395  if (strcmp(Fa,strnote)==0) definirNote(m,0,0,6);
396  else
397  if (strcmp(FaD,strnote)==0) definirNote(m,0,0,7);
398  else
399  if (strcmp(Sol,strnote)==0) definirNote(m,0,0,8);
400  else
401  if (strcmp(SolD,strnote)==0) definirNote(m,0,0,9);
402  else
403  if (strcmp(La,strnote)==0) definirNote(m,0,0,10);
404  else
405  if (strcmp(LaD,strnote)==0) definirNote(m,0,0,11);
406  else
407  if (strcmp(Si,strnote)==0) definirNote(m,0,0,12);
408 
409  if (strcmp(N1,stroctave)==0) definirOctave(m,0,0,1);
410  else
411  if (strcmp(N2,stroctave)==0) definirOctave(m,0,0,2);
412  else
413  if (strcmp(N3,stroctave)==0) definirOctave(m,0,0,3);
414  else
415  if (strcmp(N4,stroctave)==0) definirOctave(m,0,0,4);
416  else
417  if (strcmp(N5,stroctave)==0) definirOctave(m,0,0,5);
418 
419  if (strcmp(N1,strinstrument)==0) definirInstrument(m,0,0,1);
420  else
421  if (strcmp(N2,strinstrument)==0) definirInstrument(m,0,0,2);
422  else
423  if (strcmp(N3,strinstrument)==0) definirInstrument(m,0,0,3);
424  else
425  if (strcmp(N4,strinstrument)==0) definirInstrument(m,0,0,4);
426  else
427  if (strcmp(N5,strinstrument)==0) definirInstrument(m,0,0,5);
428 
429  if (strcmp(N1,strvolume)==0) definirVolume(m,0,0,1);
430  else
431  if (strcmp(N2,strvolume)==0) definirVolume(m,0,0,2);
432  else
433  if (strcmp(N3,strvolume)==0) definirVolume(m,0,0,3);
434  else
435  if (strcmp(N4,strvolume)==0) definirVolume(m,0,0,4);
436  else
437  if (strcmp(N5,strvolume)==0) definirVolume(m,0,0,5);
438 
439  if (strcmp(N1,streffet)==0) definirEffet(m,0,0,1);
440  else
441  if (strcmp(N2,streffet)==0) definirEffet(m,0,0,2);
442  else
443  if (strcmp(N3,streffet)==0) definirEffet(m,0,0,3);
444  else
445  if (strcmp(N4,streffet)==0) definirEffet(m,0,0,4);
446  else
447  if (strcmp(N5,streffet)==0) definirEffet(m,0,0,5);
448 }
449 
451 {
452 
453  //courant = 0;
454  //taille = 0;
455  printf("%d\n",nbrPortees);
456  //debut(melodie, inst, smpl, liste, nbrPortees);
457  lecture(nbrPortees,1,480,inst,melodie);
458 }
459 
460 void quitter ()
461 {
462  gtk_main_quit();
463 }
464 
465 void refresh(){}
int main(int argc, char *argv[])
Definition: main.c:195
int getInstrument(Motif *m, int portee, int tmp)
Definition: motifs.c:85
void ajouterMotif(Motif **pliste, int nbrTmp, int nbrPortees)
Definition: motifs.c:22
Sample * smpl[NBR_SMPL]
Definition: main.c:44
int getNote(Motif *m, int portee, int tmp)
Definition: motifs.c:77
void refresh()
Definition: main.c:465
Instrument * inst[NBR_INST]
Definition: main.c:43
char nom[10]
Definition: motifs.h:32
Motif * m
Definition: maintest.c:13
GtkBuilder * monBuilder
Definition: main.c:48
char * Sol
Definition: main.c:56
char * N2
Definition: main.c:62
char * Re
Definition: main.c:51
int getEffet(Motif *m, int portee, int tmp)
Definition: motifs.c:93
void ajouterSample(Sample *tab[], int i, char *chemin)
Definition: samples.c:13
void remplissageNote(GtkWidget *widget, gpointer *data)
Definition: main.c:369
Definition: motifs.h:31
char * DoD
Definition: main.c:50
void definirOctave(Motif *m, int portee, int tmp, int octave)
Definition: motifs.c:57
char * N4
Definition: main.c:64
void quitter()
Definition: main.c:460
char * N3
Definition: main.c:63
#define MAX_PATTERNS
Definition: main.c:36
char * ReD
Definition: main.c:52
#define NBR_SMPL
Definition: main.c:38
int taille
Definition: main.c:46
void fenetreSample(int argc, char *argv[])
Definition: main.c:340
char * LaD
Definition: main.c:59
#define DEF_NBR_TMP
Definition: main.c:35
void definirNote(Motif *m, int portee, int tmp, int note)
Definition: motifs.c:53
char * La
Definition: main.c:58
int nbrTmp
Definition: motifs.h:33
void fenetreInstrument(int argc, char *argv[])
Definition: main.c:348
Motif * liste
Definition: main.c:42
char * N5
Definition: main.c:65
void afficherMotif(Motif *m, int nbrPortees)
Definition: main.c:70
void setHauteur(Sample *sample, float hauteur)
Definition: samples.c:27
char * Si
Definition: main.c:60
char * Do
Definition: main.c:49
char * N1
Definition: main.c:61
#define NBR_INST
Definition: main.c:37
int getVolume(Motif *m, int portee, int tmp)
Definition: motifs.c:89
void lecture(int nombreChaines, int nombreInst, int tempo, Instrument *inst[], Motif *melodie[])
Definition: lecture.c:46
char * Fa
Definition: main.c:54
char * Mi
Definition: main.c:53
void fenetreNote(int argc, char *argv[])
Definition: main.c:362
void ajouterMotifVirtuel(Motif *melodie[], int ind, Motif *m)
Definition: melodie.c:19
void fenetreMotif(int argc, char *argv[])
Definition: main.c:355
char * SolD
Definition: main.c:57
void ajouterInstrument(Instrument *tab[], int i)
Definition: instruments.c:13
int nbrPortees
Definition: main.c:45
void debut(Motif *melodie[], Instrument *inst[], Sample *smpl[], Motif *liste, int nbrPortees)
Definition: main.c:82
void definirEffet(Motif *m, int portee, int tmp, int effet)
Definition: motifs.c:69
char * FaD
Definition: main.c:55
FMOD_TAGTYPE char void * data
Definition: fmod_codec.h:26
Motif * melodie[MAX_PATTERNS]
Definition: main.c:41
void lancerLecture()
Definition: main.c:450
void setSample(Instrument *inst, Sample *smpl)
Definition: instruments.c:54
void definirInstrument(Motif *m, int portee, int tmp, int instrument)
Definition: motifs.c:61
void definirVolume(Motif *m, int portee, int tmp, int volume)
Definition: motifs.c:65
int getOctave(Motif *m, int portee, int tmp)
Definition: motifs.c:81