Refonte majeure du code des motifs
This commit is contained in:
parent
fbf7f8b78b
commit
8c0b0337d1
|
@ -0,0 +1,9 @@
|
|||
#ifndef _melodie_h
|
||||
#define _melodie_h
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,35 +1,62 @@
|
|||
#include <string.h>
|
||||
#include "motifs.h"
|
||||
|
||||
int getIdMotif(Motif* m){
|
||||
if (m == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return getIdMotif(m->suivant)+1;
|
||||
}
|
||||
}
|
||||
|
||||
void ajouterMotif(int nbrPortees, int nbrTmp){
|
||||
Motif m = malloc(nbrPortees*sizeof(Portee));
|
||||
int i;
|
||||
for (i=0; i<nbrPortees; i++) {
|
||||
m[i] = malloc(nbrTmp*sizeof(Note));
|
||||
}
|
||||
Liste* l = malloc(sizeof(Liste));
|
||||
l->suivant = tab;
|
||||
tab = l;
|
||||
Motif* m = malloc(sizeof(Motif));
|
||||
m->nbrTmp = nbrTmp;
|
||||
m->suivant = liste;
|
||||
m->motif = malloc(nbrPortees*sizeof(portee));
|
||||
m->nom = strcat("Motif %d", getIdMotif(m));
|
||||
int i;
|
||||
for (i=0; i<nbrPortees; i++) {
|
||||
m->motif[i] = calloc(nbrTmp,sizeof(Note));
|
||||
}
|
||||
liste = m;
|
||||
}
|
||||
|
||||
void supprimerMotif(Liste** cellule, int nbrPortees){
|
||||
int i;
|
||||
for (i=0; i<nbrPortees; i++) {
|
||||
free((*cellule)->motif[i]);
|
||||
}
|
||||
free((*cellule)->motif);
|
||||
Liste* aux = (*cellule)->suivant;
|
||||
free((*cellule));
|
||||
*cellule = aux;
|
||||
void definirNomMotif(char* nom, Motif* m){
|
||||
m->nom = nom;
|
||||
}
|
||||
|
||||
void definirNote(Motif m, int portee, int tmp, int note, int octave, int instrument, int volume, int effet){
|
||||
m[portee][tmp]->note=note;
|
||||
m[portee][tmp]->octave=octave;
|
||||
m[portee][tmp]->instrument=instrument;
|
||||
m[portee][tmp]->volume=volume;
|
||||
m[portee][tmp]->effet=effet;
|
||||
void supprimerMotif(Motif** cellule){
|
||||
int i;
|
||||
for (i=0; i<nbrPortees; i++) {
|
||||
free((*cellule)->motif[i]);
|
||||
}
|
||||
free((*cellule)->motif);
|
||||
Motif* aux = (*cellule)->suivant;
|
||||
free((*cellule));
|
||||
*cellule = aux;
|
||||
}
|
||||
|
||||
void definirNote(Motif* m, int portee, int tmp, int note){
|
||||
m->Motif[portee][tmp]->note = note;
|
||||
}
|
||||
|
||||
void definirOctave(Motif m, int portee, int tmp, int octave){
|
||||
m->Motif[portee][tmp]->octave = octave;
|
||||
}
|
||||
|
||||
void definirInstrument(Motif m, int portee, int tmp, int intrument){
|
||||
m->Motif[portee][tmp]->instrument = instrument;
|
||||
}
|
||||
|
||||
void definirVolume(Motif m, int portee, int tmp, int volume){
|
||||
m->Motif[portee][tmp]->volume = volume;
|
||||
}
|
||||
|
||||
void definirEffet(Motif m, int portee, int tmp, int effet){
|
||||
m->Motif[portee][tmp]->effet = effet;
|
||||
}
|
||||
|
||||
void supprimerNote(Motif m, int portee, int tmp){
|
||||
m[portee][tmp]->note=0;
|
||||
m->motif[portee][tmp]->note = 0;
|
||||
}
|
|
@ -1,32 +1,50 @@
|
|||
#ifndef _motif_h
|
||||
#define _motif_h
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define NBRPORT 4
|
||||
#define NBRMOTIF 16
|
||||
|
||||
typedef struct _note{
|
||||
int note;
|
||||
int octave;
|
||||
int instrument;
|
||||
int volume;
|
||||
int effet;
|
||||
} Note;
|
||||
int note;
|
||||
int octave;
|
||||
int instrument;
|
||||
int volume;
|
||||
int effet;
|
||||
} Note;
|
||||
|
||||
typedef Note** Portee;
|
||||
|
||||
typedef Portee* Motif;
|
||||
typedef struct _motif{
|
||||
char* nom;
|
||||
int nbrTmp;
|
||||
Portee* motif;
|
||||
struct _motif suivant;
|
||||
} Motif;
|
||||
|
||||
typedef struct _liste{
|
||||
Motif motif;
|
||||
struct _liste* suivant;
|
||||
} Liste;
|
||||
Motif* liste = NULL;
|
||||
|
||||
Liste* tab;
|
||||
int nbrTmp = 16;
|
||||
|
||||
int nbrMotif = 16;
|
||||
|
||||
int getIdMotif(Motif* m);
|
||||
|
||||
void ajouterMotif(int nbrPortees, int nbrTmp);
|
||||
|
||||
void definirNomMotif(char* nom, Motif* m);
|
||||
|
||||
void supprimerMotif(Liste** cellule, int nbrPortees); // cellule correspond à l'adresse de l'élément de la liste (avec &)
|
||||
|
||||
void definirNote(Motif m, int portee, int tmp, int note, int octave, int instrument, int volume, int effet);
|
||||
void definirNote(Motif* m, int portee, int tmp, int note);
|
||||
|
||||
void definirOctave(Motif m, int portee, int tmp, int octave)
|
||||
|
||||
void definirInstrument(Motif m, int portee, int tmp, int intrument);
|
||||
|
||||
void definirVolume(Motif m, int portee, int tmp, int volume);
|
||||
|
||||
void definirEffet(Motif m, int portee, int tmp, int effet);
|
||||
|
||||
void supprimerNote(Motif m, int portee, int tmp);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue