Esempio n. 1
0
/**
 * Mouse button release callback
 *
 */
gint
scorearea_button_release (GtkWidget * widget, GdkEventButton * event)
{
  DenemoProject *gui = Denemo.project;
  if (gui == NULL || gui->movement == NULL)
    return FALSE;
  last_directive = NULL;
  gboolean left = (event->button != 3);
  if(gui->movement->recording && (dragging_tempo || dragging_audio))
    {
            dragging_tempo = dragging_audio = FALSE;
            gdk_window_set_cursor (gtk_widget_get_window (Denemo.window), gdk_cursor_new (GDK_LEFT_PTR));       //FIXME? does this take time/hog memory
            return TRUE;
    }
  if (dragging_separator)
    {
      if (Denemo.prefs.learning)
        MouseGestureShow(_("Dragged line separator."), _("This allows the display to show more music, split into lines. The typeset score is not affected."),
          MouseGesture);
      dragging_separator = FALSE;
      return TRUE;
    }

  //g_signal_handlers_block_by_func(Denemo.scorearea, G_CALLBACK (scorearea_motion_notify), gui);
  if (left)
    lh_down = FALSE;
  selecting = FALSE;
  set_cursor_for (event->state & DENEMO_MODIFIER_MASK);
  transform_coords (&event->x, &event->y);
  set_cursor_y_from_click (gui, event->y);
  gtk_widget_queue_draw(Denemo.scorearea);
  perform_command (event->state, GESTURE_RELEASE, left);

  return TRUE;
}
Esempio n. 2
0
void menu_item::perform_command(unsigned n,const ptr_list_base<metadb_handle> & data,const GUID & caller)
{
	menu_item_v2 * this_v2 = service_query_t(menu_item_v2,this);
	if (this_v2)
	{
		this_v2->perform_command(n,data,caller);
		this_v2->service_release();
	}
	else
	{
		perform_command(n,data);
	}
}
Esempio n. 3
0
void isr_rs232_rx(void)
{
    packet_t incoming;
    char counter = 0;

    qr.link_down = 0;

    if( !X32_RS232_READ )
        return;

    incoming.header = X32_RS232_DATA; //read first byte (HEADER)

    while( !X32_RS232_READ )
    {
        if( counter++ > TIMEOUT_BUFFER_RX )
        {
            acknowledge(ACK_NEGATIVE);
            flush_buffer();
            return;
        }
        else
            ucatnap(SLEEP_BUFFER_RX);
    }

    incoming.command = X32_RS232_DATA; //read second byte (COMMAND)

    while( !X32_RS232_READ );
    {
        if( counter++ > TIMEOUT_BUFFER_RX )
        {
            acknowledge(ACK_NEGATIVE);
            flush_buffer();
            return;
        }
        else
            ucatnap(SLEEP_BUFFER_RX);
    }

    incoming.crc = X32_RS232_DATA; //read third byte (CRC)

    if( check_hamming(incoming) )
        perform_command(incoming.header, incoming.command);
    else
    {
        acknowledge(ACK_HAMMING);
        flush_buffer();
    }
}
Esempio n. 4
0
/**
 * Mouse button press callback
 *
 */
gint
scorearea_button_press (GtkWidget * widget, GdkEventButton * event)
{
  DenemoProject *gui = Denemo.project;
  if (gui == NULL || gui->movement == NULL)
    return FALSE;
  gboolean left = (event->button != 3);
  //if the cursor is at a system separator start dragging it
  gint allocated_height = get_widget_height (Denemo.scorearea);
  gint line_height = allocated_height * gui->movement->system_height;
  gint line_num = ((int) event->y) / line_height;
  last_event_x = event->x_root;
  last_event_y = event->y_root;
  //g_debug("diff %d\n", line_height - ((int)event->y)%line_height);

  if (dragging_separator == FALSE)
    if (line_height - ((int) event->y - 8) % line_height < 12)
      {
        if (Denemo.prefs.learning)
          MouseGestureShow(_("Dragging line separator."), _("This will allow the display to show more music, split into lines. The typeset score is not affected."),
            MouseGesture);
        dragging_separator = TRUE;
        return TRUE;
      }
  dragging_separator = FALSE;

  if(gui->movement->recording)
    {
     //g_debug("audio %f %f\n", event->x, event->y);


      if(event->y < 20*gui->movement->zoom /* see draw.c for this value, the note onsets are drawn in the top 20 pixels */)
        {
            if (event->type==GDK_2BUTTON_PRESS)
                {
                    gui->movement->marked_onset_position = (gint)event->x/gui->movement->zoom;
                    if(gui->movement->marked_onset_position < (gui->leftmargin+35) + SPACE_FOR_TIME + gui->movement->maxkeywidth) {
                         if (Denemo.prefs.learning)
                            MouseGestureShow(_("Double Click Note Onset"), _("This represents detected note onsets which occur\nbefore the start of the score.\nIf they are just noise,\nor if you are working on just a portion of the audio that is ok.\nOtherwise drag with left mouse button to synchronize\nwith the start of the score."),
          MouseGesture);

                    }
                    gtk_widget_queue_draw(Denemo.scorearea);
                    return TRUE;
                } else
                {
                    gdk_window_set_cursor (gtk_widget_get_window (Denemo.window), gdk_cursor_new (left?GDK_SB_H_DOUBLE_ARROW:GDK_X_CURSOR));
                    left? (dragging_audio = TRUE) : (dragging_tempo = TRUE);
                     if (Denemo.prefs.learning)
                     left? MouseGestureShow(_("Left Drag Note Onset"), _("This moves the audio to synchronize the start with the score.\nYou can use the Leadin button for this too."),
          MouseGesture) :
                        MouseGestureShow(_("Right Drag Note Onset"), _("This changes the tempo of the score.\nUse this to synchronize the beat after setting the start"),
          MouseGesture);
                    gtk_widget_queue_draw(Denemo.scorearea);
                    return TRUE;
                }
        }

    }


  //g_debug("before %f %f\n", event->x, event->y);
  transform_coords (&event->x, &event->y);
  //g_debug("after %f %f\n", event->x, event->y);


  gtk_widget_grab_focus (widget);
  gint key = gui->movement->maxkeywidth;
  gint cmajor = key ? 0 : 5;    //allow some area for keysig in C-major

  if (gui->lefts[line_num] == 0)
    return TRUE;                //On an empty system at the bottom where there is not enough room to draw another staff.

  struct placement_info pi;
  pi.the_staff = NULL;
  if (event->y < 0)
    get_placement_from_coordinates (&pi, event->x, 0, gui->lefts[line_num], gui->rights[line_num], gui->scales[line_num]);
  else
    get_placement_from_coordinates (&pi, event->x, event->y, gui->lefts[line_num], gui->rights[line_num], gui->scales[line_num]);
  if (pi.the_staff == NULL)
    return TRUE;                //could not place the cursor
  change_staff (gui->movement, pi.staff_number, pi.the_staff);


  if (left && (gui->movement->leftmeasurenum > 1) && (event->x < (gui->leftmargin+35) + SPACE_FOR_TIME + key) && (event->x > gui->leftmargin))
    {
      if (Denemo.prefs.learning)
        MouseGestureShow(_("Press Left."), _("This moved the cursor to the measure offscreen left. The display is shifted to place that measure on screen."),
          MouseGesture);
      set_currentmeasurenum (gui, gui->movement->leftmeasurenum - 1);
      write_status (gui);
      draw_score_area();
      return TRUE;
    }
  else if (pi.nextmeasure)
    {
      if ((pi.at_edge) && ((pi.the_obj==NULL) || ((pi.the_obj->next == NULL) && (pi.offend))))//crashed here with the_obj 0x131 !!!
        {
          if ((gui->movement->currentmeasurenum != gui->movement->rightmeasurenum) &&
                (!set_currentmeasurenum (gui, gui->movement->rightmeasurenum + 1)))
              set_currentmeasurenum (gui, gui->movement->rightmeasurenum);
          else if ((gui->movement->cursor_appending) &&
                (!set_currentmeasurenum (gui, gui->movement->rightmeasurenum + 1)))
              set_currentmeasurenum (gui, gui->movement->rightmeasurenum);




          if (gui->movement->currentmeasurenum != gui->movement->rightmeasurenum) {
            if (Denemo.prefs.learning)
              MouseGestureShow(_("Press Left."), _("This moved the cursor to the measure off-screen right. The display is shifted to move the cursor to the middle."),
                MouseGesture);
          write_status (gui);
          return TRUE;
        }
        }
    }


  if (pi.the_measure != NULL)
    {                           /*don't place cursor in a place that is not there */
      //gui->movement->currentstaffnum = pi.staff_number;
      //gui->movement->currentstaff = pi.the_staff;
      gui->movement->currentmeasurenum = pi.measure_number;
      gui->movement->currentmeasure = pi.the_measure;
      gui->movement->currentobject = pi.the_obj;
      gui->movement->cursor_x = pi.cursor_x;
      gui->movement->cursor_appending = (gui->movement->cursor_x == (gint) (g_list_length ((objnode *) ((DenemoMeasure*)gui->movement->currentmeasure->data)->objects)));
      set_cursor_y_from_click (gui, event->y);
      if (event->type==GDK_2BUTTON_PRESS)
                {
                    if(gui->movement->recording &&  !g_strcmp0 (((DenemoStaff *) gui->movement->currentstaff->data)->denemo_name->str, DENEMO_CLICK_TRACK_NAME))
                        {
                            gui->movement->marked_onset_position = (gint)event->x/gui->movement->zoom;
                            if (Denemo.prefs.learning)
                                MouseGestureShow(_("Double Click on Click Track"), _("This will mark the MIDI note onset."), MouseGesture);
                            return TRUE;

                        }

                    else
                        {
                          if (Denemo.prefs.learning)
                            MouseGestureShow(_("Double Click."), _("This gives information about the object at the cursor. Click on a notehead for information about a note in a chord."),
                              MouseGesture);
                                    display_current_object();
                                    return TRUE;
                        }
                }
            else
                {
                  if (Denemo.prefs.learning)
                    MouseGestureShow(_("Press Left."), _("This moved the cursor to the object position clicked. The cursor height becomes the clicked point."),
                      MouseGesture);
                            write_status (gui);
               }
            }

  gint offset = (gint) get_click_height (gui, event->y);

   if ((((DenemoStaff *) gui->movement->currentstaff->data)->voicecontrol != DENEMO_PRIMARY)
        && (gui->movement->leftmeasurenum == 1) && (event->x > gui->leftmargin)
        && ((event->x < (gui->leftmargin+35) + SPACE_FOR_TIME + key)))
    {
          infodialog(_("The clef shown here affects the display only (as this voice is displayed on the staff above)."
          " You can change the display clef using the clef menu."
          "\nWarning! you will get confused if you set the key signature or time signature of a voice different "
          "to the staff it is typeset on. Run the Staff/Voice property editor to adjust any inconsistencies."));

    }
  if ((((DenemoStaff *) gui->movement->currentstaff->data)->voicecontrol == DENEMO_PRIMARY) && (gui->movement->leftmeasurenum == 1) && (event->x > gui->leftmargin))
    {
      if (event->x < (gui->leftmargin+35) - cmajor)
        {
        if (offset<-10)
            {
                if (Denemo.prefs.learning)
                MouseGestureShow(_("Left on Staff name."), _("This pops up the built-in staff properties. For other properties of the current staff see the staff menu or the tools icon before the clef."),
                  MouseGesture);
                staff_properties_change_cb (NULL, NULL);
            }
        else
            {
              if (Denemo.prefs.learning)
                MouseGestureShow(_("Left on initial Clef."), _("This pops up the initial clef menu."),
                  MouseGesture);
              popup_menu ("/InitialClefEditPopup");
            }
          return TRUE;
        }
      else if (event->x < (gui->leftmargin+35) + key + cmajor)
        {
          if (left)
            {
              if (offset > 0 && (offset < STAFF_HEIGHT / 2))
                {
                  if (Denemo.prefs.learning)
                    MouseGestureShow(_("Left Click on blue."), _("This adds one sharp."),
                      MouseGesture);
                if ((gui->movement->currentmeasure->next==NULL)  || confirm (_("Initial Key Signature Change"), _("Sharpen Keysignature?")))
                  call_out_to_guile ("(d-SharpenInitialKeysigs)");
                }
              else if (offset > 0 && (offset < STAFF_HEIGHT))
                {
                  if (Denemo.prefs.learning)
                    MouseGestureShow(_("Left Click on red."), _("This adds one flat."),
                      MouseGesture);
                  if ((gui->movement->currentmeasure->next==NULL) || confirm (_("Initial Key Signature Change"), _("Flatten Keysignature?")))
                    call_out_to_guile ("(d-FlattenInitialKeysigs)");
                }
            }
          else
            {
              if (Denemo.prefs.learning)
                MouseGestureShow(_("Right Click on key."), _("This pops up the key signature menu."),
                    MouseGesture);
              popup_menu ("/InitialKeyEditPopup");
            }
          return TRUE;
        }
      else if (event->x < (gui->leftmargin+35) + SPACE_FOR_TIME + key)
        {
          if (Denemo.prefs.learning)
            MouseGestureShow(_("Click on Time."), _("This pops up the time signature menu."),
                    MouseGesture);
          popup_menu ("/InitialTimeEditPopup");
          return TRUE;
        }
    }

  if (event->x < gui->leftmargin)
    {
       if (gui->braces)
        {
                gint width = BRACEWIDTH * g_list_length (gui->braces);
                //gint count = (gui->leftmargin - event->x)/BRACEWIDTH;
                if ((gui->leftmargin - event->x) < width)
                {
                    gint count = 1 + (width - gui->leftmargin + event->x)/BRACEWIDTH;


                    if ((count>0) && (count <= g_list_length (gui->braces)))
                        {
                            DenemoBrace *brace = (DenemoBrace*)g_list_nth_data (gui->braces, count-1);
                            gint choice = choose_option (_("Editing Staff Groups (Braces)"), _("Edit Start Brace"), _("Edit End Brace"));
                            gint staffnum = choice?brace->startstaff:brace->endstaff;
                            //g_print ("Count is %d for start at %d\n", count, staffnum);
                            GtkWidget *menuitem = gtk_ui_manager_get_widget (Denemo.ui_manager, "/ObjectMenu/StaffMenu/StaffGroupings");
                            goto_movement_staff_obj (NULL, -1, staffnum, 1, 0, 0);
                            if (menuitem)
                                if (choice)
                                    gtk_menu_popup (GTK_MENU (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menuitem))), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME);
                                else
                                {
                                    if (staff_directive_get_tag ("BraceEnd"))
                                        call_out_to_guile ("(d-BraceEnd)");
                                    else
                                        warningdialog (_( "This staff grouping has no End Brace so it finishes on the lowest staff. Use the Staffs/Voices->Staff Groupings menu to place an End Brace on the desired staff"));
                                }
                            //note the popup returns as soon as the menu is popped up, so we can't go back to the original position.

                        }

                    return TRUE;
                }

        }

      if (pi.staff_number == gui->movement->currentstaffnum)
        {
          gint offset = (gint) get_click_height (gui, event->y);
          if (offset < STAFF_HEIGHT / 2)
            {
              if (((DenemoStaff *) gui->movement->currentstaff->data)->staff_directives, 1)
                {
                  if (Denemo.prefs.learning)
                    MouseGestureShow(_("Click on Staff Directives."), _("This pops up the staff directives menu for editing"),
                      MouseGesture);
                  edit_staff_properties ();//gtk_menu_popup (((DenemoStaff *) gui->movement->currentstaff->data)->staffmenu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
                }
              return TRUE;
            }
          else if (((DenemoStaff *) gui->movement->currentstaff->data)->voice_directives, 1)
            {
              if (Denemo.prefs.learning)
                MouseGestureShow(_("Click on Voice Directives."), _("This pops up the voice directives menu for editing"),
                    MouseGesture);
              edit_voice_properties ();//gtk_menu_popup (((DenemoStaff *) gui->movement->currentstaff->data)->voicemenu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
              return TRUE;
            }
        }
    }

  if (left)
    {
      if (!(GDK_SHIFT_MASK & event->state))
        gui->movement->markstaffnum = 0;
      lh_down = TRUE;
    }
  else
    {
      if (gui->movement->cursor_appending && (event->state==0))
        {
          if (Denemo.prefs.learning)
           {

                    MouseGestureShow(_("Right Click Appending."), _("This pops up the append menu"),
                        MouseGesture);

           }
          popup_menu ("/NoteAppendPopup");
          return TRUE;
        }

        if ((GDK_CONTROL_MASK & event->state) == GDK_CONTROL_MASK) {
            if (Denemo.prefs.learning)
                    MouseGestureShow(_("Control-Right Click."), _("This pops up menu for inserting barlines and many other sorts of objects"),
                        MouseGesture);
            gtk_menu_popup (GTK_MENU (gtk_widget_get_parent(gtk_ui_manager_get_widget (Denemo.ui_manager, "/ObjectMenu/Directives/Markings"))),
                            NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
            return TRUE;
        }
      if ((GDK_SHIFT_MASK & event->state) == GDK_SHIFT_MASK) {
            if (Denemo.prefs.learning)
                    MouseGestureShow(_("Shift-Right Click."), _("This allows editing the directives/attributes of the object at the cursor"),
                        MouseGesture);
            call_out_to_guile ("(d-EditSimilar 'once)");
            return TRUE;
        }
    }



  if (left && (GDK_SHIFT_MASK & event->state) && (GDK_CONTROL_MASK & event->state))
  {
     // if current object is directive, start dragging its graphic, dragging_display=TRUE

      DenemoObject *obj;
      if (Denemo.prefs.learning)
                    MouseGestureShow(_("Control-Shift-Drag."), _("This allows dragging objects in the display.\nAll sorts of directives such as staccato dots, ornaments, repeat marks etc can be dragged if the display is too cluttered.\nThe typeset score is unaffected.\nClick on a notehead to drag things attached to the notehead,\nor off the noteheads for things attached to the whole chord."),
                        MouseGesture);

    last_directive = get_next_directive_at_cursor ();
    if(last_directive)
        {
            score_status (Denemo.project, TRUE);
            return TRUE;
        }
    infodialog (_("Control-Shift-Drag is used to tidy up the Denemo display. Useful if Denemo has created a clutter with your input music.\nIf you have several things attached to one object you can move them in turn by dragging them in turn.\nNotes, Slurs and Ties are fixed but most other things can be moved to make the input music clear. Does not affect the typeset score!\nNB! if you have dragged something to one side of a note you have to control-shift-click on the note itself to drag it back - it is where the cursor is that counts."));
    return TRUE;
 }






  set_cursor_for (event->state | (left ? GDK_BUTTON1_MASK : GDK_BUTTON3_MASK));




  //displayhelper(Denemo.project);
  draw_score(NULL);//this is needed to refresh cached values such as the prevailing time signature, before the command is invoked

  perform_command (event->state | (left ? GDK_BUTTON1_MASK : GDK_BUTTON3_MASK), GESTURE_PRESS, left);

  return TRUE;
}
Esempio n. 5
0
/**
 * Mouse motion callback
 *
 */
gint
scorearea_motion_notify (GtkWidget * widget, GdkEventButton * event)
{
  DenemoProject *gui = Denemo.project;
  if (gui == NULL || gui->movement == NULL)
    return FALSE;
  if (Denemo.scorearea == NULL)
    return FALSE;
  gint allocated_height = get_widget_height (Denemo.scorearea);
  gint line_height = allocated_height * gui->movement->system_height;
  if(dragging_outside)
    {
          gint incrx, incry;
          incrx=incry=0;
          if(((gint)((last_event_x - event->x_root)/gui->movement->zoom)) != 0)
            {
                incrx = -(last_event_x - event->x_root)/gui->movement->zoom;
                last_event_x = event->x_root;
            }
          if( ((gint)((last_event_y - event->y_root)/gui->movement->zoom)) != 0)
            {
                incry = -(last_event_y - event->y_root)/gui->movement->zoom;
                last_event_y = event->y_root;
            }
        if((dragging_outside==DRAG_DIRECTION_RIGHT) && (incrx > 1)
            || ((dragging_outside==DRAG_DIRECTION_LEFT) && (incrx < -1))
            || ((dragging_outside==DRAG_DIRECTION_UP) && (incry < 0))
            || ((dragging_outside==DRAG_DIRECTION_DOWN) && (incry > 0)))
            extend_selection(dragging_outside);
    return TRUE;
    }
  if (event->y < 0)
    event->y = 0.0;
  gint line_num = ((int) event->y) / line_height;


   if (last_directive && (GDK_SHIFT_MASK & event->state) && (GDK_CONTROL_MASK & event->state))
      {
          gint incrx, incry;
          incrx=incry=0;
          if(((gint)((last_event_x - event->x_root)/gui->movement->zoom)) != 0)
            {
                incrx = (last_event_x - event->x_root)/gui->movement->zoom;
                last_event_x = event->x_root;
            }
          if( ((gint)((last_event_y - event->y_root)/gui->movement->zoom)) != 0)
            {
                incry = (last_event_y - event->y_root)/gui->movement->zoom;
                last_event_y = event->y_root;
            }

        if(last_directive->graphic)
            {
                last_directive->gx -= incrx;
                last_directive->gy -= incry;
            }
        else
            {
                last_directive->tx -= incrx;
                last_directive->ty -= incry;
            }
        draw_score_area();

        return TRUE;
      }



  if(gui->movement->recording && dragging_audio)
    {
        if(gui->movement->recording->type == DENEMO_RECORDING_MIDI)
        {
            #if 0
            //This is moving only the NoteOn, so it could be moved later than the note off, and indeed later than a later note in the stream
            //- quite a bit more work needed to drag MIDI to correct the timing.
            smf_event_t *midievent;
            GList *marked_onset = gui->movement->marked_onset;
            if(marked_onset)
                {
                midievent = ((DenemoRecordedNote *)marked_onset->data)->event;
                gint shift =  2500*(event->x_root - last_event_x)/gui->movement->zoom;
                g_debug (" %f (%f %f)",shift/(double)gui->movement->recording->samplerate,
                    midievent->time_seconds,
                    ((DenemoRecordedNote *)marked_onset->data)->timing/(double)gui->movement->recording->samplerate) ;

                ((DenemoRecordedNote *)marked_onset->data)->timing += shift;

                midievent->time_seconds += shift/(double)gui->movement->recording->samplerate;
                }
            #endif
            g_warning("No drag for MIDI yet");
            return TRUE;
        }

        gui->movement->recording->leadin -= 500*(event->x_root - last_event_x)/gui->movement->zoom;//g_debug("%d %d => %d\n", (int)(10*last_event_x), (int)(10*event->x_root), (int)(10*last_event_x) - (int)(10*event->x_root));
        last_event_x = event->x_root;
        update_leadin_widget ( gui->movement->recording->leadin/(double)gui->movement->recording->samplerate);
        gtk_widget_queue_draw(Denemo.scorearea);
        return TRUE;
    }
  if(gui->movement->recording && dragging_tempo)
    {
        gdouble change = (event->x_root - last_event_x)/gui->movement->zoom;
        last_event_x = event->x_root;
        struct placement_info pi;
        get_placement_from_coordinates (&pi, event->x, 0, gui->lefts[line_num], gui->rights[line_num], gui->scales[line_num]);
        change /= pi.measure_number;
        update_tempo_widget ( change);
        set_tempo ();
        score_status (Denemo.project, TRUE);
        exportmidi (NULL, gui->movement);
        gtk_widget_queue_draw(Denemo.scorearea);
        return TRUE;
    }
#define DENEMO_MINIMUM_SYSTEM_HEIGHT (0.01)


  if (dragging_separator)
    {
      gui->movement->system_height = event->y / get_widget_height (Denemo.scorearea);
      if (gui->movement->system_height < DENEMO_MINIMUM_SYSTEM_HEIGHT)
        gui->movement->system_height = DENEMO_MINIMUM_SYSTEM_HEIGHT;
      if (gui->movement->system_height > 1.0)
        gui->movement->system_height = 1.0;
      scorearea_configure_event (Denemo.scorearea, NULL);
      draw_score_area();
      return TRUE;
    }

  if (line_height - ((int) event->y - 8) % line_height < 12)
    gdk_window_set_cursor (gtk_widget_get_window (Denemo.window), gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW));
  else
    gdk_window_set_cursor (gtk_widget_get_window (Denemo.window), gdk_cursor_new (GDK_LEFT_PTR));       //FIXME? does this take time/hog memory

  transform_coords (&event->x, &event->y);
  //g_debug("Marked %d\n", gui->movement->markstaffnum);


  if (gui->lefts[line_num] == 0)
    return TRUE;




  if (lh_down || (selecting && gui->movement->markstaffnum))
    {
      struct placement_info pi;
      pi.the_staff = NULL;
      if (event->y < 0)
        get_placement_from_coordinates (&pi, event->x, 0, gui->lefts[line_num], gui->rights[line_num], gui->scales[line_num]);
      else
        get_placement_from_coordinates (&pi, event->x, event->y, gui->lefts[line_num], gui->rights[line_num], gui->scales[line_num]);
      if (pi.the_staff == NULL)
        return TRUE;            //could not place the cursor
      if (pi.the_measure != NULL)
        {                       /*don't place cursor in a place that is not there */
          change_staff (gui->movement, pi.staff_number, pi.the_staff);
          gui->movement->currentmeasurenum = pi.measure_number;
          gui->movement->currentmeasure = pi.the_measure;
          gui->movement->currentobject = pi.the_obj;
          gui->movement->cursor_x = pi.cursor_x;
          gui->movement->cursor_appending = (gui->movement->cursor_x == (gint) (g_list_length ((objnode *) ((DenemoMeasure*)gui->movement->currentmeasure->data)->objects)));

          set_cursor_y_from_click (gui, event->y);
          if (lh_down & !selecting)
            {
              if (gui->movement->markstaffnum)
                set_point (NULL, NULL);
              else
                set_mark (NULL, NULL);
              selecting = TRUE;
            }
          calcmarkboundaries (gui->movement);
          if (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))
            perform_command (event->state, GESTURE_MOVE, event->state & GDK_BUTTON1_MASK);

          /* redraw to show new cursor position  */
          draw_score_area();
        }
    }

  if (Denemo.project->midi_destination & MIDICONDUCT)
    {
      advance_time (0.01);
      return TRUE;
    }
  return TRUE;
}
Esempio n. 6
0
int IndieLib() {
	//-------------------Constants------------------
	enum emode {menu, create, config};

	const char FPS =								60;

	const float dcam =								0.05f;

	const char prompt[] =							">\t";
	
	//----------------Logic variables---------------

	bool show_b_areas =								true;

	emode mode =									create;
	emode prev_mode =								create;

	float dm =										0;

	//--------------------Engine--------------------

	CIndieLib *prog = CIndieLib::Instance();
	if (!prog->Init()) return 1;
	prog->Window->SetTitle("Level Editor 1.1-alpha");
	//prog->Window->Cursor(true);

	// Render timer

	IND_Timer render_timer;
	int ticks =										0;
	int last_frame =								0;
	render_timer.Start();

	// Camera

	float cam_x =									(float) prog->Window->GetWidth() / 2;
	float cam_y =									(float) prog->Window->GetHeight() / 2;
	IND_Camera2d cam((int) cam_x, (int) cam_y);
	IND_Camera2d bcam((int) cam_x, (int) cam_y);
	
	//-------------------Resources------------------

	IND_Font t_font;
	IND_Entity2d menu_e;

	try {
		if (!prog->FontManager->Add(&t_font, "..\\res\\font_small.png", "..\\res\\font_small.xml", IND_ALPHA, IND_32))
			throw res_error();
		if (!prog->Entity2dManager->Add(4, &menu_e)) throw res_error();
	}
	catch (res_error) {
		prog->End();
		return 2;
	}

	//-----------Menu and additional info-----------

	cmd_line cmd_menu;
	
	char cmd_str[520];
	char buf[10];

	strcpy(cmd_str, prompt);

	menu_e.SetFont(&t_font);
	menu_e.SetAlign(IND_LEFT);
	menu_e.SetCharSpacing(-8);
	menu_e.SetLineSpacing(18);
	menu_e.SetText(cmd_str);
	menu_e.SetPosition(5, (float) (prog->Window->GetHeight() - 25), 0);
	menu_e.SetShow(false);

	// Information
	
	info tile_info;

	prog->Entity2dManager->Add(4, &tile_info.get_entity());
	tile_info.set_font(t_font);

	info lvl_info;
	bool update_info =								true;

	prog->Entity2dManager->Add(4, &lvl_info.get_entity());
	lvl_info.set_font(t_font);
	lvl_info.set_position(prog->Render->GetViewPortX() + 5, prog->Render->GetViewPortY() + 5, 0);
	lvl_info.add_text(unnamed_lt_file);

	//------------------Tiles manager---------------

	lt_manager ltm;
	try {
		if (!ltm.load_textures("..\\textures")) throw tm_init_fail();
	}
	catch (tm_init_fail) {
		prog->End();
		return 3;
	}

	//-------------Cofiguration manager-------------

	conf_manager conf_m;
	
	//-----------------Tile cursor------------------

	tile_cursor tcursor;

	float cur_dx = 0;
	float cur_dy = 0;

	try {
		if (!tcursor.init(*prog)) throw cursor_init_fail();
	}
	catch (cursor_init_fail) {
		prog->End();
		return 3;
	}
	tcursor.set_textures(ltm.get_textures());
	tcursor.set_tiles(ltm.get_tiles(0));

	//-----------------Config cursor----------------

	config_cursor ccursor(conf_m);

	try {
		if (!ccursor.init(*prog)) throw cursor_init_fail();
	}
	catch (cursor_init_fail) {
		prog->End();
		return 3;
	}
	ccursor.hide();

	editing_cursor *cursor;
	if (mode == create) cursor = &tcursor;

	lvl_info.add_text("\nTile set: ");
	lvl_info.add_text(tcursor.cur_tiles().get_name());
	
	//-------------------Main loop------------------

	while (!prog->Input->OnKeyPress(IND_ESCAPE) && !prog->Input->Quit()) {
		// Input update
		prog->Input->Update();

		// Count time for next rendering
		ticks = render_timer.GetTicks();
		
		// ~ button press (show command line)
		if (prog->Input->OnKeyPress(IND_BACKQUOTE) && !tcursor.active_tile()) {
			if (!menu_e.IsShow()) {
				prev_mode = mode;
				mode = menu;
			} else mode = prev_mode;

			menu_e.SetPosition((float) (cam_x - prog->Window->GetWidth() / 2 + 5),
				(float) (cam_y + prog->Window->GetHeight() / 2 - 25), 0);
			menu_e.SetShow(!menu_e.IsShow());
		}

		// Changing level info position
		lvl_info.set_position((int) cam_x - prog->Window->GetWidth() / 2 + 5,
			(int) cam_y - prog->Window->GetHeight() / 2 + 5, 0);
		
		// Changing active tile info position
		tile_info.set_position((int) cam_x + prog->Window->GetWidth() / 2 - 100,
			(int) cam_y - prog->Window->GetHeight() / 2 + 5, 0);

		//---------------Updating input due to active mode---------------
		
		switch (mode) {
		case menu: {
			// Menu input update
			char ch = '\0';

			for (char key = 97; key <= 122; key++)
				if (prog->Input->OnKeyPress(key - 97)) ch =			key;
			for (char key = 48; key <= 57; key++)
				if (prog->Input->OnKeyPress(key - 22)) ch =			key;
			if (prog->Input->OnKeyPress(IND_SPACE)) ch =			' ';
			if (prog->Input->OnKeyPress(IND_MINUS)) ch =			'-';
			//if (prog->Input->OnKeyPress(IND_AT)) ch =				':';
			//if (prog->Input->OnKeyPress(IND_CARET)) ch =			'_';
			if (prog->Input->OnKeyPress(IND_BACKSLASH)) ch =		'\\';
			if (prog->Input->OnKeyPress(IND_PERIOD)) ch =			'.';

			if (prog->Input->OnKeyPress(IND_BACKSPACE) || prog->Input->IsKeyPressed(IND_BACKSPACE, 100)) {
				cmd_menu.pop_back();
				strcpy(cmd_str, prompt);
				strcat(cmd_str, cmd_menu.get_string());
			}

			if (ch) {
				cmd_menu.push_back(ch);
				strcpy(cmd_str, prompt);
				strcat(cmd_str, cmd_menu.get_string());
			}

			// Performing command
			if (prog->Input->OnKeyPress(IND_RETURN)) {
				if (perform_command(cmd_menu.parse(), ltm, conf_m)) {
					strcpy(cmd_str, prompt);

					menu_e.SetShow(false);
					mode =											prev_mode;
					update_info =									true;

				} else {
					strcpy(cmd_str, prompt);
					strcat(cmd_str, "bad command");
				}
				cmd_menu.clear();
			}
				   } break;

		case create: {
			// Cursor update
			cursor_update(*prog, cursor, cur_dx, cur_dy);
			tcursor_update(*prog, tcursor);

			// 1 button press (set ground as current tile set)
			if (prog->Input->OnKeyPress(IND_1) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(0));
				update_info =										true;
			}

			// 2 button press (set terrain as current tile set)
			if (prog->Input->OnKeyPress(IND_2) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(1));
				update_info =										true;
			}

			// 3 button press (set items as current tile set)
			if (prog->Input->OnKeyPress(IND_3) && !tcursor.active_tile()) {
				tcursor.set_tiles(ltm.get_tiles(2));
				update_info =										true;
			}

					 } break;

		case config: {
			cursor_update(*prog, cursor, cur_dx, cur_dy);
					 } break;
		}

		// Non menu actions
		if (mode != menu) {
			
			// Tab button press (show/hide bounding areas OR switch working mode)
			if (prog->Input->OnKeyPress(IND_TAB))
				if (prog->Input->IsKeyPressed(IND_LCTRL)) {
					switch (mode) {
					case create:
						if (*ltm.get_lt_file() && !cursor->active_tile()) {
							mode =									config;
							cursor =								&ccursor;
							tcursor.hide();

							if (conf_m.get_doors_count())
								conf_m.update();
							else conf_m.create(ltm.get_textures(), ltm.get_tiles(1));
						}
						break;

					case config:
						mode =										create;
						cursor =									&tcursor;
						ccursor.hide();

						break;
					}
					cursor->show();
					update_info =									true;

				} else show_b_areas = !show_b_areas;

			// Camera update
			camera_update(*prog, cam, bcam, cur_dx, cur_dy, cam_x, cam_y, dm * dcam);
		}

		// Editor info
		if (update_info) {
			lvl_info.set_text("Mode: ");
			if (mode == create)
				lvl_info.add_text("create");
			else lvl_info.add_text("config");
			lvl_info.add_text("\nFile: ");
			if (*ltm.get_lt_file())
				lvl_info.add_text(ltm.get_lt_file());
			else lvl_info.add_text(unnamed_lt_file);
			lvl_info.add_text("\nTile set: ");
			lvl_info.add_text(tcursor.cur_tiles().get_name());

			update_info =											false;
		}

		// Tile info

		if (tcursor.active_tile()) {
			tile_info.set_text("Z pos: ");
			tile_info.add_text(itoa(tcursor.active_tile()->GetPosZ(), buf, 10));
			tile_info.add_text("\nZ angle: ");
			tile_info.add_text(itoa((int) tcursor.active_tile()->GetAngleZ(), buf, 10));
			tile_info.add_text("\nScale: ");
			tile_info.add_text(itoa((int) tcursor.active_tile()->GetScaleX(), buf, 10));
			tile_info.add_text(".");

			if ((int) (tcursor.active_tile()->GetScaleX() * 10) % 10 == 0)
				tile_info.add_text("0");
			if (tcursor.active_tile()->GetScaleX() * 100 < 100)
				tile_info.add_text(itoa((int) (tcursor.active_tile()->GetScaleX() * 100), buf, 10));
			else tile_info.add_text(itoa((int) (tcursor.active_tile()->GetScaleX() * 100) % 100, buf, 10));
		} else {
			tile_info.set_text("");
		}

		// Rendering

		if (ticks > last_frame + 1000/FPS) {
			
			// Viewport & camera
			prog->Render->ClearViewPort(0, 0, 0);
			prog->Render->SetViewPort2d(0, 0, prog->Window->GetWidth(), prog->Window->GetHeight());
			prog->Render->SetCamera2d(&cam);

			// Scene
			prog->Render->BeginScene();
			
			prog->Entity2dManager->RenderEntities2d(background_layer);
			prog->Entity2dManager->RenderEntities2d(objects_layer);
			prog->Entity2dManager->RenderEntities2d(items_layer);
			if (show_b_areas) {
				prog->Entity2dManager->RenderCollisionAreas(background_layer, 0, 0, 255, 255);
				prog->Entity2dManager->RenderCollisionAreas(objects_layer, 255, 0, 0, 255);
				prog->Entity2dManager->RenderCollisionAreas(items_layer, 0, 255, 0, 255);
			}
			
			prog->Render->SetCamera2d(&bcam);
			
			prog->Entity2dManager->RenderEntities2d(4);
			prog->Entity2dManager->RenderEntities2d(5);
			prog->Entity2dManager->RenderCollisionAreas(5, 255, 0, 0, 255);
			if (mode == config)
				conf_m.render_links(*prog->Render);
			
			prog->Render->EndScene();

			dm = prog->Render->GetFrameTime() / 1000.0f;
			last_frame = ticks;
		}
	}

	// Finishing

	render_timer.Stop();
	prog->End();

	return 0;
}
Esempio n. 7
0
//return the value of perform_command if executed or "" if keypress is part of a two-key shortcut, or NULL toherwise
gchar *
process_key_event (GdkEventKey * event, gchar * perform_command ())
{
  keymap *the_keymap = Denemo.map;
  //g_debug("\n********\nCaps Lock %x?\n\n********\nShifted %x?\n", event->state&GDK_LOCK_MASK,          event->state&GDK_SHIFT_MASK     );
  {
    gint state;
    state = (lock_mask (event->keyval) ^ event->state);
    if (state || ((event->keyval == GDK_Caps_Lock) || (event->keyval == GDK_Num_Lock)))
      set_cursor_for (state);   // MUST LOOK AHEAD to state after keypress HERE CATCH modifiers and set the cursor for them.....
  }
  dnm_clean_event (event);


  if (isModifier (event))
    return NULL;

  /* Look up the keystroke in the keymap and execute the appropriate
   * function */
  static GString *prefix_store = NULL;
  if (!prefix_store)
    prefix_store = g_string_new ("");

  gint command_idx = lookup_command_for_keyevent (event);
  if ((prefix_store->len == 0) && (command_idx != -1))
    {
      const gchar *command_name = lookup_name_from_idx (the_keymap, command_idx);
      if (command_name)
        {
          if (Denemo.prefs.learning)
            {
              gchar *name = dnm_accelerator_name (event->keyval, event->state);
              KeyStrokeShow (name, command_idx, TRUE);
              g_free (name);
            }
          if (Denemo.ScriptRecording)
                        if (idx_has_callback (the_keymap, command_idx))
                            {
                                append_scheme_call ((gchar *) command_name);
                            }
          //g_debug("Single Key shortcut %s invokes %s\n", dnm_accelerator_name(event->keyval, event->state), command_name);
          return perform_command (command_name, event);
        }
      else
        {
          g_warning ("Error: action %i has no name", command_idx);
          return NULL;
        }
    }

  /*  we create a store for the prefix char and look to see if it is populated when a keystroke is received. If it is populated, we try for the two-key combination, {???else we try for the single key, and if that fails populate the store. OR if it fails clear store}. If the two-key combination works we clear the store. If the two-key combination fails we try for the single key, if that succeeds we clear the store if it fails we set the store to the unresolved keystroke.  */

  gchar *ret = NULL;
  if (prefix_store->len)
    {
      gchar *name = dnm_accelerator_name (event->keyval, event->state);
      //g_debug("second key %s\n", name);
      g_string_append_printf (prefix_store, "%c%s", ',', name);
      command_idx = lookup_command_for_keybinding_name (Denemo.map, prefix_store->str);

      if (command_idx != -1)
        {
          const gchar *command_name = lookup_name_from_idx (the_keymap, command_idx);
          if (command_name)
            {
              if (Denemo.prefs.learning)
                {
                  KeyStrokeShow (prefix_store->str, command_idx, FALSE);
                }
                    if (Denemo.ScriptRecording)
                            if (idx_has_callback (the_keymap, command_idx))
                                {
                                    append_scheme_call ((gchar *) command_name);
                                }
              ret = perform_command (command_name, event);
            }
        }
      else
        {                       //Two key name was not a binding
          ret = NULL;
          write_status (Denemo.project);
          if ((Denemo.project->view != DENEMO_MENU_VIEW) || Denemo.prefs.learning)
            {
                            Denemo.prefs.learning = TRUE;
              KeyStrokeDecline (prefix_store->str);
            }
          toggle_to_drawing_area (TRUE);        //restore menus, in case the user is lost and needs to look up a keypress
          if (Denemo.project->view != DENEMO_MENU_VIEW)
                        toggle_to_drawing_area (TRUE);
        }
      g_string_assign (prefix_store, "");
      Denemo.continuations = NULL;
      return ret;
    }
  else
    {                           //no prefix stored
      gchar *name = dnm_accelerator_name (event->keyval, event->state); //FIXME free name

      if ((Denemo.continuations = (GList *) g_hash_table_lookup (Denemo.map->continuations_table, name)))
        {
          GList *g;
          GString *continuations = g_string_new ("");
          for (g = Denemo.continuations; g; g = g->next)
            g_string_append_printf (continuations, "%s%s", (gchar *) g->data, _(", or "));
          g_string_printf (prefix_store, _( "Prefix Key %s, waiting for key %stype Esc to abort"), name, continuations->str);
          g_string_free (continuations, TRUE);
          if (Denemo.prefs.immediateplayback)
              play_note (DEFAULT_BACKEND, 0, 9, 61, 300, 127 * Denemo.project->movement->master_volume);
          //gtk_statusbar_pop (GTK_STATUSBAR (Denemo.statusbar), Denemo.status_context_id);
          gtk_label_set_text (GTK_LABEL (Denemo.statuslabel), prefix_store->str);
          g_string_assign (prefix_store, name);
          if (Denemo.prefs.learning)
            {
              KeyStrokeAwait (name);
            }
          return "";            //continuation available
        }
      else
        {
          if ((Denemo.project->view != DENEMO_MENU_VIEW) || Denemo.prefs.learning)
            {
                            Denemo.prefs.learning = TRUE;
              KeyStrokeDecline (name);
            }
          toggle_to_drawing_area (TRUE);  //restore menus, in case the user is lost and needs to look up a keypress
          if (Denemo.project->view != DENEMO_MENU_VIEW)
                        toggle_to_drawing_area (TRUE);
        }
      return NULL;
    }
  return NULL;
}