Generate the open-source ABC format in C for MIDI music.
Generate music files.
Date Created:Thursday May 10th, 2007 10:47 PM
Date Modified:Sunday August 03rd, 2008 12:37 PM
#include <stdio.h>
#include "music.h"
int main()
{
srand ( time(NULL) );
m_header();
m_scale();
return 0;
}
/*
* Author: Dan Lynch
*/
void m_header(){
m_id(1);
m_title("Dans");
m_metre(4,4);
m_length("1/16");
m_key("C");
}
void m_key(char * x) {
printf("K:%s\n",x);
}
void m_length(char * x) {
printf("L:%s\n",x);
}
void m_title(char * x) {
printf("T:%s\n",x);
}
void m_metre(int n, int d) {
printf("M:%d/%d\n",n,d);
}
void m_id(int n) {
printf("X:%d\n",n);
}
void m_scale() {
char * scale="ABCDEFG";
int i;
int note;
int length;
for ( i = 0; i < 100; i++ ) {
if (i==0) printf("|(");
if (i%4==0 && i!=0 && i%16!=0 ) printf(")|(");
if (i%16==0&&i!=0) printf("\n|(");
note = rand()%7;
if (i>7) {note+=4;note=note%7;}
if (i>15) {note+=6;note=note%7;}
if (i>23) {note+=5;note=note%7;}
if (i>31) {note+=3;note=note%7;}
length = rand()%8+1;
printf("[%c,%d%c,%d%c,%d]", scale[note], length, scale[(note+2)%7], length, scale[(note+4)%7], length );
}
}
Downloads:
Download: generate.c 125 B
Download: music.h 933 B
Please login or Click Here to register for downloads
Generate ABC by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
