home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / mt / mted1.c < prev    next >
C/C++ Source or Header  |  1989-01-25  |  11KB  |  241 lines

  1. /* mted1.c   editor central module for mt */
  2. /* `MIDI Sequencing In C', Jim Conger, M&T Books, 1989 */
  3.  
  4. #include <stdio.h>  /* compiler library headers */
  5. #include <conio.h>
  6. #include <string.h>
  7.  
  8. #include "screenf.h"
  9. #include "standard.h"
  10. #include "mpu401.h"
  11. #include "mt.h"
  12. #include "video.h"
  13. #include "mtdeclar.h"
  14.  
  15.  
  16. /* Controls the Measure Level Edit menu. */
  17. void
  18. edit_menu(void)
  19. {
  20.     int i, ans, pick, lastpick, track, param, item_no, pick2, enter_int, 
  21.         edit_measure;
  22.     struct item meas_item;
  23.     char buf[80], nbuf[10];
  24.     
  25.     pick = 0;
  26.     while (1){
  27.         clearscreen(g_norm_attrib);     /* clear screen and display screen */
  28.         fdispchain(g_chain[3], 1, g_norm_attrib, g_text_mode);
  29.         
  30.         /* initialize menu top for note symbols, track names; then display */
  31.         init_meas_data();
  32.         finitscrn(mt3, 0, NPARAM3 - 1, g_emph_attrib, g_text_mode);
  33.         
  34.         write_int(g_current_measure + 1, 64, 16, g_norm_attrib);
  35.         calc_pct_free();                /* update free memory value */
  36.         write_int(g_pct_free_memory, 62, 20, g_norm_attrib);
  37.         
  38.         lastpick = pick;                /* allow cursor selection of item */
  39.         pick = movescrn(g_text_mode, mt3, pick, NPARAM3 - 1, g_emph_attrib, 
  40.             g_cursor_attrib);
  41.  
  42.         /* if in the top half of the screen, track # and position can be */
  43.         /* calculated from the menu item number (pick) selected. */
  44.         
  45.         track = (pick - NMEASURE_DISP) / (NMEASURE_DISP + 2);
  46.         item_no = (pick - NMEASURE_DISP) % (NMEASURE_DISP + 2);
  47.  
  48.         if (pick == -2)             /* Quit if ESC key */
  49.             return;
  50.         else if (pick < 0){
  51.             writerr("Use arrow keys to move cursor, ret to select.",
  52.                 g_text_char_v - 1, g_norm_attrib, g_emph_attrib);
  53.             pick = lastpick;
  54.         }
  55.                                     /* top line - select new start measure */
  56.         else if (pick < NMEASURE_DISP){
  57.             goto_measure(g_current_measure + pick);
  58.             g_current_measure = g_current_measure + pick;
  59.             pick = 0;
  60.         }
  61.                             /* see if the cursor is in the track data area */
  62.         else if (pick < (NMEASURE_DISP * (NTRACK + 1)) + (2 * NTRACK)){
  63.  
  64.             if (item_no == 0){                  /* track name */
  65.                 ans = getstr(g_text_char_v - 1,"Enter track name (8 chars max)->", 
  66.                     buf, 8, g_norm_attrib);
  67.                 if (ans){
  68.                     strcpy(mt3[pick].content, buf);
  69.                     strcpy(g_trackarray[track].name, buf);
  70.                 }
  71.             }
  72.             else if (item_no == 1){         /* MIDI channel number */
  73.                 ans = getint(g_text_char_v - 1, 
  74.                     "Enter the MIDI channel number for this track (1-16)->",
  75.                         &enter_int, 1, 16, g_norm_attrib, g_emph_attrib);
  76.                 if (ans){
  77.                     itoa(enter_int, nbuf, 10);
  78.                     strcpy(mt3[pick].content, nbuf);
  79.                     g_trackarray[track].midichan = --enter_int;
  80.                     change_channel(track, enter_int);
  81.                 }
  82.             }
  83.             else{       /* selected a measure for Note Level Edit */
  84.                 edit_measure = scrn_edit_control(track, 
  85.                     g_current_measure + item_no - 2);
  86.                 
  87.                 /* on return from NLE, update measure cursor is on */
  88.                 
  89.                 if (edit_measure >= g_current_measure && edit_measure
  90.                     < g_current_measure + NMEASURE_DISP){
  91.                     pick = NMEASURE_DISP + (track * (NMEASURE_DISP + 2)) +
  92.                         edit_measure - g_current_measure + 2;
  93.                     goto_measure(g_current_measure);
  94.                 }
  95.                 else{
  96.                     g_current_measure = goto_measure(edit_measure);
  97.                     pick = NMEASURE_DISP + (track * (NMEASURE_DISP + 2)) + 2;
  98.                 }                   
  99.             }
  100.         }
  101.         else{       /* must be bottom (command) area of MLE screen */
  102.             switch(pick){
  103.             case(151):                      /* block start */
  104.                 if (g_block_on){
  105.                     g_block_on = 0;         /* kill block if already on */
  106.                     g_block_start = g_block_end = -1;
  107.                 }
  108.                 else {
  109.                     writeword(
  110.                         "Move the cursor to the first measure of the block."
  111.                         , 1, g_text_char_v - 1, g_norm_attrib);
  112.                     ans = select_measure(&meas_item);
  113.                     if (ans){
  114.                         g_block_track = meas_item.track;
  115.                         g_block_start = meas_item.measure;
  116.                         g_block_on = 1;
  117.                         g_block_end = -1;
  118.                         
  119.                         /* add empty measures if needed to extend track */
  120.                         /* to measure selected for block start */
  121.                         advance_to_measure(g_block_track, g_block_start + 1);
  122.                     }
  123.                     else{
  124.                         g_block_on = 0;
  125.                         writerr("Measure not selected, so block cancelled.", 
  126.                             g_text_char_v, g_norm_attrib, g_norm_attrib);
  127.                     }
  128.                 }
  129.                 break;
  130.             case(152):                      /* end tracks */
  131.                 g_current_measure = goto_measure(32000);
  132.                 g_current_measure -= 2;     /* display last two measures */
  133.                 goto_measure(g_current_measure);
  134.                 break;
  135.             case(153):                      /* measure no. */
  136.                 ans = getint(g_text_char_v - 1, 
  137.                     "Enter the measure number to start on ->",
  138.                     &enter_int, 0, 32000, g_norm_attrib, g_emph_attrib);
  139.                 if (ans){
  140.                     g_current_measure = enter_int - 1;
  141.                     goto_measure(g_current_measure);
  142.                 }
  143.                 break;
  144.             case(154):                      /* Block End */
  145.                 writeword("Move the cursor to the last measure of the block."
  146.                     , 1, g_text_char_v - 1, g_norm_attrib);
  147.                 ans = select_measure(&meas_item);
  148.                 if (ans){
  149.                     if (meas_item.track == g_block_track){
  150.                         g_block_end = meas_item.measure;
  151.                         if (g_block_end < g_block_start){
  152.                             writerr("The block must end at or after start.",
  153.                                 g_text_char_v, g_norm_attrib, g_emph_attrib);
  154.                             g_block_end = -1;
  155.                         }
  156.                         else{       /* add measure data if off end of track */
  157.                             advance_to_measure(g_block_track, 
  158.                                 g_block_end + 1);
  159.                         }
  160.                     }
  161.                     else{
  162.                         writerr("The block must start and end on one track.",
  163.                             g_text_char_v, g_norm_attrib, g_emph_attrib);
  164.                         g_block_end = -1;
  165.                     }
  166.                 }
  167.                 break;
  168.             case(155):                      /* Fast forward */
  169.                 g_current_measure += 10;
  170.                 goto_measure(g_current_measure);
  171.                 break;
  172.             case(156):                      /* Erase Track */
  173.                 erase_track();
  174.                 goto_measure(g_current_measure);
  175.                 calc_pct_free();
  176.                 g_block_on = 0;
  177.                 break;
  178.             case(157):                      /* Block Paste */
  179.                 block_paste();
  180.                 calc_pct_free();
  181.                 break;
  182.             case(158):                      /* Forward */
  183.                 goto_measure(++g_current_measure);
  184.                 break;
  185.             case(159):                      /* Erase Forward */
  186.                 clear_forward();
  187.                 g_block_on = 0;
  188.                 break;
  189.             case(160):                      /* Block empty */
  190.                 if (!g_block_on || g_block_end == -1){
  191.                     writerr("First mark the START and END of the block",
  192.                         g_text_char_v - 1, g_norm_attrib, g_emph_attrib);
  193.                     break;
  194.                 }
  195.                 writeword(
  196.                     "Are you sure you want to empty the marked block? (Y/N)->"
  197.                     , 1, g_text_char_v - 1, g_norm_attrib);
  198.                 ans = getche();
  199.                 if (toupper(ans) == 'Y'){
  200.                     empty_block(g_block_track, g_block_start, g_block_end);
  201.                     calc_pct_free();
  202.                     g_block_on = 0;
  203.                     goto_measure(g_current_measure);
  204.                 }               
  205.                 break;
  206.             case(161):                      /* Rewind */
  207.                 g_current_measure = (g_current_measure - 1 < 0 ?
  208.                     0 : g_current_measure - 1);
  209.                 goto_measure(g_current_measure);
  210.                 break;
  211.             case(162):                      /* Data Dump */
  212.                 data_dump();
  213.                 break;
  214.             case(163):                      /* Block repeat */
  215.                 block_repeat();
  216.                 calc_pct_free();
  217.                 break;
  218.             case(164):                      /* Fast Rewind */
  219.                 g_current_measure = (g_current_measure - 10 < 0 ?
  220.                     0 : g_current_measure - 10);
  221.                 goto_measure(g_current_measure);
  222.                 break;
  223.             case(165):                          /* Block Transpose */
  224.                 if (!g_block_on || g_block_end == -1){
  225.                     writerr("First mark the START and END of the block",
  226.                         g_text_char_v - 1, g_norm_attrib, g_emph_attrib);
  227.                 }
  228.                 else{
  229.                     transpose_block();
  230.                 }
  231.                 break;
  232.             case(166):                          /* Begin Tracks */
  233.                 g_current_measure = goto_measure(0);
  234.                 break;
  235.             case(167):                          /* Quit */
  236.                 return;
  237.             }
  238.         }
  239.     }
  240. }
  241.