/* $Id: notes.c,v 1.5 2006/09/15 15:13:19 toad32767 Exp $ */ /** ** 2005, 2006 by Marco Trillo ** This file is part of UModPlayer, and is released by ** its autors to the Public Domain. ** In case it's not legally possible, its autors grant ** anyone the right to use, redistribute and modify ** this software for any purpose, without any conditions, ** unless such conditions are required by law. ** ** THIS FILE COMES WITHOUT ANY WARRANTY. THE AUTHORS ** SHALL NOT BE LIABLE FOR ANY DAMAGE RESULTING BY THE ** USE OR MISUSE OF THIS SOFTWARE. **/ /* * ===================== * NOTE DRAWER * ===================== */ #include #include LOCAL int first_channel; LOCAL int last_channel; #define PUTSTR(strd,echar) strd[0]=strd[1]=strd[2]=(echar) LOCAL char *Notes[12] = {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"}; LOCAL void NoteGetName(int note, char *string) { int realnote, octave; if (note == 0) PUTSTR(string, '.'); /* no note (...) */ else if (note == 254) PUTSTR(string, '^'); /* note cut (^^^) */ else if (note == 255) PUTSTR(string, '='); /* note off (===) */ else if (note == 253) PUTSTR(string, '~'); /* note fade(~~~) */ else { /* normal note */ realnote = note - 1; octave = realnote / 12; realnote %= 12; strcpy(string, Notes[realnote]); /* put note name */ sprintf(&string[2], "%1d", octave); /* put octave */ } string[3] = '\0'; /* finish string */ return; } #undef PUTSTR LOCAL void DrawHead() { int i; fputs("row", stdout); for (i = first_channel; i <= last_channel; ++i) { printf(" %3d", i); } putchar('\n'); for (i = (first_channel - 1); i <= last_channel; ++i) { fputs("----", stdout); } putchar('\n'); } /* monitor function for CoreSound */ EXPORT void DrawSong() { int pattern, row, oldrow = -1, oldpattern = 0; int tics = 0; int channels; char noteName[4]; int i; ModPlugNote *pat; for (;;) { /* * Inject the audio samples */ CoreSound_InjectPCM(); if (AudioActive == FALSE || KeyPress()) { CoreSound_Quit(); return; } pattern = ModPlug_GetCurrentPattern(file.mod); row = ModPlug_GetCurrentRow(file.mod); if (oldpattern != pattern) { puts("\n\n\n"); if ((++tics) == 4) { DrawHead(); tics = 0; } } if (oldrow != row) { /* Draw the row */ pat = ModPlug_GetPattern(file.mod, pattern, NULL); channels = (int) ModPlug_NumChannels(file.mod); pat += channels * row + first_channel - 1; /* go to current row */ if (!pat) { CoreSound_Quit(); return; } printf("%3d", row); for (i = first_channel; i <= last_channel; ++i) { NoteGetName((int) (pat->Note), noteName); printf(" %s", noteName); ++pat; } putchar('\n'); } oldrow = row; oldpattern = pattern; } return; } EXPORT void NoteDisplay_Start(int x, int y) { int channels = (int) ModPlug_NumChannels(file.mod); if (x < 0) first_channel = 1; else { if (x == 0 || x > channels) first_channel = 1; else first_channel = x; } if (y < 0) last_channel = channels; else { if (y < 1 || y > channels) last_channel = channels; else last_channel = y; } if (first_channel > last_channel) first_channel = last_channel; DrawHead(); CoreSound_Start(DrawSong); return; }