function.c
来自「Genetic Programing of music」· C语言 代码 · 共 477 行
C
477 行
/* lil-gp Genetic Programming System, version 1.0, 11 July 1995 * Copyright (C) 1995 Michigan State University * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Douglas Zongker (zongker@isl.cps.msu.edu) * Dr. Bill Punch (punch@isl.cps.msu.edu) * * Computer Science Department * A-714 Wells Hall * Michigan State University * East Lansing, Michigan 48824 * USA * */#include <math.h>#include <stdio.h>#include <string.h>#include <lilgp.h>/* functions */DATATYPE f_play_two ( int tree, farg *args ) { args[0].d=(char *)REALLOC(args[0].d,strlen(args[0].d)+strlen(args[1].d) +sizeof(char)); strcat(args[0].d,args[1].d); FREE(args[1].d); return args[0].d; } DATATYPE f_add_space ( int tree, farg *args ) { int i, stop; args[0].d=(char *)REALLOC(args[0].d, 2*strlen(args[0].d) +sizeof(char)); stop=strlen(args[0].d); args[0].d[2*stop]=0x0; for(i=(stop-1) ; i>=0 ; i--) { args[0].d[2*i]=args[0].d[i]; args[0].d[2*i+1]=88; } return args[0].d;}DATATYPE f_play_twice ( int tree, farg *args ) { char *tempString; tempString=(char *)MALLOC(strlen(args[0].d)+sizeof(char)); strcpy(tempString, args[0].d); args[0].d=(char *)REALLOC(args[0].d,2*strlen(args[0].d)+sizeof(char)); strcat(args[0].d,tempString); FREE(tempString); return args[0].d;}DATATYPE f_shift_up (int tree, farg *args ) { int i; for(i=0;i<strlen(args[0].d);i++) if(args[0].d[i] != 88 && args[0].d[i] != 72) { args[0].d[i]++;#ifdef C_MAJOR /* check to see if this is a sharp, if so, add one more */ switch(args[0].d[i] % 12) { /* C# */ case 2: /* D# */ case 4: /* F# */ case 7: /* G# */ case 9: /* A# */ case 11: args[0].d[i]++; break; default: break; } #endif } return args[0].d; }DATATYPE f_shift_down ( int tree, farg *args ) { int i; for(i=0;i<strlen(args[0].d);i++) if(args[0].d[i] != 88 && args[0].d[i] != 1) { args[0].d[i]--;#ifdef C_MAJOR /* check to see if this is a sharp, if so, subtract one more */ switch(args[0].d[i] % 12) { /* C# */ case 2: /* D# */ case 4: /* F# */ case 7: /* G# */ case 9: /* A# */ case 11: args[0].d[i]--; break; default: break; } #endif } return args[0].d; }DATATYPE f_mirror ( int tree, farg *args ) { char *newNoteString; int i; int length; length=(int)strlen(args[0].d); newNoteString=(char *)MALLOC(length+sizeof(char)); for(i=0;i<length;i++) newNoteString[i]=args[0].d[length-i-1]; newNoteString[length]=0x0; FREE(args[0].d); return newNoteString;}DATATYPE f_play_and_mirror (int tree, farg *args) { int i; int length; length=(int)strlen(args[0].d); args[0].d=(char *)REALLOC(args[0].d,2*length+sizeof(char)); for(i=0;i<length;i++) args[0].d[length+i]=args[0].d[length-i-1]; args[0].d[2*length]=0x0; return args[0].d; }/* terminals */DATATYPE f_C_4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=49; note[1]=0x0; return note; }DATATYPE f_CS4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=50; note[1]=0x0; return note; }DATATYPE f_D_4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=51; note[1]=0x0; return note; }DATATYPE f_DS4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=52; note[1]=0x0; return note; }DATATYPE f_E_4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=53; note[1]=0x0; return note; }DATATYPE f_F_4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=54; note[1]=0x0; return note; }DATATYPE f_FS4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=55; note[1]=0x0; return note; }DATATYPE f_G_4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=56; note[1]=0x0; return note; }DATATYPE f_GS4 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=57; note[1]=0x0; return note; }DATATYPE f_A_5 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=58; note[1]=0x0; return note; }DATATYPE f_AS5 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=59; note[1]=0x0; return note; }DATATYPE f_B_5 ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=60; note[1]=0x0; return note; }DATATYPE f_RST ( int tree, farg *args ) { char *note; note=(char *)MALLOC(2*sizeof(char)); note[0]=88; note[1]=0x0; return note; }/* Pseudo Chords */DATATYPE f_C_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=49; note[1]=53; note[2]=56; note[3]=0x0; return note; }DATATYPE f_D_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=51; note[1]=55; note[2]=58; note[3]=0x0; return note; }DATATYPE f_E_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=53; note[1]=57; note[2]=60; note[3]=0x0; return note; }DATATYPE f_F_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=54; note[1]=58; note[2]=61; note[3]=0x0; return note; }DATATYPE f_G_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=56; note[1]=60; note[2]=63; note[3]=0x0; return note; }DATATYPE f_A_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=58; note[1]=62; note[2]=65; note[3]=0x0; return note; }DATATYPE f_B_Chord ( int tree, farg *args ) { char *note; note=(char *)MALLOC(4*sizeof(char)); note[0]=60; note[1]=64; note[2]=67; note[3]=0x0; return note; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?