ncnu.c (5067B)
1 #include <ncurses.h> 2 3 4 // modes 5 #define INSERT 0 6 #define EDIT 1 7 // line number offset 8 #define LN_OFFSET 5 9 10 float step = 0.125; 11 int curX = 0; 12 int curY = 0; 13 int yMax, xMax; 14 int mode = INSERT; 15 16 /* owwd = owerwrite default */ 17 bool owwd_note = true; 18 int default_note = 69; //TODO: add option for displaying frequency, supercollider note etc. 19 bool owwd_dur = true; 20 int default_dur = 0.5; 21 22 23 // This will later be used to connect the instrument letters to actual names. 24 char* instlist[] = {"piano", "violin", "testins"}; 25 char* get_instrument(char** instlist, char insnum) { return instlist[insnum - 'A']; } 26 27 //TODO: typedef for note events (containing start_time, duration, note etc) 28 //TODO: Set minimum and maximum values for some of the numbers. 29 //TODO: Instead of hard coding the keybindings, make a header file like dwm 30 // for starters, and perhaps a runtime config file later 31 //TODO: Implement a tone buffer that contains all of the existing notes plus the 32 // one about to be placed, so that this can be used to decide the properties 33 // of the new note (the buffer will be played when 'p' is pushed). 34 35 int insert_events(){ 36 char inst = 'A'; 37 int note = default_note; 38 float start_time = 0.5; 39 float dur = 0.5; 40 char num; 41 mvprintw(curY, curX + LN_OFFSET, "%c(%d, %1.3f, %1.3f)", inst, note, start_time, dur); 42 refresh(); 43 while (1){ 44 num = getch(); 45 switch(num){ 46 /* Changing instrument */ 47 case 'z': 48 inst++; 49 break; 50 case 'Z': 51 inst--; 52 break; 53 /* Changing note, duration, position */ 54 case 'n': 55 note--; 56 break; 57 case 'N': 58 note -= 12; 59 break; 60 case 'e': 61 note++; 62 break; 63 case 'E': 64 note += 12; 65 break; 66 /* Change duration */ 67 case 'h': 68 dur -= step; 69 break; 70 case 'i': 71 dur += step; 72 break; 73 /* Change position */ 74 case 's': 75 start_time -= step; 76 break; 77 case 't': 78 start_time += step; 79 break; 80 /* Finishing insert */ 81 case ',': 82 printw(", "); 83 getyx(stdscr, curY, curX); 84 // TODO: a function that appends the new note event to a .txt file, so it matches what's 85 // shown on the display. 86 if(owwd_note) default_note = note; 87 return INSERT; 88 case 10: // this is enter 89 curX = 0; 90 curY++; 91 if(owwd_note) default_note = note; 92 return INSERT; 93 case 27: // esc 94 return EDIT; 95 default: 96 break; 97 } 98 mvprintw(curY, curX+LN_OFFSET, "%c(%d, %1.3f, %1.3f)", inst, note, start_time, dur); 99 mvprintw(yMax - 5, 1, "- New entry-\n note: %d\n start time: %1.3f\n duration: %1.3f", note, start_time, dur); 100 /* mvprintw(yMax - 5, 1, "- New entry-\n instrument: %s\n note: %d\n start time: %1.3f\n duration: %1.3f", 101 get_instrument(instlist, inst), note, start_time, dur); 102 // This includes the name of the instrument */ 103 refresh(); 104 } 105 } 106 /* Tonebook is the name of the notepad like text display */ 107 void draw_tonepad(int yLen, int yFirstNum){ 108 // quick and dirty 109 for(int i = 0; i < yLen; i++){ 110 if(i < 10) 111 mvprintw(i, 0, " %d", yFirstNum + i); 112 else if(i < 100) 113 mvprintw(i, 0, " %d", yFirstNum + i); 114 else if(i < 1000) 115 mvprintw(i, 0, " %d", yFirstNum + i); 116 else 117 mvprintw(i, 0, "%d", yFirstNum + i); 118 } 119 } 120 121 int edit_events(){ 122 char num; 123 while (1){ 124 num = getch(); 125 switch(num){ 126 /* Changing instrument */ 127 case 'z': 128 inst++; 129 break; 130 case 'Z': 131 inst--; 132 break; 133 /* Changing note, duration, position */ 134 case 'n': 135 note--; 136 break; 137 case 'N': 138 note -= 12; 139 break; 140 case 'e': 141 note++; 142 break; 143 case 'E': 144 note += 12; 145 break; 146 /* Change duration */ 147 case 'h': 148 dur -= step; 149 break; 150 } 151 152 int main(){ 153 initscr(); 154 noecho(); 155 cbreak(); 156 157 // max positions 158 getmaxyx(stdscr, yMax, xMax); 159 draw_tonepad(yMax - 8, 0); 160 161 // current position 162 bool running = 1; 163 while(running){ 164 while(mode == EDIT) 165 mode = edit_events(); 166 while(mode == INSERT) 167 mode = insert_events(); 168 running = 0; 169 } 170 endwin(); 171 172 return 0; 173 }