root/core/levent.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. levent_index_for_name
  2. levent_index_for_id
  3. levent_count
  4. levent_id_for_name
  5. levent_name_for_id
  6. levent_post_to_ui_by_name
  7. levent_set_record
  8. levent_set_play

   1 #include "stdlib.h"
   2 #include "levent.h"
   3 
   4 /* function dealing with "logical events"*/
   5 unsigned levent_index_for_name(const char *name)
   6 {
   7   unsigned i;
   8   // TODO could check for id=-1 or id=0, both show up at end of table ?
   9   for (i=0; levent_table[i].name; i++) {
  10     // case insensitive might be better
  11     if (strcmp(levent_table[i].name,name) == 0) {
  12         return i;
  13     }
  14   }
  15   return LEVENT_INVALID_INDEX;
  16 }
  17 
  18 unsigned levent_index_for_id(unsigned id)
  19 {
  20   unsigned i;
  21   // TODO could check for id=-1 or id=0, both show up at end of table ?
  22   for (i=0; levent_table[i].name; i++) {
  23     // case insensitive might be better
  24     if (id == levent_table[i].id) {
  25         return i;
  26     }
  27   }
  28   return LEVENT_INVALID_INDEX;
  29 }
  30 
  31 unsigned levent_count(void)
  32 {
  33   static unsigned num_levents = 0;
  34   if(!num_levents) {
  35     levent_def *ev;
  36     // TODO could check for id=-1 or id=0, both show up at end of table ?
  37     for (ev = levent_table; ev->name; ev++) {
  38       num_levents++;
  39     }
  40   }
  41   return num_levents;
  42 }
  43 
  44 unsigned levent_id_for_name(const char *name)
  45 {
  46   unsigned i = levent_index_for_name(name);
  47   if (i!=LEVENT_INVALID_INDEX)
  48     return levent_table[i].id;
  49   else
  50     return 0; // or -1 ? both appear at the end of the event list
  51 }
  52 
  53 const char * levent_name_for_id(unsigned id)
  54 {
  55   unsigned i = levent_index_for_id(id);
  56   if (i!=LEVENT_INVALID_INDEX)
  57     return levent_table[i].name;
  58   else
  59     return NULL;
  60 }
  61 
  62 // note, slow linear search every time
  63 int levent_post_to_ui_by_name(const char *name)
  64 {
  65         unsigned id=levent_id_for_name(name);
  66         if(id) {
  67                 PostLogicalEventToUI(id,0);
  68                 return 1;
  69         }
  70         return 0;
  71 }
  72 
  73 void levent_set_record(void) {
  74         levent_post_to_ui_by_name("PressRecButton");
  75         levent_post_to_ui_by_name("UnpressRecButton");
  76 }
  77 
  78 void levent_set_play(void) {
  79         levent_post_to_ui_by_name("PressPBButton");
  80         levent_post_to_ui_by_name("UnpressPBButton");
  81 }

/* [<][>][^][v][top][bottom][index][help] */