void GFX_PP_Update(struct Patch *patch, bool is_loading){
  printf("GFX_PP_Update %s\n", patch==NULL?"(null)":patch->name);
  
  called_from_pp_update = true;{
    //if(g_currpatch==patch)
    //  goto exit;
    if(patch==NULL){

      //g_instruments_widget->tabs->showPage(no_instrument_widget);

    }else if(patch->instrument==get_MIDI_instrument()){
      printf("PP update. Instrument name: \"%s\". port name: \"%s\"\n",patch==NULL?"(null)":patch->name,patch==NULL?"(null)":((struct PatchData*)patch->patchdata)->midi_port->name);

      MIDI_instrument_widget *instrument = get_midi_instrument_widget(patch);
      if(instrument==NULL){
        instrument = create_midi_instrument(patch);
        //instrument = get_midi_instrument_widget(patch);
      }

      update_midi_instrument_widget(instrument,patch);
      
      g_instruments_widget->tabs->setCurrentWidget(instrument);
      MW_update_all_chips();

      MIDI_SetThroughPatch(patch);

    }else if(patch->instrument==get_audio_instrument()){
      Audio_instrument_widget *instrument = get_audio_instrument_widget(patch);
      if(instrument==NULL){
        fprintf(stderr,"                 WARNING: patch %s didn't have an instrument widget. Creating one now. (Might happen when loading song or starting up. Nothing is wrong if that is the case)\n",patch->name);
        instrument = create_audio_instrument_widget(patch, true);
        //instrument = get_audio_instrument_widget(patch);
      }
      
      update_audio_instrument_widget(instrument,patch);
      g_instruments_widget->tabs->setCurrentWidget(instrument);
      //if (instrument->_sample_requester_widget != NULL && !is_loading)
      //  instrument->_sample_requester_widget->update_file_list_if_needed();

      MW_update_all_chips();      

      MIDI_SetThroughPatch(patch);

    }else if(patch->instrument!=NULL){
      RError("PP_Update: Don't know how to handle instrument %p",patch->instrument);
    }

    // background color for editor tracks assigned to current instrument are slightly different than background color for non-current instruments.
    if(patch!=NULL && patch_used_in_current_editor_block(patch))
      root->song->tracker_windows->must_redraw = true;
    else if (g_currpatch != NULL && patch_used_in_current_editor_block(g_currpatch))
      root->song->tracker_windows->must_redraw = true;
    
    g_currpatch = patch;
    redrawMixerStrips(false);

  }
  //exit:
  called_from_pp_update = false;
}
void GFX_update_instrument_widget(struct Patch *patch){
  if (patch==NULL)
    return;
  
  if(patch->instrument==get_MIDI_instrument()){
    printf("PP update. Instrument name: \"%s\". port name: \"%s\"\n",patch==NULL?"(null)":patch->name,patch==NULL?"(null)":((struct PatchData*)patch->patchdata)->midi_port->name);

    MIDI_instrument_widget *instrument = get_midi_instrument_widget(patch);
    if(instrument==NULL){
      return;
    }

    if (instrument->isVisible())
      update_midi_instrument_widget(instrument,patch);

  }else if(patch->instrument==get_audio_instrument()){
    Audio_instrument_widget *instrument = get_audio_instrument_widget(patch);
    if(instrument==NULL){
      printf("GFX_update_instrument_widget. instrument==NULL\n");
      return;
    }

    if (instrument->isVisible())
      update_audio_instrument_widget(instrument,patch);
  }
}
Exemple #3
0
void MIDI_InitPatch(struct Patch *patch) {
  patch->playnote=MIDIplaynote;
  patch->stopnote=MIDIstopnote;
  patch->changevelocity=MIDIchangevelocity;
  patch->changepitch=MIDIchangepitch;
  patch->sendrawmidimessage=MIDIsendrawmidimessage;
  patch->closePatch=MIDIclosePatch;
  patch->changeTrackPan=MIDIchangeTrackPan;

  patch->patchdata = createPatchData();

  patch->instrument = get_MIDI_instrument();
  
  patch->is_usable = true;
}
static void DrawWTrackNames(
                     struct Tracker_Windows *window,
                     const struct WBlocks *wblock,
                     int starttrack,
                     int endtrack
                     )
{

  struct WTracks *wtrack1 = (struct WTracks *)ListFindElement1(&wblock->wtracks->l, starttrack);
  struct WTracks *wtrack2 = (struct WTracks *)ListFindElement1(&wblock->wtracks->l, endtrack);

  struct Patch *patch = wtrack1->track->patch;
  
  int x1 = wtrack1->x + 2;
  int x2 = wtrack2->x2 - 1;
  int y1 = wtrack1->y;
  int y2 = wtrack1->panonoff.y1 - 2;

  // Background
  unsigned int color = patch==NULL ? GFX_get_color(HIGH_EDITOR_BACKGROUND_COLOR_NUM) : get_displayed_instrument_color(patch).rgb();
  bool is_current_track = get_current_instruments_gui_patch()==patch;
  
  if(is_current_track)
    GFX_SetMixColor2(window, WHITE_COLOR_NUM, color, 150);
  else
    GFX_SetMixColor2(window, WHITE_COLOR_NUM, color, 0);
    
  GFX_T_FilledBox(window, CURSOR_EDIT_ON_COLOR_NUM,
                  x1,y1,x2,y2,
                  PAINT_BUFFER);

  GFX_CancelMixColor(window); // in case track is not visible and the above filledbox call is not executed, the mixcolor will be set for the next paint operation instead. Bad stuff, caused by radium originally being written for amigaos, where painting outside the visible area would cause memory corruption (instead of being ignored). Unfortunately, the cliprect system was wrongly put into common/ instead of amiga/.

  // Track border
  if (endtrack > starttrack){    
    struct WTracks *wtrack = NextWTrack(wtrack1);

    while(wtrack != NULL){
      //for(int i=0;i<num_tracks;i++){
      //printf("%d: %d\n", i, draw_border[i]);

      //struct WTracks *next = NextWTrack(wtrack2);

      //printf("    Drawing track header border for track %d\n", wtrack->l.num);
      
      GFX_Line(window,TRACK_SEPARATOR2B_COLOR_NUM,
               wtrack->x, wtrack->y,
               wtrack->x, wtrack->panonoff.y1 - 1,
               PAINT_BUFFER);

      if (wtrack==wtrack2)
        break;
      
      wtrack = NextWTrack(wtrack);
    }
  }

  // Text
  GFX_SetClipRect(window,x1, 0, x2, wblock->t.y1, PAINT_BUFFER);
  {
    static char temp[500];
    int wtrack_x1 = R_MAX(wtrack1->x, wblock->t.x1) + window->fontwidth/2;

    if (wtrack1->l.num==wtrack2->l.num)
      sprintf(temp,"%d:", wtrack1->l.num);
    else
      sprintf(temp,"%d->%d:", wtrack1->l.num, wtrack2->l.num);
    GFX_T_Text(
               window,TEXT_COLOR_NUM,temp,
               wtrack_x1,
               wtrack1->y+WTRACKS_SPACE-1,
               wtrack1->x2-wtrack1->x-1,
               TEXT_CLIPRECT|TEXT_BOLD|TEXT_NOTEXT,
               PAINT_BUFFER
               );
    
    int name_x = wtrack_x1 + GFX_get_text_width(window,temp) + window->fontwidth;
    const char *name = patch==NULL ? wtrack1->track->trackname : patch->name;
    int midi_channel = ATOMIC_GET(wtrack1->track->midi_channel);
    if (midi_channel){
      if (patch==NULL || patch->instrument!=get_MIDI_instrument()){
        snprintf(temp, 498, "%s [%d]", name, midi_channel+1);
        name = (const char*)&temp;
      }
    }
    GFX_T_Text(
               window,INSTRUMENT_NAME_COLOR_NUM, name,
               name_x,
               wtrack1->y+WTRACKS_SPACE-1,
               wtrack2->x2 - name_x, //(wtrack2->x2-window->fontwidth/2) - name_x,
               TEXT_SCALE|TEXT_NOTEXT, //|TEXT_CENTER,
               PAINT_BUFFER
               );
  }
  GFX_CancelClipRect(window,PAINT_BUFFER);
}