]> git.sesse.net Git - vlc/blob - modules/video_filter/atmo/AtmoConfig.cpp
enhanced & corrected AtmoLight filter module
[vlc] / modules / video_filter / atmo / AtmoConfig.cpp
1 /*
2  * AtmoConfig.cpp: Class for holding all configuration values of AtmoWin - stores
3  * the values and retrieves its values from registry
4  *
5  * See the README.txt file for copyright information and how to reach the author(s).
6  *
7  * $Id$
8  */
9
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "AtmoConfig.h"
14
15 /* Import Hint
16
17    if somebody Adds new config option this has to be done in the following
18    files and includes!
19
20    AtmoConfig.h  -- extend class definition!, and add get... and set... Methods!
21                     so that the real variables are still hidden inside the class!
22    AtmoConfigRegistry.cpp --> SaveToRegistry();
23    AtmoConfigRegistry.cpp --> LoadFromRegistry();
24    AtmoConfig.cpp --> Assign( ... );
25
26 */
27
28 CAtmoConfig::CAtmoConfig()
29 {
30   // setup basic configruation structures...
31   m_IsShowConfigDialog = 0;
32   m_eAtmoConnectionType = actClassicAtmo;
33   for(int i=0;i<10;i++)
34       m_ChannelAssignments[i] = NULL;
35
36 #if defined (_ATMO_VLC_PLUGIN_)
37   m_devicename = NULL;
38   m_devicenames[0] = NULL;
39   m_devicenames[1] = NULL;
40   m_devicenames[2] = NULL;
41 #endif
42   // load all config values with there defaults
43   m_ZoneDefinitions  = NULL;
44   m_AtmoZoneDefCount = -1;
45   m_DMX_BaseChannels = NULL;
46
47   LoadDefaults();
48 }
49
50 CAtmoConfig::~CAtmoConfig() {
51    // and finally cleanup...
52    clearAllChannelMappings();
53
54    if(m_ZoneDefinitions)
55    {
56      for(int zone=0; zone<m_AtmoZoneDefCount; zone++)
57          delete m_ZoneDefinitions[zone];
58      delete m_ZoneDefinitions;
59      m_ZoneDefinitions = NULL;
60    }
61
62    free( m_DMX_BaseChannels );
63
64 #if defined (_ATMO_VLC_PLUGIN_)
65     free( m_devicename );
66     free( m_devicenames[0] );
67     free( m_devicenames[1] );
68     free( m_devicenames[2] );
69 #endif
70 }
71
72 void CAtmoConfig::LoadDefaults() {
73     //    m_eAtmoConnectionType = actSerialPort;
74     //    m_Comport
75 #if defined (_ATMO_VLC_PLUGIN_)
76
77     free( m_devicename );
78     free( m_devicenames[0] );
79     free( m_devicenames[1] );
80     free( m_devicenames[2] );
81
82     m_devicename = NULL;
83     m_devicenames[0] = NULL;
84     m_devicenames[1] = NULL;
85     m_devicenames[2] = NULL;
86
87 #else
88
89     m_Comport     = -1;
90     m_Comports[0] = -1;
91     m_Comports[1] = -1;
92     m_Comports[2] = -1;
93
94 #endif
95
96     m_eEffectMode = emDisabled;
97
98     m_IgnoreConnectionErrorOnStartup = ATMO_FALSE;
99
100     m_UpdateEdgeWeightningFlag = 0;
101
102
103
104     m_Software_gamma_mode = agcNone;
105     m_Software_gamma_red    = 10;
106     m_Software_gamma_green  = 10;
107     m_Software_gamma_blue   = 10;
108     m_Software_gamma_global = 10;
109
110     m_WhiteAdjustment_Red    = 255;
111     m_WhiteAdjustment_Green  = 255;
112     m_WhiteAdjustment_Blue   = 255;
113         m_UseSoftwareWhiteAdj    = 1;
114
115         m_ColorChanger_iSteps    = 50;
116         m_ColorChanger_iDelay    = 25;
117
118         m_LrColorChanger_iSteps  = 50;
119         m_LrColorChanger_iDelay  = 25;
120
121     m_IsSetShutdownColor     = 1;
122         m_ShutdownColor_Red      = 0;
123         m_ShutdownColor_Green    = 0;
124         m_ShutdownColor_Blue     = 0;
125
126     m_StaticColor_Red        = 127; // ??
127     m_StaticColor_Green      = 192;
128     m_StaticColor_Blue       = 255;
129
130     m_LiveViewFilterMode         = afmCombined;
131     m_LiveViewFilter_PercentNew  = 50;
132     m_LiveViewFilter_MeanLength  = 300;
133     m_LiveViewFilter_MeanThreshold   = 40;
134     m_show_statistics = ATMO_FALSE;
135
136     m_LiveView_EdgeWeighting  = 8;
137     m_LiveView_BrightCorrect  = 100;
138     m_LiveView_DarknessLimit  = 5;
139     m_LiveView_HueWinSize     = 3;
140     m_LiveView_SatWinSize     = 3;
141     m_LiveView_WidescreenMode = 0;
142
143     m_LiveView_HOverscanBorder  = 0;
144     m_LiveView_VOverscanBorder  = 0;
145     m_LiveView_DisplayNr        = 0;
146     m_LiveView_FrameDelay       = 30;
147     m_LiveView_GDI_FrameRate    = 25;
148
149
150     m_Hardware_global_gamma    = 128;
151     m_Hardware_global_contrast = 100;
152     m_Hardware_contrast_red    = 100;
153     m_Hardware_contrast_green  = 100;
154     m_Hardware_contrast_blue   = 100;
155
156     m_Hardware_gamma_red       = 22;
157     m_Hardware_gamma_green     = 22;
158     m_Hardware_gamma_blue      = 22;
159
160     m_DMX_BaseChannels         = strdup("0");
161     m_DMX_RGB_Channels        = 5; // so wie atmolight
162
163     m_MoMo_Channels           = 3; // default momo, there exists also a 4 ch version!
164
165     m_ZonesTopCount            = 1;
166     m_ZonesBottomCount         = 1;
167     m_ZonesLRCount             = 1;
168     m_ZoneSummary              = ATMO_FALSE;
169     UpdateZoneCount();
170
171
172     clearAllChannelMappings();
173     m_CurrentChannelAssignment = 0;
174     CAtmoChannelAssignment *temp = new CAtmoChannelAssignment();
175     temp->system = true;
176     temp->setName( "Standard" );
177     this->m_ChannelAssignments[0] =  temp;
178
179     UpdateZoneDefinitionCount();
180 }
181
182 void CAtmoConfig::Assign(CAtmoConfig *pAtmoConfigSrc) {
183
184 #if defined(_ATMO_VLC_PLUGIN_)
185     this->setSerialDevice(0, pAtmoConfigSrc->getSerialDevice(0));
186     this->setSerialDevice(1, pAtmoConfigSrc->getSerialDevice(1));
187     this->setSerialDevice(2, pAtmoConfigSrc->getSerialDevice(2));
188     this->setSerialDevice(3, pAtmoConfigSrc->getSerialDevice(3));
189 #else
190     this->m_Comport                  = pAtmoConfigSrc->m_Comport;
191     this->m_Comports[0]              = pAtmoConfigSrc->m_Comports[0];
192     this->m_Comports[1]              = pAtmoConfigSrc->m_Comports[1];
193     this->m_Comports[2]              = pAtmoConfigSrc->m_Comports[2];
194 #endif
195
196     this->m_eAtmoConnectionType      = pAtmoConfigSrc->m_eAtmoConnectionType;
197     this->m_eEffectMode              = pAtmoConfigSrc->m_eEffectMode;
198
199     this->m_WhiteAdjustment_Red      = pAtmoConfigSrc->m_WhiteAdjustment_Red;
200     this->m_WhiteAdjustment_Green    = pAtmoConfigSrc->m_WhiteAdjustment_Green;
201     this->m_WhiteAdjustment_Blue     = pAtmoConfigSrc->m_WhiteAdjustment_Blue;
202     this->m_UseSoftwareWhiteAdj      = pAtmoConfigSrc->m_UseSoftwareWhiteAdj;
203
204     this->m_IsSetShutdownColor       = pAtmoConfigSrc->m_IsSetShutdownColor;
205     this->m_ShutdownColor_Red        = pAtmoConfigSrc->m_ShutdownColor_Red;
206     this->m_ShutdownColor_Green      = pAtmoConfigSrc->m_ShutdownColor_Green;
207     this->m_ShutdownColor_Blue       = pAtmoConfigSrc->m_ShutdownColor_Blue;
208
209     this->m_ColorChanger_iSteps      = pAtmoConfigSrc->m_ColorChanger_iSteps;
210     this->m_ColorChanger_iDelay      = pAtmoConfigSrc->m_ColorChanger_iDelay;
211
212     this->m_LrColorChanger_iSteps    = pAtmoConfigSrc->m_LrColorChanger_iSteps;
213     this->m_LrColorChanger_iDelay    = pAtmoConfigSrc->m_LrColorChanger_iDelay;
214
215     this->m_StaticColor_Red          = pAtmoConfigSrc->m_StaticColor_Red;
216     this->m_StaticColor_Green        = pAtmoConfigSrc->m_StaticColor_Green;
217     this->m_StaticColor_Blue         = pAtmoConfigSrc->m_StaticColor_Blue;
218
219     this->m_LiveViewFilterMode             = pAtmoConfigSrc->m_LiveViewFilterMode;
220     this->m_LiveViewFilter_PercentNew      = pAtmoConfigSrc->m_LiveViewFilter_PercentNew;
221     this->m_LiveViewFilter_MeanLength      = pAtmoConfigSrc->m_LiveViewFilter_MeanLength;
222     this->m_LiveViewFilter_MeanThreshold   = pAtmoConfigSrc->m_LiveViewFilter_MeanThreshold;
223
224     this->m_show_statistics               = pAtmoConfigSrc->m_show_statistics;
225
226
227     this->m_LiveView_EdgeWeighting  =  pAtmoConfigSrc->m_LiveView_EdgeWeighting;
228     this->m_LiveView_BrightCorrect  =  pAtmoConfigSrc->m_LiveView_BrightCorrect;
229     this->m_LiveView_DarknessLimit  =  pAtmoConfigSrc->m_LiveView_DarknessLimit;
230     this->m_LiveView_HueWinSize     =  pAtmoConfigSrc->m_LiveView_HueWinSize;
231     this->m_LiveView_SatWinSize     =  pAtmoConfigSrc->m_LiveView_SatWinSize;
232     this->m_LiveView_WidescreenMode =  pAtmoConfigSrc->m_LiveView_WidescreenMode;
233
234     this->m_LiveView_HOverscanBorder  = pAtmoConfigSrc->m_LiveView_HOverscanBorder;
235     this->m_LiveView_VOverscanBorder  = pAtmoConfigSrc->m_LiveView_VOverscanBorder;
236     this->m_LiveView_DisplayNr        = pAtmoConfigSrc->m_LiveView_DisplayNr;
237     this->m_LiveView_FrameDelay       = pAtmoConfigSrc->m_LiveView_FrameDelay;
238     this->m_LiveView_GDI_FrameRate    = pAtmoConfigSrc->m_LiveView_GDI_FrameRate;
239
240     this->m_ZonesTopCount             = pAtmoConfigSrc->m_ZonesTopCount;
241     this->m_ZonesBottomCount          = pAtmoConfigSrc->m_ZonesBottomCount;
242     this->m_ZonesLRCount              = pAtmoConfigSrc->m_ZonesLRCount;
243     this->m_ZoneSummary               = pAtmoConfigSrc->m_ZoneSummary;
244     UpdateZoneCount();
245
246     this->m_Software_gamma_mode      =  pAtmoConfigSrc->m_Software_gamma_mode;
247     this->m_Software_gamma_red       =  pAtmoConfigSrc->m_Software_gamma_red;
248     this->m_Software_gamma_green     =  pAtmoConfigSrc->m_Software_gamma_green;
249     this->m_Software_gamma_blue      =  pAtmoConfigSrc->m_Software_gamma_blue;
250     this->m_Software_gamma_global    =  pAtmoConfigSrc->m_Software_gamma_global;
251
252     this->setDMX_BaseChannels( pAtmoConfigSrc->getDMX_BaseChannels() );
253
254     this->m_DMX_RGB_Channels         = pAtmoConfigSrc->m_DMX_RGB_Channels;
255
256     this->m_MoMo_Channels            = pAtmoConfigSrc->m_MoMo_Channels;
257
258     this->m_CurrentChannelAssignment = pAtmoConfigSrc->m_CurrentChannelAssignment;
259
260     clearChannelMappings();
261     for(int i=1;i<pAtmoConfigSrc->getNumChannelAssignments();i++) {
262         CAtmoChannelAssignment *ta = pAtmoConfigSrc->m_ChannelAssignments[i];
263         if(ta!=NULL) {
264             CAtmoChannelAssignment *dest = this->m_ChannelAssignments[i];
265             if(dest == NULL) {
266                dest = new CAtmoChannelAssignment();
267                this->m_ChannelAssignments[i] = dest;
268             }
269             // memcpy(dest, ta, sizeof(tChannelAssignment));
270             dest->setSize(ta->getSize());
271             dest->setName(ta->getName());
272             dest->system = ta->system;
273             for(int c=0;c<dest->getSize();c++)
274                 dest->setZoneIndex(c, ta->getZoneIndex(c));
275         }
276     }
277
278     UpdateZoneDefinitionCount();
279 }
280
281
282
283 int CAtmoConfig::getNumChannelAssignments() {
284     int z=0;
285     for(int i=0;i<10;i++)
286         if(this->m_ChannelAssignments[i]!=NULL) z++;
287     return z;
288 }
289
290 void CAtmoConfig::clearChannelMappings() {
291     for(int i=1;i<10;i++) {
292         CAtmoChannelAssignment *ca = m_ChannelAssignments[i];
293         if(ca!=NULL)
294            delete ca;
295         m_ChannelAssignments[i] = NULL;
296     }
297 }
298
299 void CAtmoConfig::clearAllChannelMappings() {
300     for(int i=0;i<10;i++) {
301         CAtmoChannelAssignment *ca = m_ChannelAssignments[i];
302         if(ca!=NULL)
303            delete ca;
304         m_ChannelAssignments[i] = NULL;
305     }
306 }
307
308 void CAtmoConfig::AddChannelAssignment(CAtmoChannelAssignment *ta) {
309     for(int i=0;i<10;i++) {
310         if(m_ChannelAssignments[i] == NULL) {
311            m_ChannelAssignments[i] = ta;
312            break;
313         }
314     }
315 }
316
317 void CAtmoConfig::SetChannelAssignment(int index, CAtmoChannelAssignment *ta) {
318      if(m_ChannelAssignments[index]!=NULL)
319         delete m_ChannelAssignments[index];
320      m_ChannelAssignments[index] = ta;
321 }
322
323 CAtmoZoneDefinition *CAtmoConfig::getZoneDefinition(int zoneIndex) {
324     if(zoneIndex < 0)
325        return NULL;
326     if(zoneIndex >= m_AtmoZoneDefCount)
327        return NULL;
328     return m_ZoneDefinitions[zoneIndex];
329
330 }
331
332 void CAtmoConfig::UpdateZoneCount()
333 {
334   m_computed_zones_count = m_ZonesTopCount + m_ZonesBottomCount + 2 * m_ZonesLRCount;
335   if(m_ZoneSummary)
336      m_computed_zones_count++;
337 }
338
339
340
341 int CAtmoConfig::getZoneCount()
342 {
343     return(m_computed_zones_count);
344 }
345
346 void CAtmoConfig::UpdateZoneDefinitionCount()
347 {
348    if( getZoneCount() != m_AtmoZoneDefCount)
349    {
350       // okay zonen anzahl hat sich geändert - wir müssen neu rechnen
351       // und allokieren!
352       if(m_ZoneDefinitions)
353       {
354         for(int zone=0; zone<m_AtmoZoneDefCount; zone++)
355             delete m_ZoneDefinitions[zone];
356         delete m_ZoneDefinitions;
357         m_ZoneDefinitions = NULL;
358       }
359       m_AtmoZoneDefCount = getZoneCount();
360       if(m_AtmoZoneDefCount > 0)
361       {
362          m_ZoneDefinitions = new CAtmoZoneDefinition*[m_AtmoZoneDefCount];
363          for(int zone=0; zone< m_AtmoZoneDefCount; zone++) {
364              m_ZoneDefinitions[zone] = new CAtmoZoneDefinition();
365              m_ZoneDefinitions[zone]->Fill(255);
366          }
367       }
368    }
369 }
370
371 #if defined(_ATMO_VLC_PLUGIN_)
372
373 char *CAtmoConfig::getSerialDevice(int i)
374 {
375    if(i == 0)
376       return m_devicename;
377    else  {
378        i--;
379        return m_devicenames[i];
380    }
381 }
382
383 void CAtmoConfig::setSerialDevice(int i,const char *pszNewDevice)
384 {
385     if(i == 0)
386        setSerialDevice(pszNewDevice);
387     else {
388        i--;
389        free( m_devicenames[i] );
390        if(pszNewDevice)
391           m_devicenames[i] = strdup(pszNewDevice);
392        else
393           m_devicenames[i] = NULL;
394     }
395 }
396
397 #else
398
399 int CAtmoConfig::getComport(int i)
400 {
401   if(i == 0)
402      return this->m_Comport;
403   else {
404      i--;
405      return this->m_Comports[i];
406   }
407 }
408
409 void CAtmoConfig::setComport(int i, int nr)
410 {
411   if(i == 0)
412       this->m_Comport = nr;
413   else {
414     this->m_Comports[i-1] = nr;
415   }
416 }
417
418 #endif
419
420 void CAtmoConfig::setDMX_BaseChannels(char *channels)
421 {
422      free(m_DMX_BaseChannels);
423      m_DMX_BaseChannels = strdup(channels);
424 }
425