void VarText::set( const UString &rText ) { // Avoid an infinite loop if( rText == m_text ) { return; } m_text = rText; if( m_substVars ) { // Stop observing other variables delObservers(); VlcProc *pVlcProc = VlcProc::instance( getIntf() ); VarManager *pVarManager = VarManager::instance( getIntf() ); // Observe needed variables if( m_text.find( "$H" ) != UString::npos ) { pVarManager->getHelpText().addObserver( this ); } if( m_text.find( "$T" ) != UString::npos || m_text.find( "$t" ) != UString::npos || m_text.find( "$L" ) != UString::npos || m_text.find( "$l" ) != UString::npos || m_text.find( "$D" ) != UString::npos || m_text.find( "$d" ) != UString::npos ) { pVlcProc->getTimeVar().addObserver( this ); } if( m_text.find( "$V" ) != UString::npos ) { pVlcProc->getVolumeVar().addObserver( this ); } if( m_text.find( "$N" ) != UString::npos ) { pVlcProc->getStreamNameVar().addObserver( this ); } if( m_text.find( "$F" ) != UString::npos ) { pVlcProc->getStreamURIVar().addObserver( this ); } if( m_text.find( "$B" ) != UString::npos ) { pVlcProc->getStreamBitRateVar().addObserver( this ); } if( m_text.find( "$S" ) != UString::npos ) { pVlcProc->getStreamSampleRateVar().addObserver( this ); } if( m_text.find( "$R" ) != UString::npos ) { pVlcProc->getSpeedVar().addObserver( this ); } } notify(); }
int VlcProc::onGenericCallback2( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { (void)oldVal; VlcProc *pThis = (VlcProc*)pParam; AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); /** * For intf-event, commands are labeled based on the value of newVal. * * For some values (e.g position), only keep the latest command * when there are multiple pending commands (remove=true). * * for others, don't discard commands (remove=false) **/ if( strcmp( pVariable, "intf-event" ) == 0 ) { stringstream label; bool b_remove; switch( newVal.i_int ) { case INPUT_EVENT_STATE: case INPUT_EVENT_POSITION: case INPUT_EVENT_ES: case INPUT_EVENT_CHAPTER: case INPUT_EVENT_RECORD: b_remove = true; break; case INPUT_EVENT_VOUT: case INPUT_EVENT_AOUT: case INPUT_EVENT_DEAD: b_remove = false; break; default: return VLC_SUCCESS; } label << pVariable << "_" << newVal.i_int; CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, &VlcProc::on_intf_event_changed, label.str() ); if( pCmd ) pQueue->push( CmdGenericPtr( pCmd ), b_remove ); return VLC_SUCCESS; } msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable ); return VLC_EGENERIC; }
int VlcProc::onEqPreampChange( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; EqualizerPreamp *pVarPreamp = (EqualizerPreamp*)(pThis->m_cVarEqPreamp.get()); // Post a set preamp command CmdSetEqPreamp *pCmd = new CmdSetEqPreamp( pThis->getIntf(), *pVarPreamp, (newVal.f_float + 20.0) / 40.0 ); AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmd ) ); return VLC_SUCCESS; }
int VlcProc::onEqBandsChange( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; // Post a set equalizer bands command CmdSetEqBands *pCmd = new CmdSetEqBands( pThis->getIntf(), pThis->m_varEqBands, newVal.psz_string ); AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmd ) ); return VLC_SUCCESS; }
int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; int i_id = newVal.i_int; CmdPlaytreeDelete *pCmdTree = new CmdPlaytreeDelete( pThis->getIntf(), i_id); // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmdTree ), false ); return VLC_SUCCESS; }
int VlcProc::onItemAppend( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; playlist_add_t *p_add = static_cast<playlist_add_t*>(newVal.p_address); CmdPlaytreeAppend *pCmdTree = new CmdPlaytreeAppend( pThis->getIntf(), p_add ); // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmdTree ), false ); return VLC_SUCCESS; }
int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldval, vlc_value_t newval, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; input_item_t *p_item = static_cast<input_item_t*>(newval.p_address); // Create a playtree notify command CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), p_item ); // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); pQueue->push( CmdGenericPtr( pCmdTree ), true ); return VLC_SUCCESS; }
int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { (void)oldVal; VlcProc *pThis = (VlcProc*)pParam; AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); #define ADD_CALLBACK_ENTRY( var, func, remove ) \ { \ if( strcmp( pVariable, var ) == 0 ) \ { \ string label = var; \ CmdGeneric *pCmd = new CmdCallback( pThis->getIntf(), pObj, newVal, \ &VlcProc::func, label ); \ if( pCmd ) \ pQueue->push( CmdGenericPtr( pCmd ), remove ); \ return VLC_SUCCESS; \ } \ } ADD_CALLBACK_ENTRY( "item-current", on_item_current_changed, false ) ADD_CALLBACK_ENTRY( "volume", on_volume_changed, true ) ADD_CALLBACK_ENTRY( "bit-rate", on_bit_rate_changed, false ) ADD_CALLBACK_ENTRY( "sample-rate", on_sample_rate_changed, false ) ADD_CALLBACK_ENTRY( "can-record", on_can_record_changed, false ) ADD_CALLBACK_ENTRY( "random", on_random_changed, false ) ADD_CALLBACK_ENTRY( "loop", on_loop_changed, false ) ADD_CALLBACK_ENTRY( "repeat", on_repeat_changed, false ) ADD_CALLBACK_ENTRY( "audio-filter", on_audio_filter_changed, false ) ADD_CALLBACK_ENTRY( "intf-toggle-fscontrol", on_intf_show_changed, false ) ADD_CALLBACK_ENTRY( "mouse-moved", on_mouse_moved_changed, false ) #undef ADD_CALLBACK_ENTRY msg_Err( pThis->getIntf(), "no callback entry for %s", pVariable ); return VLC_EGENERIC; }
int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable, vlc_value_t oldVal, vlc_value_t newVal, void *pParam ) { VlcProc *pThis = (VlcProc*)pParam; AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); CmdGeneric *pCmd = NULL; #define ADD_CALLBACK_ENTRY( var, label ) \ { \ if( strcmp( pVariable, var ) == 0 ) \ pCmd = new Cmd_##label( pThis->getIntf(), pObj, newVal ); \ } ADD_CALLBACK_ENTRY( "item-current", item_current_changed ) ADD_CALLBACK_ENTRY( "volume-change", volume_changed ) ADD_CALLBACK_ENTRY( "intf-event", intf_event_changed ) ADD_CALLBACK_ENTRY( "bit-rate", bit_rate_changed ) ADD_CALLBACK_ENTRY( "sample-rate", sample_rate_changed ) ADD_CALLBACK_ENTRY( "can-record", can_record_changed ) ADD_CALLBACK_ENTRY( "random", random_changed ) ADD_CALLBACK_ENTRY( "loop", loop_changed ) ADD_CALLBACK_ENTRY( "repeat", repeat_changed ) ADD_CALLBACK_ENTRY( "audio-filter", audio_filter_changed ) ADD_CALLBACK_ENTRY( "intf-show", intf_show_changed ) #undef ADD_CALLBACK_ENTRY if( pCmd ) pQueue->push( CmdGenericPtr( pCmd ), false ); else msg_Err( pObj, "no Callback entry provided for %s", pVariable ); return VLC_SUCCESS; }
void VarText::delObservers() { // Stop observing other variables VlcProc *pVlcProc = getIntf()->p_sys->p_vlcProc; VarManager *pVarManager = getIntf()->p_sys->p_varManager; if( pVlcProc ) { pVlcProc->getTimeVar().delObserver( this ); pVlcProc->getVolumeVar().delObserver( this ); pVlcProc->getSpeedVar().delObserver( this ); pVlcProc->getStreamNameVar().delObserver( this ); pVlcProc->getStreamURIVar().delObserver( this ); pVlcProc->getStreamBitRateVar().delObserver( this ); pVlcProc->getStreamSampleRateVar().delObserver( this ); } if( pVarManager ) pVarManager->getHelpText().delObserver( this ); }
const UString VarText::get() const { if( !m_substVars ) { // Do not substitute "$X" variables return m_text; } uint32_t pos; VlcProc *pVlcProc = VlcProc::instance( getIntf() ); // Fill a temporary UString object, and replace the escape characters // ($H for help, $T for current time, $L for time left, $D for duration, // $V for volume) UString temp( m_text ); // $H is processed first, in case the help string contains other variables // to replace. And it is replaced only once, in case one of these other // variables is $H... if( (pos = temp.find( "$H" )) != UString::npos ) { VarManager *pVarManager = VarManager::instance( getIntf() ); temp.replace( pos, 2, pVarManager->getHelpText().get() ); } while( (pos = temp.find( "$T" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringCurrTime().c_str() ); } while( (pos = temp.find( "$t" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringCurrTime(true).c_str() ); } while( (pos = temp.find( "$L" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringTimeLeft().c_str() ); } while( (pos = temp.find( "$l" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringTimeLeft(true).c_str() ); } while( (pos = temp.find( "$D" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringDuration().c_str() ); } while( (pos = temp.find( "$d" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getTimeVar().getAsStringDuration(true).c_str() ); } while( (pos = temp.find( "$V" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getVolumeVar().getAsStringPercent().c_str() ); } while( (pos = temp.find( "$N" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamNameVar().get() ); } while( (pos = temp.find( "$F" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamURIVar().get() ); } while( (pos = temp.find( "$B" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamBitRateVar().get() ); } while( (pos = temp.find( "$S" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getStreamSampleRateVar().get() ); } while( (pos = temp.find( "$R" )) != UString::npos ) { temp.replace( pos, 2, pVlcProc->getSpeedVar().get() ); } return temp; }