Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

JogShuttle Class Reference

Class to encapsulate an abstract JogShuttle device. More...

#include <jogshuttle.h>

Collaboration diagram for JogShuttle:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~JogShuttle ()
 Destructor.
bool start ()
 Start the GDK input handler if enabled.
void stop ()
 Stop the GDK input handler.
void registerCallback (void *user, JogShuttleCallback callback)
 Register callback.
void deregisterCallback ()
 Deegister callback.
media_ctrl_keygetKeyset ()

Static Public Member Functions

static JogShuttlegetInstance ()
 Singleton getInstance method.

Protected Member Functions

void inputCallback (gint source, GdkInputCondition condition)
 The GDK input callback function.
 JogShuttle ()
 Constructor.

Private Member Functions

void jog (int dir)
 Handle movement on the jog dial.
void shuttle (int angle)
 Handle movement of the shuttle ring.
void button (struct media_ctrl_event *)
 Handle key press.
void button_old (int code)

Private Attributes

JogShuttleCallback _callback
 Placeholder for callbacks.
void * _callbackdata
 Any client supplied callbackdata is here.
media_ctrl _ctrl
int input_
gint monitorTag_
unsigned short _modifier_code
media_ctrl_key_modifier

Static Private Attributes

static JogShuttle_instance = NULL
 Singleton pattern.

Friends

void JogShuttle_inputCallback (gpointer data, gint source, GdkInputCondition condition)
 A C wrappper for the GDK input handler callback.

Detailed Description

Class to encapsulate an abstract JogShuttle device.

This class is used by the kino core to interact with a JogShuttle device. (Also used by the preference dialog for configuration). It depends on the GDK input system, and uses the libmediactrl stuff to translate different (more or less broken) devices events into something that resembles the linux event system. It also keeps track of modifier keys, that is, up to two keys pressed in succesion.

Definition at line 49 of file jogshuttle.h.


Constructor & Destructor Documentation

JogShuttle::JogShuttle  )  [protected]
 

Constructor.

Definition at line 126 of file jogshuttle.cc.

References _ctrl, media_ctrl::device, and start().

Referenced by getInstance().

00126                        :
00127         _callback( NULL ),
00128         input_( -1 ),
00129         monitorTag_( -1 ),
00130         _modifier_code( 0 )
00131 {
00132     _ctrl.device = NULL;
00133     start();
00134 }

JogShuttle::~JogShuttle  ) 
 

Destructor.

Remove the callback function from the GDK input handler.

Definition at line 140 of file jogshuttle.cc.

References _ctrl, input_, media_ctrl_close(), and monitorTag_.

00141 {
00142     if ( input_ >= 0 )
00143     {
00144         gdk_input_remove( monitorTag_ );
00145         media_ctrl_close(&_ctrl);
00146     }
00147 }


Member Function Documentation

void JogShuttle::button struct media_ctrl_event ev  )  [private]
 

Handle key press.

Parameters:
ev The key event Modifier keys - we maintain the state of the first key that is pressed down. This is a "poor man"s way of doing modifier keys. It means that we can press a single key, keep it down, and press a number of others. Any key can be used as a modifier key, although you would probably want to not assign an action to a modifier key when first pressed. There is no way to react to multiple modifier keys though.

Definition at line 267 of file jogshuttle.cc.

References _callback, _callbackdata, _modifier_code, media_ctrl_key::action, media_ctrl_event::code, Preferences::getInstance(), media_ctrl_event::index, KEY_RELEASE, processCommand(), and media_ctrl_event::value.

Referenced by inputCallback().

00268 {
00269     /* Figure out what codes to use */
00270     unsigned short first;
00271     unsigned short second;
00272 
00273     /* 
00274         Release may need to clear a modifier key
00275     */
00276     if ( ev->value == KEY_RELEASE && _modifier_code != 0 )
00277     {
00278         _modifier_code = 0;
00279         return;
00280     }
00281 
00282     /* Do a callback or action based command */
00283     if ( _callback != NULL )
00284     {
00285         /* This is a key press - if there are no modifier, make sure that
00286         this is saved */
00287         if ( _modifier_code == 0 )
00288             _modifier_code = ev->index + 1;
00289 
00290         if ( _modifier_code != ev->index + 1 )
00291         {
00292             first = _modifier_code - 1;
00293             second = ev->index + 1;
00294         }
00295         else
00296         {
00297             first = ev->index; /* Same as modifier */
00298             second = 0;
00299         }
00300         _callback( _callbackdata, first, second );
00301     }
00302     else
00303     {
00304         /* This is a key press - if there are no modifier, make sure that
00305         this is saved */
00306         if ( _modifier_code == 0 )
00307             _modifier_code = ev->code;
00308 
00309         if ( _modifier_code != ev->code )
00310         {
00311             first = _modifier_code;
00312             second = ev->code;
00313         }
00314         else
00315         {
00316             first = ev->code; /* Same as modifier */
00317             second = 0;
00318         }
00319         
00320         /* Get the action from the prefs */
00321         string action
00322         = Preferences::getInstance()._JogShuttleMappings[
00323               make_pair( first, second ) ]._action;
00324 
00325         if ( "" != action )
00326         {
00327             gdk_threads_enter();
00328             processCommand( ( char * ) action.c_str() );
00329             gdk_threads_leave();
00330         }
00331     }
00332     return ;
00333 
00334 }

void JogShuttle::button_old int  code  )  [private]
 

void JogShuttle::deregisterCallback  ) 
 

Deegister callback.

Deregister an interest in getting notification when buttons are pressed

Parameters:
callback Function to stop calling

Definition at line 206 of file jogshuttle.cc.

References _callback.

00207 {
00208     if ( _callback == NULL )
00209         g_warning( "JogShuttle::deregisterCallback - not registered\n" );
00210     _callback = NULL;
00211 }

JogShuttle & JogShuttle::getInstance  )  [static]
 

Singleton getInstance method.

Standard pattern. Non-threadsafe, but first instance gets called from the commands.cc which should be OK.

Definition at line 117 of file jogshuttle.cc.

References _instance, and JogShuttle().

Referenced by kinoInitialise(), on_checkbutton_jogshuttle_toggled(), on_optionmenu_jogshuttle_action_clicked(), on_optionmenu_jogshuttle_firstsecond_button_clicked(), on_preferences_activate(), on_preferences_dialog_cancel_button_clicked(), on_preferences_dialog_destroy_event(), on_preferences_dialog_ok_button_clicked(), and startJogShuttle().

00118 {
00119     if ( _instance == NULL )
00120         _instance = new JogShuttle();
00121     return *_instance;
00122 }

struct media_ctrl_key * JogShuttle::getKeyset  ) 
 

Definition at line 213 of file jogshuttle.cc.

References _ctrl, media_ctrl::device, and media_ctrl_device::keys.

00214 {
00215     if ( _ctrl.device != NULL ) return _ctrl.device->keys;
00216     else return NULL;
00217 }

void JogShuttle::inputCallback gint  source,
GdkInputCondition  condition
[protected]
 

The GDK input callback function.

GDK calls this whenever input is received. It is hooked into the system during object construction.

Definition at line 344 of file jogshuttle.cc.

References _ctrl, button(), media_ctrl_event::code, jog(), MEDIA_CTRL_EVENT_JOG, MEDIA_CTRL_EVENT_KEY, MEDIA_CTRL_EVENT_NONE, MEDIA_CTRL_EVENT_SHUTTLE, media_ctrl_read_event(), shuttle(), stop(), media_ctrl_event::type, and media_ctrl_event::value.

Referenced by JogShuttle_inputCallback().

00345 {
00346     g_return_if_fail( this != NULL );
00347     // g_return_if_fail( input_ >= 0 );
00348     // g_return_if_fail( input_ == source );
00349     if ( condition != GDK_INPUT_READ )
00350         stop();
00351     g_return_if_fail( condition == GDK_INPUT_READ );
00352 
00353     struct media_ctrl_event ev;
00354     
00355     ev.type = MEDIA_CTRL_EVENT_NONE;
00356     media_ctrl_read_event(&_ctrl, &ev);
00357 
00358 
00359     /* We can get four "kinds" of events:
00360 
00361     ev.type == MEDIA_CTRL_EVENT_NONE (0x00)
00362     An event that actually isnt one... Since we read every event
00363     from the input subsystem, we sometimes get double events 
00364     (e.g. the shuttlepro reports its state approx. every second.)
00365     libmediactrl translates these events to none-events.
00366     
00367     
00368     ev.type == MEDIA_CTRL_EVENT_KEY (0x01)
00369     This is a button press. The whole event will be handled in the
00370     button method..
00371 
00372     ev.type == MEDIA_CTRL_EVENT_JOG (0x02)
00373     This event is issued when ever the dial position changes. 
00374     ev.value is the offset to the current jog position.
00375 
00376 
00377     - ev.code == EDIA_CTRL_EVENT_SHUTTLE (0x02) 
00378     the outer wheel ev.value indicates the position, with positive 
00379     values from 0x01 to 0x0f (inclusive) indicating clockwise twist, 
00380     and negative values from -1 to -15 indicating counterclockwise 
00381     twist.  A 0 value is reported. 
00382 
00383 
00384     */
00385 
00386     if ( ev.type == MEDIA_CTRL_EVENT_NONE ) return;
00387 #if 0
00388     printf( "JogShuttle: %02x %02x %02d\n", ev.type, ev.code, ev.value );
00389 #endif
00390 
00391 
00392     if ( ev.type == MEDIA_CTRL_EVENT_JOG ) 
00393     {
00394         this->jog( CLAMP( ev.value, -1, 1 ) );
00395     } 
00396     else if ( ev.type == MEDIA_CTRL_EVENT_SHUTTLE ) 
00397     {
00398         this->shuttle( ev.value );
00399     }
00400     else if ( ev.type == MEDIA_CTRL_EVENT_KEY ) 
00401     {
00402         this->button( &ev );
00403     }
00404     else
00405     {
00406         return;
00407     }
00408 }

void JogShuttle::jog int  offs  )  [private]
 

Handle movement on the jog dial.

Parameters:
dir A number from -x to x to specify the offset from the current frame. A negative number moves backward. Typically, x is 1 to step frame-by-frame.

Definition at line 229 of file jogshuttle.cc.

References videoBackBy(), and videoForwardBy().

Referenced by inputCallback().

00230 {
00231     gdk_threads_enter();
00232     if ( offs < 0 )
00233         videoBackBy(offs);
00234     else
00235         videoForwardBy(offs);
00236     gdk_threads_leave();
00237 }

void JogShuttle::registerCallback void *  user,
JogShuttleCallback  callback
 

Register callback.

Register an interest in getting notification when buttons are pressed

Parameters:
callback Function to call

Definition at line 192 of file jogshuttle.cc.

References _callback, and _callbackdata.

00193 {
00194     if ( _callback )
00195         g_warning( "JogShuttle::registerCallback - already registered\n" );
00196     _callback = callback;
00197     _callbackdata = user;
00198 }

void JogShuttle::shuttle int  angle  )  [private]
 

Handle movement of the shuttle ring.

Parameters:
angle A number from -8 to 8 that speccifies a direction and speed.

Definition at line 243 of file jogshuttle.cc.

References videoShuttle().

Referenced by inputCallback().

00244 {
00245     /*if ( angle > 0 )
00246         angle--;
00247     if ( angle < 0 )
00248         angle++;
00249     */
00250     gdk_threads_enter();
00251     videoShuttle( angle );
00252     gdk_threads_leave();
00253 }

bool JogShuttle::start  ) 
 

Start the GDK input handler if enabled.

Returns:
a boolean indicating if not started due to not enabled or device open failed.

Definition at line 154 of file jogshuttle.cc.

References _ctrl, media_ctrl::device, Preferences::enableJogShuttle, media_ctrl::fd, Preferences::getInstance(), JogShuttle_inputCallback, media_ctrl_open(), monitorTag_, and stop().

Referenced by JogShuttle().

00155 {
00156     Preferences & prefs = Preferences::getInstance();
00157     
00158     if ( prefs.enableJogShuttle )
00159     {
00160         stop();
00161         media_ctrl_open( &_ctrl );
00162         if ( _ctrl.device ) 
00163         {
00164             monitorTag_ = gdk_input_add( _ctrl.fd, GDK_INPUT_READ,
00165                              JogShuttle_inputCallback,
00166                              ( gpointer ) this );
00167             return true;
00168         }
00169     }
00170     return false;
00171 }

void JogShuttle::stop  ) 
 

Stop the GDK input handler.

Definition at line 175 of file jogshuttle.cc.

References _ctrl, media_ctrl::device, media_ctrl_close(), and monitorTag_.

Referenced by inputCallback(), and start().

00176 {
00177     if ( monitorTag_ != -1 )
00178     {
00179         gdk_input_remove( monitorTag_ );
00180         monitorTag_ = -1;
00181     }
00182     if ( _ctrl.device )
00183         media_ctrl_close( &_ctrl );
00184 }


Friends And Related Function Documentation

void JogShuttle_inputCallback gpointer  data,
gint  source,
GdkInputCondition  condition
[friend]
 

A C wrappper for the GDK input handler callback.

Definition at line 99 of file jogshuttle.cc.

Referenced by start().

00100 {
00101     JogShuttle * js = static_cast<JogShuttle *>( data );
00102     g_return_if_fail( js != NULL );
00103     js->inputCallback( source, condition );
00104 }


Member Data Documentation

JogShuttleCallback JogShuttle::_callback [private]
 

Placeholder for callbacks.

Definition at line 55 of file jogshuttle.h.

Referenced by button(), deregisterCallback(), and registerCallback().

void* JogShuttle::_callbackdata [private]
 

Any client supplied callbackdata is here.

Definition at line 57 of file jogshuttle.h.

Referenced by button(), and registerCallback().

struct media_ctrl JogShuttle::_ctrl [private]
 

Definition at line 80 of file jogshuttle.h.

Referenced by getKeyset(), inputCallback(), JogShuttle(), start(), stop(), and ~JogShuttle().

JogShuttle * JogShuttle::_instance = NULL [static, private]
 

Singleton pattern.

It is accesible to other classes via the getInstance method.

Definition at line 111 of file jogshuttle.cc.

Referenced by getInstance().

media_ctrl_key* JogShuttle::_modifier [private]
 

Definition at line 87 of file jogshuttle.h.

unsigned short JogShuttle::_modifier_code [private]
 

Definition at line 86 of file jogshuttle.h.

Referenced by button().

int JogShuttle::input_ [private]
 

Definition at line 81 of file jogshuttle.h.

Referenced by ~JogShuttle().

gint JogShuttle::monitorTag_ [private]
 

Definition at line 82 of file jogshuttle.h.

Referenced by start(), stop(), and ~JogShuttle().


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 22:13:07 2007 for Kino by  doxygen 1.4.2