home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / mt / mtsc1.c < prev    next >
C/C++ Source or Header  |  1989-02-24  |  8KB  |  226 lines

  1. /* mtsc1.c  central module for screen editing functions of mt */
  2. /* `MIDI Sequencing In C', Jim Conger, M&T Books, 1989 */
  3.  
  4. #include <stdio.h>
  5. #include <conio.h>
  6.  
  7. #include "standard.h"
  8. #include "screenf.h"
  9. #include "mpu401.h"
  10. #include "mt.h"
  11. #include "video.h"
  12. #include "mtsc.h"
  13. #include "mtdeclar.h"
  14.  
  15.  
  16. /* Central module for Note Level editor.  Returns measure number ended on */
  17. int  
  18. scrn_edit_control(int track, int measure)
  19. {
  20.     int i, beat, pick;
  21.     char buf[SCRNWIDE], nbuf[10];
  22.     struct note_time far *note_list;
  23.     beat = 0;
  24.     
  25.     setvideomode(g_graph_mode);
  26.  
  27.     strcpy(buf, "MIDI Note Editor  -  Track Number ");
  28.     itoa(track + 1, nbuf, 10);
  29.     strcat(buf, nbuf);
  30.     strcat(buf, ",  [");
  31.     strcat(buf, g_trackarray[track].name);
  32.     strcat(buf, "]");
  33.     writeword(buf, 20, 1, g_norm_attrib);   
  34.  
  35.     display_keyboard();
  36.     mark_middle_c(TRUE);
  37.     
  38.     initscrn(mt6, 0, NPARAM6 - 1, g_emph_attrib);   /* put menu at bottom */
  39.     init_screen_box(beat, measure);                 /* draw in edit area */
  40.     name_top_note(g_oct_shown);
  41.     name_measure(measure);
  42.     
  43.     writeword("Compiling note data.  Hit ESC to terminate.", 
  44.         1, g_graph_char_v, g_norm_attrib);
  45.     note_list = build_note_list(track);             /* build note list */
  46.     if (note_list == NULL){
  47.         writerr("ESC key hit (or not enough memory to compile note list.)",
  48.             g_graph_char_v, g_norm_attrib, g_emph_attrib);
  49.         setvideomode(g_text_mode);
  50.         return(measure);
  51.     }
  52.     
  53.     disp_notes(note_list, measure, beat);           /* draw note lines */
  54.     clearline(g_graph_char_v, g_norm_attrib);       /* clear bottom line */
  55.     
  56.     pick = 0;
  57.     while(1){                   /* cursor selection of a command */
  58.         pick = movescrn(g_graph_mode, mt6, pick, NPARAM6 - 1,
  59.             g_line_color, g_line_color);
  60.         switch(pick){
  61.             case(0):        /* Up Octive */
  62.                 if (g_top_note < NNOTES - 12){
  63.                     g_top_note += 12;
  64.                     g_bot_note += 12;
  65.                     name_top_note(g_oct_shown);
  66.                     mark_middle_c(FALSE);
  67.                     init_screen_box(beat, measure);
  68.                     disp_notes(note_list, measure, beat);
  69.                 }
  70.                 else
  71.                     writerr("You are at the top of the MIDI scale already.",
  72.                         g_graph_char_v, g_norm_attrib, g_norm_attrib);
  73.                 break;
  74.             case(1):        /* Next Measure */
  75.                 measure++;
  76.                 name_measure(measure);
  77.                 init_screen_box(beat, measure);
  78.                 disp_notes(note_list, measure, beat);
  79.                 break;
  80.             case(2):        /* Note Delete */
  81.                 note_list = delete_note(note_list, measure, track);
  82.                 break;
  83.             case(3):        /* tick */
  84.                 break;
  85.             case(4):        /* Down Octive */
  86.                 if (g_top_note - ((g_oct_shown + 1) * 12) + 1 >= 0){
  87.                     g_top_note -= 12;
  88.                     g_bot_note -= 12;
  89.                     name_top_note(g_oct_shown);
  90.                     mark_middle_c(FALSE);
  91.                     init_screen_box(beat, measure);
  92.                     disp_notes(note_list, measure, beat);
  93.                 }
  94.                 else
  95.                     writerr("You are already at the bottom of the MIDI scale.",
  96.                         g_graph_char_v, g_norm_attrib, g_norm_attrib);
  97.                 break;
  98.             case(5):        /* Next Beat */
  99.                 if (beat < g_meter - 1)
  100.                     beat++;
  101.                 else{
  102.                     beat = 0;
  103.                     measure++;
  104.                 }
  105.                 name_measure(measure);
  106.                 init_screen_box(beat, measure);
  107.                 disp_notes(note_list, measure, beat);
  108.                 break;
  109.             case(6):        /* Note Add */
  110.                 add_note(note_list, measure, track);
  111.                 break;
  112.             case(7):        /* Note = */
  113.                 break;
  114.             case(8):        /* Expand Scale */
  115.                 if (g_scale > 1){
  116.                     g_scale /= 2;
  117.                     init_screen_box(beat, measure);
  118.                     disp_notes(note_list, measure, beat);
  119.                 }
  120.                 else
  121.                     writerr("Already at most expanded scale possible, 1/1.", 
  122.                         g_graph_char_v, g_norm_attrib, g_norm_attrib);
  123.                 break;
  124.             case(9):        /* Prev. Beat */
  125.                 if (beat > 0)
  126.                     beat--;
  127.                 else{
  128.                     if (measure > 0){
  129.                         measure--;
  130.                         beat = g_meter - 1;
  131.                     }
  132.                 }
  133.                 name_measure(measure);
  134.                 init_screen_box(beat, measure);
  135.                 disp_notes(note_list, measure, beat);
  136.                 break;
  137.             case(10):       /* Velocity Change */
  138.                 change_vel(note_list, measure);
  139.                 break;
  140.             case(11):       /* Key Velocity (not an command) */
  141.                 break;
  142.             case(12):       /* Shrink Scale */
  143.                 if (g_scale < 8){
  144.                     g_scale *= 2;
  145.                     init_screen_box(beat, measure);
  146.                     disp_notes(note_list, measure, beat);
  147.                 }
  148.                 else{
  149.                     writerr("Scale already shrunk to maximum possible.",
  150.                         g_graph_char_v, g_norm_attrib, g_norm_attrib);
  151.                 }
  152.                 break;
  153.             case(13):       /* Prev Measure */
  154.                 if (measure){
  155.                     measure--;
  156.                     name_measure(measure);
  157.                     init_screen_box(beat, measure);
  158.                     disp_notes(note_list, measure, beat);
  159.                 }
  160.                 else{
  161.                     writerr("Already at beginning of track.", g_graph_char_v, 
  162.                         g_norm_attrib, g_norm_attrib);
  163.                 }               
  164.                 break;
  165.             case(14):       /* Quit */
  166.             case(-2):       /* ESC */
  167.                 setvideomode(6);    /* kludge to get vga back to 25 line */
  168.                 setvideomode(g_text_mode);
  169.                 free_note_list(note_list);
  170.                 return(measure);
  171.             default:
  172.                 writerr("Use arrow keys to make selection, then hit return.",
  173.                     g_graph_char_v, g_norm_attrib, g_norm_attrib);
  174.                 break;
  175.         }
  176.     }
  177.     return(measure);
  178. }
  179.  
  180.  
  181. /* Initialize global variables used in NLE graphics display based on */
  182. /* video data read in on startup of MT. */
  183. void
  184. init_edit_param(void)
  185. {
  186.     int i, text_lines;
  187.     
  188.     text_lines = SC_TOP_LINES + SC_MENU_LINES + SC_BOT_LINES;
  189.     g_oct_shown = (g_dots_v - (text_lines * g_let_dots_v)) / OCTIVE_HIGH;
  190.     g_top_note_line = (SC_TOP_LINES * g_let_dots_v) + HALF_NOTE_DOTS;
  191.     g_bot_note_line = g_top_note_line + (g_oct_shown * OCTIVE_HIGH) - 
  192.         (2 * HALF_NOTE_DOTS);
  193.     g_top_note = 71 + (6 * (g_oct_shown - 2));
  194.     g_bot_note = g_top_note - (g_oct_shown * 12) + 1;
  195.  
  196.     
  197.     /* if in mode with more than 25 lines of text on screen */
  198.     /* adjust the graphics menu to be at the bottom of screen. */
  199.     
  200.     if (g_graph_char_v > SCRNTALL){
  201.         for (i = 0; i < NPARAM6; i++){
  202.             mt6[i].ypos += g_graph_char_v - SCRNTALL;
  203.         }
  204.     }
  205. }
  206.  
  207.  
  208. void
  209. display_keyboard(void)          /* put a keyboard image on left of screen */
  210. {
  211.     int m, n, y;
  212.  
  213.     y = g_top_note_line - HALF_NOTE_DOTS;
  214.     for (m = 0; m < g_oct_shown; m++){
  215.         for (n = 0; n < 7; n++){
  216.             draw_rectangle(FALSE, 1, y, LEFT_BORDER - 2, y + 8,
  217.                 g_line_color);
  218.             if (n != 0 && n != 4 && n != 7){
  219.                 draw_rectangle(TRUE, 1, y - 2, (LEFT_BORDER - 2)/2,
  220.                     y + 2, g_line_color);
  221.             }
  222.             y += 2 * HALF_NOTE_DOTS;
  223.         }
  224.     }
  225. }
  226.