Add markov chain layout
This commit is contained in:
parent
0100fff828
commit
0f566741bb
2
Makefile
2
Makefile
@ -9,7 +9,7 @@ CC = gcc
|
|||||||
FLAGS = -pipe
|
FLAGS = -pipe
|
||||||
|
|
||||||
CFLAGS = -Wall
|
CFLAGS = -Wall
|
||||||
CFLAGS += -Ofast
|
CFLAGS += -O2
|
||||||
#CFLAGS += -g
|
#CFLAGS += -g
|
||||||
#CFLAGS += -pg
|
#CFLAGS += -pg
|
||||||
|
|
||||||
|
13
src/chain.c
13
src/chain.c
@ -7,15 +7,18 @@
|
|||||||
#include "chain.h"
|
#include "chain.h"
|
||||||
|
|
||||||
m_node* m_next(const m_node* rhs){
|
m_node* m_next(const m_node* rhs){
|
||||||
uint16_t total = 0;
|
int i = 1;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
uint16_t v = rand() % (sizeof(uint16_t) * 8);
|
long v = rand() % UINT16_MAX - 1;
|
||||||
|
//printf("v : %li\n", v);
|
||||||
|
|
||||||
while(v > total){
|
long total = rhs->_conns[i]._probability;
|
||||||
|
|
||||||
|
while(v >= total){
|
||||||
|
//printf("prob : %u\n", rhs->_conns[i]._probability);
|
||||||
total += rhs->_conns[i]._probability;
|
total += rhs->_conns[i]._probability;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rhs->_conns[i]._node;
|
return rhs->_conns[i - 1]._node;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
enum chord {
|
enum chord {
|
||||||
one = 0x01,
|
one = 0x01,
|
||||||
@ -24,8 +25,9 @@ enum chord {
|
|||||||
// probability out of the size of a short
|
// probability out of the size of a short
|
||||||
struct m_conn {
|
struct m_conn {
|
||||||
uint16_t _probability;
|
uint16_t _probability;
|
||||||
struct m_conn* _node;
|
struct m_node* _node;
|
||||||
};
|
};
|
||||||
|
typedef struct m_conn m_conn;
|
||||||
|
|
||||||
struct m_node {
|
struct m_node {
|
||||||
enum chord _chord;
|
enum chord _chord;
|
||||||
|
111
src/main.c
111
src/main.c
@ -5,6 +5,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "chain.h"
|
#include "chain.h"
|
||||||
|
|
||||||
@ -12,12 +13,120 @@
|
|||||||
|
|
||||||
// sample version of how to progress
|
// sample version of how to progress
|
||||||
m_node* init(){
|
m_node* init(){
|
||||||
m_node* nodes = (m_node*)malloc(sizeof(m_node) * NOTE_COUNT);
|
printf("init...\n");
|
||||||
|
m_node* nodes = (m_node*)malloc(7 * sizeof(m_node));
|
||||||
|
m_node* curr;
|
||||||
|
|
||||||
|
//I chord
|
||||||
|
curr = nodes;
|
||||||
|
curr->_chord = one;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 2);
|
||||||
|
curr->_conns[0]._probability = (UINT16_MAX) / 2;
|
||||||
|
//printf("I prob : %u\n", curr->_conns[0]._probability);
|
||||||
|
curr->_conns[0]._node = nodes + 1; //ii
|
||||||
|
curr->_conns[1]._probability = (UINT16_MAX) / 2;
|
||||||
|
curr->_conns[1]._node = nodes + 5; //vi
|
||||||
|
|
||||||
|
//ii chord
|
||||||
|
curr++;
|
||||||
|
curr->_chord = two;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 2);
|
||||||
|
curr->_conns[0]._probability = ((UINT16_MAX) / 4) * 3;
|
||||||
|
curr->_conns[0]._node = nodes + 4; //V
|
||||||
|
curr->_conns[1]._probability = ((UINT16_MAX) / 4);
|
||||||
|
curr->_conns[1]._node = nodes + 6; //vii
|
||||||
|
|
||||||
|
//iii chord
|
||||||
|
curr++;
|
||||||
|
curr->_chord = three;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 1);
|
||||||
|
curr->_conns[0]._probability = UINT16_MAX;
|
||||||
|
curr->_conns[0]._node = nodes + 5; //vi
|
||||||
|
|
||||||
|
//IV chord
|
||||||
|
curr++;
|
||||||
|
curr->_chord = four;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 2);
|
||||||
|
curr->_conns[0]._probability = ((UINT16_MAX) / 4) * 3;
|
||||||
|
curr->_conns[0]._node = nodes + 0; //I
|
||||||
|
curr->_conns[1]._probability = ((UINT16_MAX) / 4);
|
||||||
|
curr->_conns[1]._node = nodes + 5; //vi
|
||||||
|
|
||||||
|
//V chord
|
||||||
|
curr++;
|
||||||
|
curr->_chord = five;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 3);
|
||||||
|
curr->_conns[0]._probability = ((UINT16_MAX) / 3) * 2;
|
||||||
|
curr->_conns[0]._node = nodes + 0; //I
|
||||||
|
curr->_conns[1]._probability = ((UINT16_MAX) / 6);
|
||||||
|
curr->_conns[1]._node = nodes + 3; //IV
|
||||||
|
curr->_conns[2]._probability = ((UINT16_MAX) / 6);
|
||||||
|
curr->_conns[2]._node = nodes + 5; //vi
|
||||||
|
|
||||||
|
//vi chord
|
||||||
|
curr++;
|
||||||
|
curr->_chord = six;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 4);
|
||||||
|
curr->_conns[0]._probability = ((UINT16_MAX) / 10) * 3;
|
||||||
|
curr->_conns[0]._node = nodes + 0; //I
|
||||||
|
curr->_conns[1]._probability = ((UINT16_MAX) / 10);
|
||||||
|
curr->_conns[1]._node = nodes + 1; //ii
|
||||||
|
curr->_conns[2]._probability = ((UINT16_MAX) / 10) * 5;
|
||||||
|
curr->_conns[2]._node = nodes + 4; //V
|
||||||
|
curr->_conns[3]._probability = ((UINT16_MAX) / 10);
|
||||||
|
curr->_conns[3]._node = nodes + 6; //vii
|
||||||
|
|
||||||
|
//vii
|
||||||
|
curr++;
|
||||||
|
curr->_chord = seven;
|
||||||
|
curr->_conns = (m_conn*)malloc(sizeof(m_conn) * 2);
|
||||||
|
curr->_conns[0]._probability = ((UINT16_MAX) / 3) * 2;
|
||||||
|
curr->_conns[0]._node = nodes + 0; //I
|
||||||
|
curr->_conns[1]._probability = ((UINT16_MAX) / 6);
|
||||||
|
curr->_conns[1]._node = nodes + 3; //IV
|
||||||
|
curr->_conns[2]._probability = ((UINT16_MAX) / 6);
|
||||||
|
curr->_conns[2]._node = nodes + 5; //vi
|
||||||
|
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
|
m_node* mchain = init();
|
||||||
|
m_node* current = mchain;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
int i_count = 0;
|
||||||
|
unsigned long ccount = 0;
|
||||||
|
|
||||||
|
while(i_count < 2){
|
||||||
|
switch(current->_chord){
|
||||||
|
case one:
|
||||||
|
printf("I ");
|
||||||
|
i_count++;
|
||||||
|
break;
|
||||||
|
case two:
|
||||||
|
printf("ii ");
|
||||||
|
break;
|
||||||
|
case three:
|
||||||
|
printf("iii ");
|
||||||
|
break;
|
||||||
|
case four:
|
||||||
|
printf("IV ");
|
||||||
|
break;
|
||||||
|
case five:
|
||||||
|
printf("V ");
|
||||||
|
break;
|
||||||
|
case six:
|
||||||
|
printf("vi ");
|
||||||
|
break;
|
||||||
|
case seven:
|
||||||
|
printf("vii ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
current = m_next(current);
|
||||||
|
ccount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nDone with %lu!\n", ccount);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user