extended_panels.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  1. /*****************************************************************************
  2. * extended_panels.cpp : Extended controls panels
  3. ****************************************************************************
  4. * Copyright (C) 2006-2013 the VideoLAN team
  5. * $Id$
  6. *
  7. * Authors: Clément Stenac <zorglub@videolan.org>
  8. * Antoine Cellerier <dionoea .t videolan d@t org>
  9. * Jean-Baptiste Kempf <jb@videolan.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * ( at your option ) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  24. *****************************************************************************/
  25. #ifdef HAVE_CONFIG_H
  26. # include "config.h"
  27. #endif
  28. #include <math.h>
  29. #include <QLabel>
  30. #include <QVariant>
  31. #include <QString>
  32. #include <QFont>
  33. #include <QGridLayout>
  34. #include <QComboBox>
  35. #include <QTimer>
  36. #include <QFileDialog>
  37. #include <QGraphicsScene>
  38. #include <QPainter>
  39. #include "components/extended_panels.hpp"
  40. #include "dialogs/preferences.hpp"
  41. #include "qt.hpp"
  42. #include "input_manager.hpp"
  43. #include "util/qt_dirs.hpp"
  44. #include "util/customwidgets.hpp"
  45. #include "../../audio_filter/equalizer_presets.h"
  46. #include <vlc_vout.h>
  47. #include <vlc_modules.h>
  48. #include <vlc_plugin.h>
  49. static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add );
  50. static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
  51. static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
  52. const QString ModuleFromWidgetName( QObject *obj )
  53. {
  54. return obj->objectName().replace( "Enable","" );
  55. }
  56. QString OptionFromWidgetName( QObject *obj )
  57. {
  58. /* Gruik ? ... nah */
  59. QString option = obj->objectName().replace( "Slider", "" )
  60. .replace( "Combo" , "" )
  61. .replace( "Dial" , "" )
  62. .replace( "Check" , "" )
  63. .replace( "Spin" , "" )
  64. .replace( "Text" , "" );
  65. for( char a = 'A'; a <= 'Z'; a++ )
  66. {
  67. option = option.replace( QString( a ),
  68. QString( '-' ) + QString( a + 'a' - 'A' ) );
  69. }
  70. return option;
  71. }
  72. static inline void setup_vfilter( intf_thread_t *p_intf, const char* psz_name, QWidget *widget )
  73. {
  74. vlc_object_t *p_obj = ( vlc_object_t * )
  75. vlc_object_find_name( p_intf->obj.libvlc, psz_name );
  76. QCheckBox *checkbox = qobject_cast<QCheckBox*>( widget );
  77. QGroupBox *groupbox = qobject_cast<QGroupBox*>( widget );
  78. if( p_obj )
  79. {
  80. vlc_object_release( p_obj ); \
  81. if( checkbox ) checkbox->setChecked( true ); \
  82. else if (groupbox) groupbox->setChecked( true ); \
  83. }
  84. else
  85. {
  86. if( checkbox ) checkbox->setChecked( false );
  87. else if (groupbox) groupbox->setChecked( false );
  88. }
  89. }
  90. #define SETUP_VFILTER( widget ) \
  91. setup_vfilter( p_intf, #widget, ui.widget##Enable ); \
  92. CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
  93. #define SETUP_VFILTER_OPTION( widget, signal ) \
  94. initComboBoxItems( ui.widget ); \
  95. setWidgetValue( ui.widget ); \
  96. CONNECT( ui.widget, signal, this, updateFilterOptions() );
  97. ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
  98. QObject( _parent ), p_intf( _p_intf )
  99. {
  100. ui.setupUi( _parent );
  101. SETUP_VFILTER( adjust )
  102. SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
  103. SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
  104. SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
  105. SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
  106. SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
  107. SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
  108. SETUP_VFILTER( extract )
  109. SETUP_VFILTER_OPTION( extractComponentText, textChanged( const QString& ) )
  110. SETUP_VFILTER( posterize )
  111. SETUP_VFILTER( colorthres )
  112. SETUP_VFILTER_OPTION( colorthresColorText, textChanged( const QString& ) )
  113. SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
  114. SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
  115. SETUP_VFILTER( sepia )
  116. SETUP_VFILTER_OPTION( sepiaIntensitySpin, valueChanged( int ) )
  117. SETUP_VFILTER( invert )
  118. SETUP_VFILTER( gradient )
  119. SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
  120. SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
  121. SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
  122. SETUP_VFILTER( motionblur )
  123. SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
  124. SETUP_VFILTER( motiondetect )
  125. SETUP_VFILTER( psychedelic )
  126. SETUP_VFILTER( sharpen )
  127. SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
  128. SETUP_VFILTER( ripple )
  129. SETUP_VFILTER( wave )
  130. SETUP_VFILTER( transform )
  131. SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
  132. SETUP_VFILTER( rotate )
  133. SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
  134. ui.rotateAngleDial->setWrapping( true );
  135. ui.rotateAngleDial->setNotchesVisible( true );
  136. SETUP_VFILTER( puzzle )
  137. SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
  138. SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
  139. SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
  140. SETUP_VFILTER( magnify )
  141. SETUP_VFILTER( clone )
  142. SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
  143. SETUP_VFILTER( wall )
  144. SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
  145. SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
  146. SETUP_VFILTER( erase )
  147. SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
  148. SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
  149. SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
  150. BUTTONACT( ui.eraseBrowseBtn, browseEraseFile() );
  151. SETUP_VFILTER( marq )
  152. SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( const QString& ) )
  153. SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
  154. SETUP_VFILTER( logo )
  155. SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
  156. SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
  157. SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
  158. SETUP_VFILTER_OPTION( logoOpacitySlider, valueChanged( int ) )
  159. BUTTONACT( ui.logoBrowseBtn, browseLogo() );
  160. SETUP_VFILTER( gradfun )
  161. SETUP_VFILTER_OPTION( gradfunRadiusSlider, valueChanged( int ) )
  162. SETUP_VFILTER( grain )
  163. SETUP_VFILTER_OPTION( grainVarianceSlider, valueChanged( int ) )
  164. SETUP_VFILTER( mirror )
  165. SETUP_VFILTER( gaussianblur )
  166. SETUP_VFILTER_OPTION( gaussianblurSigmaSlider, valueChanged( int ) )
  167. SETUP_VFILTER( antiflicker )
  168. SETUP_VFILTER_OPTION( antiflickerSofteningSizeSlider, valueChanged( int ) )
  169. SETUP_VFILTER( hqdn3d )
  170. SETUP_VFILTER_OPTION( hqdn3dLumaSpatSlider, valueChanged( int ) )
  171. SETUP_VFILTER_OPTION( hqdn3dLumaTempSlider, valueChanged( int ) )
  172. SETUP_VFILTER_OPTION( hqdn3dChromaSpatSlider, valueChanged( int ) )
  173. SETUP_VFILTER_OPTION( hqdn3dChromaTempSlider, valueChanged( int ) )
  174. SETUP_VFILTER( anaglyph )
  175. #undef SETUP_VFILTER
  176. #undef SETUP_VFILTER_OPTION
  177. CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
  178. CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
  179. CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
  180. CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
  181. CONNECT( ui.leftRightCropSync, toggled ( bool ), this, cropChange() );
  182. CONNECT( ui.topBotCropSync, toggled ( bool ), this, cropChange() );
  183. CONNECT( ui.topBotCropSync, toggled( bool ),
  184. ui.cropBotPx, setDisabled( bool ) );
  185. CONNECT( ui.leftRightCropSync, toggled( bool ),
  186. ui.cropRightPx, setDisabled( bool ) );
  187. }
  188. void ExtVideo::cropChange()
  189. {
  190. if( ui.topBotCropSync->isChecked() )
  191. ui.cropBotPx->setValue( ui.cropTopPx->value() );
  192. if( ui.leftRightCropSync->isChecked() )
  193. ui.cropRightPx->setValue( ui.cropLeftPx->value() );
  194. vout_thread_t *p_vout = THEMIM->getVout();
  195. if( p_vout )
  196. {
  197. var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
  198. var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
  199. var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
  200. var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
  201. vlc_object_release( p_vout );
  202. }
  203. }
  204. void ExtVideo::clean()
  205. {
  206. ui.cropTopPx->setValue( 0 );
  207. ui.cropBotPx->setValue( 0 );
  208. ui.cropLeftPx->setValue( 0 );
  209. ui.cropRightPx->setValue( 0 );
  210. }
  211. static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add )
  212. {
  213. char *psz_parser, *psz_string;
  214. psz_string = config_GetPsz( p_intf, psz_filter_type );
  215. if( !psz_string ) psz_string = strdup( "" );
  216. psz_parser = strstr( psz_string, psz_name );
  217. if( b_add )
  218. {
  219. if( !psz_parser )
  220. {
  221. psz_parser = psz_string;
  222. if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
  223. psz_string, psz_name ) == -1 )
  224. {
  225. free( psz_parser );
  226. return NULL;
  227. }
  228. free( psz_parser );
  229. }
  230. else
  231. {
  232. free( psz_string );
  233. return NULL;
  234. }
  235. }
  236. else
  237. {
  238. if( psz_parser )
  239. {
  240. if( *( psz_parser + strlen( psz_name ) ) == ':' )
  241. {
  242. memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
  243. strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
  244. }
  245. else
  246. {
  247. *psz_parser = '\0';
  248. }
  249. /* Remove trailing : : */
  250. size_t i_len = strlen( psz_string );
  251. if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
  252. {
  253. *( psz_string + i_len - 1 ) = '\0';
  254. }
  255. }
  256. else
  257. {
  258. free( psz_string );
  259. return NULL;
  260. }
  261. }
  262. return psz_string;
  263. }
  264. static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
  265. {
  266. char *psz_string;
  267. module_t *p_obj = module_find( psz_name );
  268. if( !p_obj )
  269. {
  270. msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
  271. return;
  272. }
  273. psz_string = ChangeFiltersString( p_intf, "audio-filter", psz_name, b_add );
  274. if( !psz_string )
  275. return;
  276. config_PutPsz( p_intf, "audio-filter", psz_string );
  277. free( psz_string );
  278. }
  279. static const char* GetVFilterType( struct intf_thread_t *p_intf, const char *psz_name )
  280. {
  281. module_t *p_obj = module_find( psz_name );
  282. if( !p_obj )
  283. {
  284. msg_Err( p_intf, "Unable to find filter module \"%s\".", psz_name );
  285. return NULL;
  286. }
  287. if( module_provides( p_obj, "video splitter" ) )
  288. return "video-splitter";
  289. else if( module_provides( p_obj, "video filter" ) )
  290. return "video-filter";
  291. else if( module_provides( p_obj, "sub source" ) )
  292. return "sub-source";
  293. else if( module_provides( p_obj, "sub filter" ) )
  294. return "sub-filter";
  295. else
  296. {
  297. msg_Err( p_intf, "Unknown video filter type." );
  298. return NULL;
  299. }
  300. }
  301. static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
  302. {
  303. char *psz_string;
  304. const char *psz_filter_type = GetVFilterType( p_intf, psz_name );
  305. psz_string = ChangeFiltersString( p_intf, psz_filter_type, psz_name, b_add );
  306. if( !psz_string )
  307. return;
  308. /* Vout is not kept, so put that in the config */
  309. config_PutPsz( p_intf, psz_filter_type, psz_string );
  310. /* Try to set on the fly */
  311. if( !strcmp( psz_filter_type, "video-splitter" ) )
  312. {
  313. playlist_t *p_playlist = THEPL;
  314. var_SetString( p_playlist, psz_filter_type, psz_string );
  315. }
  316. else
  317. {
  318. vout_thread_t *p_vout = THEMIM->getVout();
  319. if( p_vout )
  320. {
  321. var_SetString( p_vout, psz_filter_type, psz_string );
  322. vlc_object_release( p_vout );
  323. }
  324. }
  325. free( psz_string );
  326. }
  327. void ExtVideo::updateFilters()
  328. {
  329. QString module = ModuleFromWidgetName( sender() );
  330. QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
  331. QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
  332. ChangeVFiltersString( p_intf, qtu( module ),
  333. checkbox ? checkbox->isChecked()
  334. : groupbox->isChecked() );
  335. }
  336. #define UPDATE_AND_APPLY_TEXT( widget, file ) \
  337. CONNECT( ui.widget, textChanged( const QString& ), \
  338. this, updateFilterOptions() ); \
  339. ui.widget->setText( toNativeSeparators( file ) ); \
  340. ui.widget->disconnect( SIGNAL( textChanged( const QString& ) ) );
  341. void ExtVideo::browseLogo()
  342. {
  343. QString file = QFileDialog::getOpenFileName( NULL, qtr( "Logo filenames" ),
  344. p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
  345. UPDATE_AND_APPLY_TEXT( logoFileText, file );
  346. }
  347. void ExtVideo::browseEraseFile()
  348. {
  349. QString file = QFileDialog::getOpenFileName( NULL, qtr( "Image mask" ),
  350. p_intf->p_sys->filepath, "Images (*.png *.jpg);;All (*)" );
  351. UPDATE_AND_APPLY_TEXT( eraseMaskText, file );
  352. }
  353. #undef UPDATE_AND_APPLY_TEXT
  354. void ExtVideo::initComboBoxItems( QObject *widget )
  355. {
  356. QComboBox *combobox = qobject_cast<QComboBox*>( widget );
  357. if( !combobox ) return;
  358. QString option = OptionFromWidgetName( widget );
  359. module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
  360. qtu( option ) );
  361. if( p_item == NULL )
  362. {
  363. msg_Err( p_intf, "Couldn't find option \"%s\".", qtu( option ) );
  364. return;
  365. }
  366. if( p_item->i_type == CONFIG_ITEM_INTEGER
  367. || p_item->i_type == CONFIG_ITEM_BOOL )
  368. {
  369. int64_t *values;
  370. char **texts;
  371. ssize_t count = config_GetIntChoices( VLC_OBJECT( p_intf ),
  372. qtu( option ), &values, &texts );
  373. for( ssize_t i = 0; i < count; i++ )
  374. {
  375. combobox->addItem( qtr( texts[i] ), qlonglong(values[i]) );
  376. free( texts[i] );
  377. }
  378. free( texts );
  379. free( values );
  380. }
  381. else if( p_item->i_type == CONFIG_ITEM_STRING )
  382. {
  383. char **values;
  384. char **texts;
  385. ssize_t count = config_GetPszChoices( VLC_OBJECT( p_intf ),
  386. qtu( option ), &values, &texts );
  387. for( ssize_t i = 0; i < count; i++ )
  388. {
  389. combobox->addItem( qtr( texts[i] ), qfu(values[i]) );
  390. free( texts[i] );
  391. free( values[i] );
  392. }
  393. free( texts );
  394. free( values );
  395. }
  396. }
  397. void ExtVideo::setWidgetValue( QObject *widget )
  398. {
  399. QString module = ModuleFromWidgetName( widget->parent() );
  400. //std::cout << "Module name: " << module.toStdString() << std::endl;
  401. QString option = OptionFromWidgetName( widget );
  402. //std::cout << "Option name: " << option.toStdString() << std::endl;
  403. vlc_object_t *p_obj = ( vlc_object_t * )
  404. vlc_object_find_name( p_intf->obj.libvlc, qtu( module ) );
  405. int i_type;
  406. vlc_value_t val;
  407. if( !p_obj )
  408. {
  409. #if 0
  410. msg_Dbg( p_intf,
  411. "Module instance %s not found, looking in config values.",
  412. qtu( module ) );
  413. #endif
  414. i_type = config_GetType( p_intf, qtu( option ) ) & VLC_VAR_CLASS;
  415. switch( i_type )
  416. {
  417. case VLC_VAR_INTEGER:
  418. case VLC_VAR_BOOL:
  419. val.i_int = config_GetInt( p_intf, qtu( option ) );
  420. break;
  421. case VLC_VAR_FLOAT:
  422. val.f_float = config_GetFloat( p_intf, qtu( option ) );
  423. break;
  424. case VLC_VAR_STRING:
  425. val.psz_string = config_GetPsz( p_intf, qtu( option ) );
  426. break;
  427. }
  428. }
  429. else
  430. {
  431. i_type = var_Type( p_obj, qtu( option ) ) & VLC_VAR_CLASS;
  432. var_Get( p_obj, qtu( option ), &val );
  433. vlc_object_release( p_obj );
  434. }
  435. /* Try to cast to all the widgets we're likely to encounter. Only
  436. * one of the casts is expected to work. */
  437. QSlider *slider = qobject_cast<QSlider*> ( widget );
  438. QCheckBox *checkbox = qobject_cast<QCheckBox*> ( widget );
  439. QSpinBox *spinbox = qobject_cast<QSpinBox*> ( widget );
  440. QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
  441. VLCQDial *dial = qobject_cast<VLCQDial*> ( widget );
  442. QLineEdit *lineedit = qobject_cast<QLineEdit*> ( widget );
  443. QComboBox *combobox = qobject_cast<QComboBox*> ( widget );
  444. if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
  445. {
  446. if( slider ) slider->setValue( val.i_int );
  447. else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
  448. : Qt::Unchecked );
  449. else if( spinbox ) spinbox->setValue( val.i_int );
  450. else if( dial ) dial->setValue( (360 - val.i_int) % 360 );
  451. else if( lineedit )
  452. {
  453. char str[30];
  454. snprintf( str, sizeof(str), "%06" PRIX64, val.i_int );
  455. lineedit->setText( str );
  456. }
  457. else if( combobox ) combobox->setCurrentIndex(
  458. combobox->findData( qlonglong(val.i_int) ) );
  459. else msg_Warn( p_intf, "Could not find the correct Integer widget" );
  460. }
  461. else if( i_type == VLC_VAR_FLOAT )
  462. {
  463. if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
  464. else if( doublespinbox ) doublespinbox->setValue( val.f_float );
  465. else if( dial ) dial->setValue( (360 - lroundf(val.f_float)) % 360 );
  466. else msg_Warn( p_intf, "Could not find the correct Float widget" );
  467. }
  468. else if( i_type == VLC_VAR_STRING )
  469. {
  470. if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
  471. else if( combobox ) combobox->setCurrentIndex(
  472. combobox->findData( qfu( val.psz_string ) ) );
  473. else msg_Warn( p_intf, "Could not find the correct String widget" );
  474. free( val.psz_string );
  475. }
  476. else
  477. if( p_obj )
  478. msg_Err( p_intf,
  479. "Module %s's %s variable is of an unsupported type ( %d )",
  480. qtu( module ),
  481. qtu( option ),
  482. i_type );
  483. }
  484. void ExtVideo::setFilterOption( struct intf_thread_t *p_intf, const char *psz_module, const char *psz_option,
  485. int i_int, double f_float, QString val )
  486. {
  487. vlc_object_t *p_obj = ( vlc_object_t * )vlc_object_find_name( p_intf->obj.libvlc, psz_module );
  488. int i_type;
  489. bool b_is_command;
  490. if( !p_obj )
  491. {
  492. msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", psz_module );
  493. i_type = config_GetType( p_intf, psz_option );
  494. b_is_command = false;
  495. }
  496. else
  497. {
  498. i_type = var_Type( p_obj, psz_option );
  499. if( i_type == 0 )
  500. i_type = config_GetType( p_intf, psz_option );
  501. b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
  502. }
  503. i_type &= VLC_VAR_CLASS;
  504. if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
  505. {
  506. if( i_int == -1 )
  507. msg_Warn( p_intf, "Could not find the correct Integer widget" );
  508. config_PutInt( p_intf, psz_option, i_int );
  509. if( b_is_command )
  510. {
  511. if( i_type == VLC_VAR_INTEGER )
  512. var_SetInteger( p_obj, psz_option, i_int );
  513. else
  514. var_SetBool( p_obj, psz_option, i_int );
  515. }
  516. }
  517. else if( i_type == VLC_VAR_FLOAT )
  518. {
  519. if( f_float == -1 )
  520. msg_Warn( p_intf, "Could not find the correct Float widget" );
  521. config_PutFloat( p_intf, psz_option, f_float );
  522. if( b_is_command )
  523. var_SetFloat( p_obj, psz_option, f_float );
  524. }
  525. else if( i_type == VLC_VAR_STRING )
  526. {
  527. if( val.isNull() )
  528. msg_Warn( p_intf, "Could not find the correct String widget" );
  529. config_PutPsz( p_intf, psz_option, qtu( val ) );
  530. if( b_is_command )
  531. var_SetString( p_obj, psz_option, qtu( val ) );
  532. }
  533. else
  534. msg_Err( p_intf,
  535. "Module %s's %s variable is of an unsupported type ( %d )",
  536. psz_module,
  537. psz_option,
  538. i_type );
  539. if( !b_is_command )
  540. {
  541. msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
  542. psz_module,
  543. psz_option );
  544. ChangeVFiltersString( p_intf, psz_module, false );
  545. ChangeVFiltersString( p_intf, psz_module, true );
  546. }
  547. if( p_obj ) vlc_object_release( p_obj );
  548. }
  549. void ExtVideo::updateFilterOptions()
  550. {
  551. QString module = ModuleFromWidgetName( sender()->parent() );
  552. //msg_Dbg( p_intf, "Module name: %s", qtu( module ) );
  553. QString option = OptionFromWidgetName( sender() );
  554. //msg_Dbg( p_intf, "Option name: %s", qtu( option ) );
  555. /* Try to cast to all the widgets we're likely to encounter. Only
  556. * one of the casts is expected to work. */
  557. QSlider *slider = qobject_cast<QSlider*> ( sender() );
  558. QCheckBox *checkbox = qobject_cast<QCheckBox*> ( sender() );
  559. QSpinBox *spinbox = qobject_cast<QSpinBox*> ( sender() );
  560. QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
  561. VLCQDial *dial = qobject_cast<VLCQDial*> ( sender() );
  562. QLineEdit *lineedit = qobject_cast<QLineEdit*> ( sender() );
  563. QComboBox *combobox = qobject_cast<QComboBox*> ( sender() );
  564. int i_int = -1;
  565. double f_float = -1.;
  566. QString val;
  567. if( slider ) {
  568. i_int = slider->value();
  569. f_float = ( double )slider->value() / ( double )slider->tickInterval(); /* hack alert! */
  570. }
  571. else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
  572. else if( spinbox ) i_int = spinbox->value();
  573. else if( doublespinbox ) f_float = doublespinbox->value();
  574. else if( dial ) {
  575. i_int = (360 - dial->value()) % 360;
  576. f_float = i_int;
  577. }
  578. else if( lineedit ) {
  579. i_int = lineedit->text().toInt( NULL,16 );
  580. f_float = lineedit->text().toDouble();
  581. val = lineedit->text();
  582. }
  583. else if( combobox ) {
  584. i_int = combobox->itemData( combobox->currentIndex() ).toInt();
  585. val = combobox->itemData( combobox->currentIndex() ).toString();
  586. }
  587. setFilterOption( p_intf, qtu( module ), qtu( option ), i_int, f_float, val);
  588. }
  589. int ExtVideo::getPostprocessing( struct intf_thread_t *p_intf)
  590. {
  591. char *psz_config = config_GetPsz(p_intf, "video-filter");
  592. int i_q = -1;
  593. if (psz_config) {
  594. if (strstr(psz_config, "postproc"))
  595. i_q = config_GetInt(p_intf, "postproc-q");
  596. free(psz_config);
  597. }
  598. return i_q;
  599. }
  600. void ExtVideo::setPostprocessing( struct intf_thread_t *p_intf, int q)
  601. {
  602. const char *psz_name = "postproc";
  603. if( q == -1 )
  604. {
  605. ChangeVFiltersString( p_intf, psz_name, false );
  606. }
  607. else
  608. {
  609. ChangeVFiltersString( p_intf, psz_name, false );
  610. setFilterOption( p_intf, "postproc", "postproc-q", q, -1, QString() );
  611. }
  612. }
  613. /**********************************************************************
  614. * v4l2 controls
  615. **********************************************************************/
  616. ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
  617. : QWidget( _parent ), p_intf( _p_intf ), box( NULL )
  618. {
  619. QVBoxLayout *layout = new QVBoxLayout( this );
  620. help = new QLabel( qtr("No v4l2 instance found.\n"
  621. "Please check that the device has been opened with VLC and is playing.\n\n"
  622. "Controls will automatically appear here.")
  623. , this );
  624. help->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
  625. help->setWordWrap( true );
  626. layout->addWidget( help );
  627. setLayout( layout );
  628. }
  629. void ExtV4l2::showEvent( QShowEvent *event )
  630. {
  631. QWidget::showEvent( event );
  632. Refresh();
  633. }
  634. void ExtV4l2::Refresh( void )
  635. {
  636. vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( THEPL, "v4l2" );
  637. help->hide();
  638. if( box )
  639. {
  640. layout()->removeWidget( box );
  641. delete box;
  642. box = NULL;
  643. }
  644. if( p_obj )
  645. {
  646. vlc_value_t val, text;
  647. int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
  648. &val, &text );
  649. if( i_ret < 0 )
  650. {
  651. msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
  652. help->show();
  653. vlc_object_release( p_obj );
  654. return;
  655. }
  656. box = new QGroupBox( this );
  657. layout()->addWidget( box );
  658. QVBoxLayout *layout = new QVBoxLayout( box );
  659. box->setLayout( layout );
  660. for( int i = 0; i < val.p_list->i_count; i++ )
  661. {
  662. vlc_value_t vartext;
  663. const char *psz_var = text.p_list->p_values[i].psz_string;
  664. if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext, NULL ) )
  665. continue;
  666. QString name = qtr( vartext.psz_string );
  667. free( vartext.psz_string );
  668. msg_Dbg( p_intf, "v4l2 control \"%" PRIx64 "\": %s (%s)",
  669. val.p_list->p_values[i].i_int, psz_var, qtu( name ) );
  670. int i_type = var_Type( p_obj, psz_var );
  671. switch( i_type & VLC_VAR_TYPE )
  672. {
  673. case VLC_VAR_INTEGER:
  674. {
  675. QLabel *label = new QLabel( name, box );
  676. QHBoxLayout *hlayout = new QHBoxLayout();
  677. hlayout->addWidget( label );
  678. int i_val = var_GetInteger( p_obj, psz_var );
  679. if( i_type & VLC_VAR_HASCHOICE )
  680. {
  681. QComboBox *combobox = new QComboBox( box );
  682. combobox->setObjectName( qfu( psz_var ) );
  683. vlc_value_t val2, text2;
  684. var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
  685. &val2, &text2 );
  686. for( int j = 0; j < val2.p_list->i_count; j++ )
  687. {
  688. combobox->addItem(
  689. text2.p_list->p_values[j].psz_string,
  690. qlonglong( val2.p_list->p_values[j].i_int) );
  691. if( i_val == val2.p_list->p_values[j].i_int )
  692. combobox->setCurrentIndex( j );
  693. }
  694. var_FreeList( &val2, &text2 );
  695. CONNECT( combobox, currentIndexChanged( int ), this,
  696. ValueChange( int ) );
  697. hlayout->addWidget( combobox );
  698. }
  699. else
  700. {
  701. QSlider *slider = new QSlider( box );
  702. slider->setObjectName( qfu( psz_var ) );
  703. slider->setOrientation( Qt::Horizontal );
  704. vlc_value_t val2;
  705. var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
  706. &val2, NULL );
  707. if( val2.i_int < INT_MIN )
  708. val2.i_int = INT_MIN; /* FIXME */
  709. slider->setMinimum( val2.i_int );
  710. var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
  711. &val2, NULL );
  712. if( val2.i_int > INT_MAX )
  713. val2.i_int = INT_MAX; /* FIXME */
  714. slider->setMaximum( val2.i_int );
  715. if( !var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
  716. &val2, NULL ) )
  717. slider->setSingleStep( val2.i_int );
  718. slider->setValue( i_val );
  719. CONNECT( slider, valueChanged( int ), this,
  720. ValueChange( int ) );
  721. hlayout->addWidget( slider );
  722. }
  723. layout->addLayout( hlayout );
  724. break;
  725. }
  726. case VLC_VAR_BOOL:
  727. {
  728. QCheckBox *button = new QCheckBox( name, box );
  729. button->setObjectName( qfu( psz_var ) );
  730. button->setChecked( var_GetBool( p_obj, psz_var ) );
  731. CONNECT( button, clicked( bool ), this,
  732. ValueChange( bool ) );
  733. layout->addWidget( button );
  734. break;
  735. }
  736. case VLC_VAR_VOID:
  737. {
  738. if( i_type & VLC_VAR_ISCOMMAND )
  739. {
  740. QPushButton *button = new QPushButton( name, box );
  741. button->setObjectName( qfu( psz_var ) );
  742. CONNECT( button, clicked( bool ), this,
  743. ValueChange( bool ) );
  744. layout->addWidget( button );
  745. }
  746. else
  747. {
  748. QLabel *label = new QLabel( name, box );
  749. layout->addWidget( label );
  750. }
  751. break;
  752. }
  753. default:
  754. msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
  755. break;
  756. }
  757. }
  758. var_FreeList( &val, &text );
  759. vlc_object_release( p_obj );
  760. }
  761. else
  762. {
  763. msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
  764. help->show();
  765. if ( isVisible() )
  766. QTimer::singleShot( 2000, this, SLOT(Refresh()) );
  767. }
  768. }
  769. void ExtV4l2::ValueChange( bool value )
  770. {
  771. ValueChange( (int)value );
  772. }
  773. void ExtV4l2::ValueChange( int value )
  774. {
  775. QObject *s = sender();
  776. vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( THEPL, "v4l2" );
  777. if( p_obj )
  778. {
  779. QString var = s->objectName();
  780. int i_type = var_Type( p_obj, qtu( var ) );
  781. switch( i_type & VLC_VAR_TYPE )
  782. {
  783. case VLC_VAR_INTEGER:
  784. if( i_type & VLC_VAR_HASCHOICE )
  785. {
  786. QComboBox *combobox = qobject_cast<QComboBox*>( s );
  787. value = combobox->itemData( value ).toInt();
  788. }
  789. var_SetInteger( p_obj, qtu( var ), value );
  790. break;
  791. case VLC_VAR_BOOL:
  792. var_SetBool( p_obj, qtu( var ), value );
  793. break;
  794. case VLC_VAR_VOID:
  795. var_TriggerCallback( p_obj, qtu( var ) );
  796. break;
  797. }
  798. vlc_object_release( p_obj );
  799. }
  800. else
  801. {
  802. msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
  803. Refresh();
  804. }
  805. }
  806. /**********************************************************************
  807. * Sliders
  808. **********************************************************************/
  809. FilterSliderData::FilterSliderData( QObject *parent, QSlider *_slider ) :
  810. QObject( parent ), slider( _slider )
  811. {
  812. b_save_to_config = false;
  813. }
  814. FilterSliderData::FilterSliderData( QObject *parent,
  815. intf_thread_t *_p_intf,
  816. QSlider *_slider,
  817. QLabel *_label, QLabel *_nameLabel,
  818. const slider_data_t *_p_data ):
  819. QObject( parent ), slider( _slider ), valueLabel( _label ),
  820. nameLabel( _nameLabel ), p_data( _p_data ), p_intf( _p_intf )
  821. {
  822. b_save_to_config = false;
  823. slider->setMinimum( p_data->f_min / p_data->f_resolution );
  824. slider->setMaximum( p_data->f_max / p_data->f_resolution );
  825. nameLabel->setText( p_data->descs );
  826. CONNECT( slider, valueChanged( int ), this, updateText( int ) );
  827. setValue( initialValue() );
  828. /* In case current == min|max text would not be first updated */
  829. if ( slider->value() == slider->maximum() ||
  830. slider->value() == slider->minimum() )
  831. updateText( slider->value() );
  832. CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
  833. }
  834. void FilterSliderData::setValue( float f )
  835. {
  836. slider->setValue( f / p_data->f_resolution );
  837. }
  838. void FilterSliderData::updateText( int i )
  839. {
  840. float f = ((float) i) * p_data->f_resolution * p_data->f_visual_multiplier;
  841. valueLabel->setText( QString( p_data->units )
  842. .prepend( "%1 " )
  843. .arg( QString::number( f, 'f', 1 ) ) );
  844. }
  845. float FilterSliderData::initialValue()
  846. {
  847. vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
  848. float f = p_data->f_value;
  849. if( p_aout )
  850. {
  851. if ( var_Type( p_aout, qtu(p_data->name) ) == 0 )
  852. {
  853. vlc_object_release( p_aout );
  854. /* Not found, will try in config */
  855. }
  856. else
  857. {
  858. f = var_GetFloat( p_aout, qtu(p_data->name) );
  859. vlc_object_release( p_aout );
  860. return f;
  861. }
  862. }
  863. if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
  864. return f;
  865. f = config_GetFloat( p_intf, qtu(p_data->name) );
  866. return f;
  867. }
  868. void FilterSliderData::onValueChanged( int i ) const
  869. {
  870. float f = ((float) i) * p_data->f_resolution;
  871. vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
  872. if ( p_aout )
  873. {
  874. var_SetFloat( p_aout, qtu(p_data->name), f );
  875. vlc_object_release( p_aout );
  876. }
  877. writeToConfig();
  878. }
  879. void FilterSliderData::writeToConfig() const
  880. {
  881. if ( !b_save_to_config ) return;
  882. float f = ((float) slider->value()) * p_data->f_resolution;
  883. config_PutFloat( p_intf, qtu(p_data->name), f );
  884. }
  885. void FilterSliderData::setSaveToConfig( bool b )
  886. {
  887. b_save_to_config = b;
  888. }
  889. AudioFilterControlWidget::AudioFilterControlWidget
  890. ( intf_thread_t *_p_intf, QWidget *parent, const char *_name ) :
  891. QWidget( parent ), p_intf( _p_intf ), name( _name ), i_smallfont(0)
  892. {}
  893. void AudioFilterControlWidget::build()
  894. {
  895. QFont smallFont = QApplication::font();
  896. smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
  897. QVBoxLayout *layout = new QVBoxLayout( this );
  898. slidersBox = new QGroupBox( qtr( "Enable" ) );
  899. slidersBox->setCheckable( true );
  900. layout->addWidget( slidersBox );
  901. QGridLayout *ctrlLayout = new QGridLayout( slidersBox );
  902. int i = 0;
  903. foreach( const FilterSliderData::slider_data_t &data, controls )
  904. {
  905. QSlider *slider = new QSlider( Qt::Vertical );
  906. QLabel *valueLabel = new QLabel();
  907. valueLabel->setFont( smallFont );
  908. valueLabel->setAlignment( Qt::AlignHCenter );
  909. QLabel *nameLabel = new QLabel();
  910. nameLabel->setFont( smallFont );
  911. nameLabel->setAlignment( Qt::AlignHCenter );
  912. FilterSliderData *filter =
  913. new FilterSliderData( this, p_intf,
  914. slider, valueLabel, nameLabel, & data );
  915. ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
  916. ctrlLayout->addWidget( valueLabel, 1, i, Qt::AlignHCenter );
  917. ctrlLayout->addWidget( nameLabel, 2, i, Qt::AlignHCenter );
  918. i++;
  919. sliderDatas << filter;
  920. }
  921. vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
  922. char *psz_af;
  923. if( p_aout )
  924. {
  925. psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
  926. vlc_object_release( p_aout );
  927. }
  928. else
  929. psz_af = config_GetPsz( p_intf, "audio-filter" );
  930. if( psz_af && strstr( psz_af, qtu(name) ) != NULL )
  931. slidersBox->setChecked( true );
  932. else
  933. slidersBox->setChecked( false );
  934. CONNECT( slidersBox, toggled(bool), this, enable(bool) );
  935. free( psz_af );
  936. }
  937. AudioFilterControlWidget::~AudioFilterControlWidget()
  938. {
  939. }
  940. void AudioFilterControlWidget::enable( bool b_enable ) const
  941. {
  942. ChangeAFiltersString( p_intf, qtu(name), b_enable );
  943. playlist_EnableAudioFilter( THEPL, qtu(name), b_enable );
  944. }
  945. void AudioFilterControlWidget::setSaveToConfig( bool b_save )
  946. {
  947. foreach( FilterSliderData *f, sliderDatas )
  948. f->setSaveToConfig( b_save );
  949. }
  950. /**********************************************************************
  951. * Equalizer
  952. **********************************************************************/
  953. EqualizerSliderData::EqualizerSliderData( QObject *parent, intf_thread_t *_p_intf,
  954. QSlider *slider, QLabel *_label,
  955. QLabel *_nameLabel, const slider_data_t *_p_data,
  956. int _index )
  957. : FilterSliderData( parent, slider ), index( _index )
  958. {
  959. p_intf = _p_intf;
  960. valueLabel = _label;
  961. nameLabel = _nameLabel;
  962. p_data = _p_data;
  963. slider->setMinimum( p_data->f_min / p_data->f_resolution );
  964. slider->setMaximum( p_data->f_max / p_data->f_resolution );
  965. nameLabel->setText( p_data->descs );
  966. CONNECT( slider, valueChanged( int ), this, updateText( int ) );
  967. setValue( initialValue() );
  968. updateText( slider->value() );
  969. CONNECT( slider, valueChanged( int ), this, onValueChanged( int ) );
  970. }
  971. QStringList EqualizerSliderData::getBandsFromAout() const
  972. {
  973. vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
  974. QStringList bands;
  975. if( p_aout )
  976. {
  977. if ( var_Type( p_aout, qtu(p_data->name) ) == VLC_VAR_STRING )
  978. {
  979. char *psz_bands = var_GetString( p_aout, qtu(p_data->name) );
  980. if ( psz_bands )
  981. {
  982. bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
  983. free( psz_bands );
  984. }
  985. }
  986. vlc_object_release( p_aout );
  987. }
  988. if ( bands.count() ) return bands;
  989. /* Or try config then */
  990. if ( ! config_FindConfig( VLC_OBJECT(p_intf), qtu(p_data->name) ) )
  991. return bands;
  992. char *psz_bands = config_GetPsz( p_intf, qtu(p_data->name) );
  993. if ( psz_bands )
  994. {
  995. bands = QString( psz_bands ).split( " ", QString::SkipEmptyParts );
  996. free( psz_bands );
  997. }
  998. return bands;
  999. }
  1000. float EqualizerSliderData::initialValue()
  1001. {
  1002. float f = p_data->f_value;
  1003. QStringList bands = getBandsFromAout();
  1004. if ( bands.count() > index )
  1005. f = QLocale( QLocale::C ).toFloat( bands[ index ] );
  1006. return f;
  1007. }
  1008. void EqualizerSliderData::onValueChanged( int i ) const
  1009. {
  1010. QStringList bands = getBandsFromAout();
  1011. if ( bands.count() > index )
  1012. {
  1013. float f = ((float) i) * p_data->f_resolution;
  1014. bands[ index ] = QLocale( QLocale::C ).toString( f );
  1015. vlc_object_t *p_aout = (vlc_object_t *) THEMIM->getAout();
  1016. if ( p_aout )
  1017. {
  1018. var_SetString( p_aout, qtu(p_data->name), qtu(bands.join( " " )) );
  1019. vlc_object_release( p_aout );
  1020. }
  1021. writeToConfig();
  1022. }
  1023. }
  1024. void EqualizerSliderData::writeToConfig() const
  1025. {
  1026. if ( !b_save_to_config ) return;
  1027. QStringList bands = getBandsFromAout();
  1028. if ( bands.count() > index )
  1029. {
  1030. float f = (float) slider->value() * p_data->f_resolution;
  1031. bands[ index ] = QLocale( QLocale::C ).toString( f );
  1032. config_PutPsz( p_intf, qtu(p_data->name), qtu(bands.join( " " )) );
  1033. }
  1034. }
  1035. Equalizer::Equalizer( intf_thread_t *p_intf, QWidget *parent )
  1036. : AudioFilterControlWidget( p_intf, parent, "equalizer" )
  1037. {
  1038. i_smallfont = -3;
  1039. bool b_vlcBands = var_InheritBool( p_intf, "equalizer-vlcfreqs" );
  1040. const FilterSliderData::slider_data_t vlc_bands[10] =
  1041. {
  1042. { "equalizer-bands", qtr("60 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1043. { "equalizer-bands", qtr("170 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1044. { "equalizer-bands", qtr("310 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1045. { "equalizer-bands", qtr("600 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1046. { "equalizer-bands", qtr("1 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1047. { "equalizer-bands", qtr("3 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1048. { "equalizer-bands", qtr("6 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1049. { "equalizer-bands", qtr("12 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1050. { "equalizer-bands", qtr("14 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1051. { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1052. };
  1053. const FilterSliderData::slider_data_t iso_bands[10] =
  1054. {
  1055. { "equalizer-bands", qtr("31 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1056. { "equalizer-bands", qtr("63 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1057. { "equalizer-bands", qtr("125 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1058. { "equalizer-bands", qtr("250 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1059. { "equalizer-bands", qtr("500 Hz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1060. { "equalizer-bands", qtr("1 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1061. { "equalizer-bands", qtr("2 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1062. { "equalizer-bands", qtr("4 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1063. { "equalizer-bands", qtr("8 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1064. { "equalizer-bands", qtr("16 KHz"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 },
  1065. };
  1066. const FilterSliderData::slider_data_t preamp_vals =
  1067. { "equalizer-preamp", qtr("Preamp"), qtr("dB"), -20.0f, 20.0f, 0.0f, 0.1f, 1.0 };
  1068. for( int i=0; i<10 ;i++ ) controls.append( (b_vlcBands) ? vlc_bands[i] : iso_bands[i] );
  1069. preamp_values = preamp_vals;
  1070. build();
  1071. }
  1072. void Equalizer::build()
  1073. {
  1074. QFont smallFont = QApplication::font();
  1075. smallFont.setPointSize( smallFont.pointSize() + i_smallfont );
  1076. Ui::EqualizerWidget ui;
  1077. ui.setupUi( this );
  1078. QGridLayout *ctrlLayout = new QGridLayout( ui.slidersPlaceholder );
  1079. /* set up preamp control */
  1080. ui.preampLabel->setFont( smallFont );
  1081. ui.preampValue->setFont( smallFont );
  1082. preamp = new FilterSliderData( this, p_intf,
  1083. ui.preampSlider, ui.preampValue, ui.preampLabel, & preamp_values );
  1084. /* fix sliders spacing accurately */
  1085. int i_width = qMax( QFontMetrics( smallFont ).width( "500 Hz" ),
  1086. QFontMetrics( smallFont ).width( "-20.0 dB" ) );
  1087. int i = 0;
  1088. foreach( const FilterSliderData::slider_data_t &data, controls )
  1089. {
  1090. QSlider *slider = new QSlider( Qt::Vertical );
  1091. slider->setMinimumWidth( i_width );
  1092. QLabel *valueLabel = new QLabel();
  1093. valueLabel->setFont( smallFont );
  1094. valueLabel->setAlignment( Qt::AlignHCenter );
  1095. QLabel *nameLabel = new QLabel();
  1096. nameLabel->setFont( smallFont );
  1097. nameLabel->setAlignment( Qt::AlignHCenter );
  1098. EqualizerSliderData *filter =
  1099. new EqualizerSliderData( this, p_intf,
  1100. slider, valueLabel, nameLabel, & data, i );
  1101. ctrlLayout->addWidget( slider, 0, i, Qt::AlignHCenter );
  1102. ctrlLayout->addWidget( valueLabel, 2, i, Qt::AlignHCenter );
  1103. ctrlLayout->addWidget( nameLabel, 1, i, Qt::AlignHCenter );
  1104. sliderDatas << filter; /* keep track for applying presets */
  1105. i++;
  1106. }
  1107. /* Add the listed presets */
  1108. ui.presetsCombo->addItem( "", QVariant() ); /* 1st entry = custom/modified */
  1109. for( i = 0 ; i < NB_PRESETS ; i ++ )
  1110. {
  1111. QGraphicsScene scene;
  1112. QPixmap icon( 40, 40 );
  1113. icon.fill( Qt::transparent );
  1114. QPainter painter( &icon );
  1115. for ( int j = 0; j < eqz_preset_10b[i].i_band; j++ )
  1116. {
  1117. float f_value = eqz_preset_10b[i].f_amp[j];
  1118. if ( f_value > 20.0 ) f_value = 20.0;
  1119. if ( f_value < -20.0 ) f_value = -20.0;
  1120. QRectF shape( j, 20.0 - f_value, 1, f_value );
  1121. scene.addRect( shape, QPen(), palette().brush( QPalette::WindowText ) );
  1122. }
  1123. scene.addLine( 0.0, 20.0, eqz_preset_10b[i].i_band, 20.0,
  1124. palette().color( QPalette::WindowText ) );
  1125. scene.setSceneRect( 0.0, 0.0, eqz_preset_10b[i].i_band , 40.0 );
  1126. scene.render( &painter, icon.rect(), scene.sceneRect(), Qt::IgnoreAspectRatio );
  1127. ui.presetsCombo->addItem( icon, qtr( preset_list_text[i] ),
  1128. QVariant( preset_list[i] ) );
  1129. }
  1130. CONNECT( ui.presetsCombo, activated(int), this, setCorePreset(int) );
  1131. /* Set enable checkbox */
  1132. vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
  1133. char *psz_af;
  1134. if( p_aout )
  1135. {
  1136. psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
  1137. vlc_object_release( p_aout );
  1138. }
  1139. else
  1140. psz_af = config_GetPsz( p_intf, "audio-filter" );
  1141. /* To enable or disable subwidgets */
  1142. /* If that list grows, better iterate over layout's childs */
  1143. CONNECT( ui.enableCheck, toggled(bool), ui.presetsCombo, setEnabled(bool) );
  1144. CONNECT( ui.enableCheck, toggled(bool), ui.presetLabel, setEnabled(bool) );
  1145. CONNECT( ui.enableCheck, toggled(bool), ui.eq2PassCheck, setEnabled(bool) );
  1146. CONNECT( ui.enableCheck, toggled(bool), ui.slidersPlaceholder, setEnabled(bool) );
  1147. CONNECT( ui.enableCheck, toggled(bool), ui.preampSlider, setEnabled(bool) );
  1148. CONNECT( ui.enableCheck, toggled(bool), ui.preampValue, setEnabled(bool) );
  1149. CONNECT( ui.enableCheck, toggled(bool), ui.preampLabel, setEnabled(bool) );
  1150. if( psz_af && strstr( psz_af, qtu(name) ) != NULL )
  1151. ui.enableCheck->setChecked( true );
  1152. else
  1153. ui.enableCheck->setChecked( false );
  1154. /* workaround for non emitted toggle() signal */
  1155. ui.enableCheck->toggle(); ui.enableCheck->toggle();
  1156. free( psz_af );
  1157. CONNECT( ui.enableCheck, toggled(bool), this, enable(bool) );
  1158. /* Connect and set 2 Pass checkbox */
  1159. ui.eq2PassCheck->setChecked( var_InheritBool( p_aout, "equalizer-2pass" ) );
  1160. CONNECT( ui.eq2PassCheck, toggled(bool), this, enable2Pass(bool) );
  1161. }
  1162. void Equalizer::setSaveToConfig( bool b_save )
  1163. {
  1164. AudioFilterControlWidget::setSaveToConfig( b_save );
  1165. preamp->setSaveToConfig( b_save );
  1166. }
  1167. void Equalizer::setCorePreset( int i_preset )
  1168. {
  1169. if( i_preset < 1 )
  1170. return;
  1171. i_preset--;/* 1st in index was an empty entry */
  1172. preamp->setValue( eqz_preset_10b[i_preset].f_preamp );
  1173. for ( int i=0; i< qMin( eqz_preset_10b[i_preset].i_band,
  1174. sliderDatas.count() ) ; i++ )
  1175. sliderDatas[i]->setValue( eqz_preset_10b[i_preset].f_amp[i] );
  1176. vlc_object_t *p_aout = (vlc_object_t *)THEMIM->getAout();
  1177. if( p_aout )
  1178. {
  1179. var_SetString( p_aout , "equalizer-preset" , preset_list[i_preset] );
  1180. vlc_object_release( p_aout );
  1181. }
  1182. config_PutPsz( p_intf, "equalizer-preset", preset_list[i_preset] );
  1183. }
  1184. /* Function called when the set2Pass button is activated */
  1185. void Equalizer::enable2Pass( bool b_enable ) const
  1186. {
  1187. vlc_object_t *p_aout= (vlc_object_t *)THEMIM->getAout();
  1188. if( p_aout )
  1189. {
  1190. var_SetBool( p_aout, "equalizer-2pass", b_enable );
  1191. vlc_object_release( p_aout );
  1192. }
  1193. config_PutInt( p_intf, "equalizer-2pass", b_enable );
  1194. }
  1195. /**********************************************************************
  1196. * Audio filters
  1197. **********************************************************************/
  1198. /**********************************************************************
  1199. * Dynamic range compressor
  1200. **********************************************************************/
  1201. Compressor::Compressor( intf_thread_t *p_intf, QWidget *parent )
  1202. : AudioFilterControlWidget( p_intf, parent, "compressor" )
  1203. {
  1204. i_smallfont = -2;
  1205. const FilterSliderData::slider_data_t a[7] =
  1206. {
  1207. { "compressor-rms-peak", qtr("RMS/peak"), "", 0.0f, 1.0f, 0.00f, 0.001f, 1.0 },
  1208. { "compressor-attack", qtr("Attack"), qtr("ms"), 1.5f, 400.0f, 25.00f, 0.100f, 1.0 },
  1209. { "compressor-release", qtr("Release"), qtr("ms"), 2.0f, 800.0f, 100.00f, 0.100f, 1.0 },
  1210. { "compressor-threshold", qtr("Threshold"), qtr("dB"), -30.0f, 0.0f, -11.00f, 0.010f, 1.0 },
  1211. { "compressor-ratio", qtr("Ratio"), ":1", 1.0f, 20.0f, 8.00f, 0.010f, 1.0 },
  1212. { "compressor-knee", qtr("Knee\nradius"), qtr("dB"), 1.0f, 10.0f, 2.50f, 0.010f, 1.0 },
  1213. { "compressor-makeup-gain", qtr("Makeup\ngain"), qtr("dB"), 0.0f, 24.0f, 7.00f, 0.010f, 1.0 },
  1214. };
  1215. for( int i=0; i<7 ;i++ ) controls.append( a[i] );
  1216. build();
  1217. }
  1218. /**********************************************************************
  1219. * Spatializer
  1220. **********************************************************************/
  1221. Spatializer::Spatializer( intf_thread_t *p_intf, QWidget *parent )
  1222. : AudioFilterControlWidget( p_intf, parent, "spatializer" )
  1223. {
  1224. i_smallfont = -1;
  1225. const FilterSliderData::slider_data_t a[5] =
  1226. {
  1227. { "spatializer-roomsize", qtr("Size"), "", 0.0f, 1.1f, 0.85f, 0.1f, 10.0 },
  1228. { "spatializer-width", qtr("Width"), "", 0.0f, 1.0f, 1.0f, 0.1f, 10.0 },
  1229. { "spatializer-wet", qtr("Wet"), "", 0.0f, 1.0f, 0.4f, 0.1f, 10.0 },
  1230. { "spatializer-dry", qtr("Dry"), "", 0.0f, 1.0f, 0.5f, 0.1f, 10.0 },
  1231. { "spatializer-damp", qtr("Damp"), "", 0.0f, 1.0f, 0.5f, 0.1f, 10.0 },
  1232. };
  1233. for( int i=0; i<5 ;i++ ) controls.append( a[i] );
  1234. build();
  1235. }
  1236. #include <QToolButton>
  1237. #include <QGridLayout>
  1238. #define SUBSDELAY_CFG_MODE "subsdelay-mode"
  1239. #define SUBSDELAY_CFG_FACTOR "subsdelay-factor"
  1240. #define SUBSDELAY_MODE_ABSOLUTE 0
  1241. #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY 1
  1242. #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
  1243. SyncWidget::SyncWidget( QWidget *_parent ) : QWidget( _parent )
  1244. {
  1245. QHBoxLayout *layout = new QHBoxLayout;
  1246. spinBox.setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
  1247. spinBox.setDecimals( 3 );
  1248. spinBox.setMinimum( -600.0 );
  1249. spinBox.setMaximum( 600.0 );
  1250. spinBox.setSingleStep( 0.1 );
  1251. spinBox.setSuffix( " s" );
  1252. spinBox.setButtonSymbols( QDoubleSpinBox::PlusMinus );
  1253. CONNECT( &spinBox, valueChanged( double ), this, valueChangedHandler( double ) );
  1254. layout->addWidget( &spinBox );
  1255. layout->addWidget( &spinLabel );
  1256. layout->setContentsMargins( 0, 0, 0, 0 );
  1257. setLayout( layout );
  1258. }
  1259. void SyncWidget::valueChangedHandler( double d )
  1260. {
  1261. if ( d < 0 )
  1262. spinLabel.setText( qtr("(Hastened)") );
  1263. else if ( d > 0 )
  1264. spinLabel.setText( qtr("(Delayed)") );
  1265. else
  1266. spinLabel.setText( "" );
  1267. emit valueChanged( d );
  1268. }
  1269. void SyncWidget::setValue( double d )
  1270. {
  1271. spinBox.setValue( d );
  1272. }
  1273. SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
  1274. QWidget( _parent ) , p_intf( _p_intf )
  1275. {
  1276. QGroupBox *AVBox, *subsBox;
  1277. QToolButton *updateButton;
  1278. b_userAction = true;
  1279. QGridLayout *mainLayout = new QGridLayout( this );
  1280. /* AV sync */
  1281. AVBox = new QGroupBox( qtr( "Audio/Video" ) );
  1282. QGridLayout *AVLayout = new QGridLayout( AVBox );
  1283. QLabel *AVLabel = new QLabel;
  1284. AVLabel->setText( qtr( "Audio track synchronization:" ) );
  1285. AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
  1286. AVSpin = new SyncWidget( this );
  1287. AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
  1288. mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
  1289. /* Subs */
  1290. subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
  1291. QGridLayout *subsLayout = new QGridLayout( subsBox );
  1292. QLabel *subsLabel = new QLabel;
  1293. subsLabel->setText( qtr( "Subtitle track synchronization:" ) );
  1294. subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
  1295. subsSpin = new SyncWidget( this );
  1296. subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
  1297. QLabel *subSpeedLabel = new QLabel;
  1298. subSpeedLabel->setText( qtr( "Subtitle speed:" ) );
  1299. subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 1 );
  1300. subSpeedSpin = new QDoubleSpinBox;
  1301. subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
  1302. subSpeedSpin->setDecimals( 3 );
  1303. subSpeedSpin->setMinimum( 1 );
  1304. subSpeedSpin->setMaximum( 100 );
  1305. subSpeedSpin->setSingleStep( 0.2 );
  1306. subSpeedSpin->setSuffix( " fps" );
  1307. subSpeedSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
  1308. subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
  1309. QLabel *subDurationLabel = new QLabel;
  1310. subDurationLabel->setText( qtr( "Subtitle duration factor:" ) );
  1311. subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
  1312. subDurationSpin = new QDoubleSpinBox;
  1313. subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
  1314. subDurationSpin->setDecimals( 3 );
  1315. subDurationSpin->setMinimum( 0 );
  1316. subDurationSpin->setMaximum( 20 );
  1317. subDurationSpin->setSingleStep( 0.2 );
  1318. subDurationSpin->setButtonSymbols( QDoubleSpinBox::PlusMinus );
  1319. subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
  1320. mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
  1321. updateButton = new QToolButton;
  1322. updateButton->setAutoRaise( true );
  1323. mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
  1324. /* Various Connects */
  1325. CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
  1326. CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
  1327. CONNECT( subSpeedSpin, valueChanged ( double ),
  1328. this, adjustSubsSpeed( double ) );
  1329. CONNECT( subDurationSpin, valueChanged ( double ),
  1330. this, adjustSubsDuration( double ) );
  1331. CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
  1332. BUTTON_SET_ACT_I( updateButton, "", update,
  1333. qtr( "Force update of this dialog's values" ), update() );
  1334. initSubsDuration();
  1335. /* Set it */
  1336. update();
  1337. }
  1338. SyncControls::~SyncControls()
  1339. {
  1340. subsdelayClean();
  1341. }
  1342. void SyncControls::clean()
  1343. {
  1344. b_userAction = false;
  1345. AVSpin->setValue( 0.0 );
  1346. subsSpin->setValue( 0.0 );
  1347. subSpeedSpin->setValue( 1.0 );
  1348. subsdelayClean();
  1349. b_userAction = true;
  1350. }
  1351. void SyncControls::update()
  1352. {
  1353. b_userAction = false;
  1354. int64_t i_delay;
  1355. if( THEMIM->getInput() )
  1356. {
  1357. i_delay = var_GetInteger( THEMIM->getInput(), "audio-delay" );
  1358. AVSpin->setValue( ( (double)i_delay ) / CLOCK_FREQ );
  1359. i_delay = var_GetInteger( THEMIM->getInput(), "spu-delay" );
  1360. subsSpin->setValue( ( (double)i_delay ) / CLOCK_FREQ );
  1361. subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
  1362. subDurationSpin->setValue( var_InheritFloat( p_intf, SUBSDELAY_CFG_FACTOR ) );
  1363. }
  1364. b_userAction = true;
  1365. }
  1366. void SyncControls::advanceAudio( double f_advance )
  1367. {
  1368. if( THEMIM->getInput() && b_userAction )
  1369. {
  1370. int64_t i_delay = f_advance * CLOCK_FREQ;
  1371. var_SetInteger( THEMIM->getInput(), "audio-delay", i_delay );
  1372. }
  1373. }
  1374. void SyncControls::advanceSubs( double f_advance )
  1375. {
  1376. if( THEMIM->getInput() && b_userAction )
  1377. {
  1378. int64_t i_delay = f_advance * CLOCK_FREQ;
  1379. var_SetInteger( THEMIM->getInput(), "spu-delay", i_delay );
  1380. }
  1381. }
  1382. void SyncControls::adjustSubsSpeed( double f_fps )
  1383. {
  1384. if( THEMIM->getInput() && b_userAction )
  1385. {
  1386. var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
  1387. }
  1388. }
  1389. void SyncControls::adjustSubsDuration( double f_factor )
  1390. {
  1391. if( THEMIM->getInput() && b_userAction )
  1392. {
  1393. subsdelaySetFactor( f_factor );
  1394. ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
  1395. }
  1396. }
  1397. void SyncControls::initSubsDuration()
  1398. {
  1399. int i_mode = var_InheritInteger( p_intf, SUBSDELAY_CFG_MODE );
  1400. switch (i_mode)
  1401. {
  1402. default:
  1403. case SUBSDELAY_MODE_ABSOLUTE:
  1404. subDurationSpin->setToolTip( qtr( "Extend subtitle duration by this value.\n"
  1405. "Set 0 to disable." ) );
  1406. subDurationSpin->setSuffix( " s" );
  1407. break;
  1408. case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
  1409. subDurationSpin->setToolTip( qtr( "Multiply subtitle duration by this value.\n"
  1410. "Set 0 to disable." ) );
  1411. subDurationSpin->setSuffix( "" );
  1412. break;
  1413. case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
  1414. subDurationSpin->setToolTip( qtr( "Recalculate subtitle duration according\n"
  1415. "to their content and this value.\n"
  1416. "Set 0 to disable." ) );
  1417. subDurationSpin->setSuffix( "" );
  1418. break;
  1419. }
  1420. }
  1421. void SyncControls::subsdelayClean()
  1422. {
  1423. /* Remove subsdelay filter */
  1424. ChangeVFiltersString( p_intf, "subsdelay", false );
  1425. }
  1426. void SyncControls::subsdelaySetFactor( double f_factor )
  1427. {
  1428. /* Set the factor in the preferences */
  1429. config_PutFloat( p_intf, SUBSDELAY_CFG_FACTOR, f_factor );
  1430. /* Try to find an instance of subsdelay, and set its factor */
  1431. vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->obj.libvlc, "subsdelay" );
  1432. if( p_obj )
  1433. {
  1434. var_SetFloat( p_obj, SUBSDELAY_CFG_FACTOR, f_factor );
  1435. vlc_object_release( p_obj );
  1436. }
  1437. }
  1438. /**********************************************************************
  1439. * Video filters / Adjust
  1440. **********************************************************************/
  1441. /**********************************************************************
  1442. * Extended playbak controls
  1443. **********************************************************************/