22 #include "MALedSkit.hpp" 24 #include "core/MADevice.hpp" 25 #include "core/MAValueGenerators.hpp" 26 #include "MASkitDatabase.hpp" 28 #include <MCContainers.hpp> 30 #include <boost/algorithm/string.hpp> 31 #include <boost/math/constants/constants.hpp> 41 unsigned char Char = data.
GetUChar();
46 Time = (Time << 7)+(
int)Char;
49 Time = (Time << 7)+(
int)Char % 128;
75 MC_LOG(
"-- %s LED animations --",
Name.c_str());
79 if (!animation->empty())
81 printf(
"LED 0x%x: ", i);
83 std::string LogMessage;
93 if (!LogMessage.empty())
94 MC_LOG(
"%s", LogMessage.c_str());
108 MC_WARNING(
"Wrong file signature, can't decode LED sequence");
118 if (BinaryData.
GetInt16(
false) != 0)
120 MC_WARNING(
"Not format 0 file, can't decode the LED sequence");
125 if (BinaryData.
GetInt16(
false) != 1)
127 MC_WARNING(
"Not a file with one track, can't decode the LED sequence");
131 int TimeDelta = BinaryData.
GetInt16(
false);
136 MC_WARNING(
"Wrong chunk signature, can't decode LED sequence");
141 int ChunkLength = BinaryData.
GetInt32(
false);
147 MC_WARNING(
"Only Sony ERS-7 model is supported, can't decode LED sequence");
153 ChunkLength -= (4+9+1);
157 MC_WARNING(
"Track name is not readable, can't decode LED sequence");
162 int StringLength = BinaryData.
GetUChar();
164 if (BinaryData.
GetString(StringLength).empty())
166 MC_WARNING(
"Track name is not readable, can't decode LED sequence");
172 ChunkLength -= (1+StringLength+1);
176 MC_WARNING(
"Tempo identifier is invalid, can't decode LED sequence");
186 const float TimeConversionRate = (float)KeyframeUsec / ((
float)TimeDelta*1000 / 1024) / 1000;
187 int StartTime = (int)((
float)GetTime(BinaryData, ChunkLength)*TimeConversionRate);
202 MC::IntList Devices, StartTimes, Intensities;
205 LedSkit->
Name = name;
206 while (ChunkLength > 4)
208 unsigned char DeviceChar = BinaryData.
GetUChar();
209 unsigned char IntensityChar = BinaryData.
GetUChar();
212 if (IntensityChar == 31)
214 if (IntensityChar == 63)
216 if (IntensityChar == 95)
218 if (IntensityChar == 127)
220 if (IntensityChar > 0)
222 Devices.push_back((
int)DeviceChar);
223 Intensities.push_back((
int)IntensityChar);
224 StartTimes.push_back(StartTime);
226 if (IntensityChar == 0)
230 if (*device == DeviceChar)
232 LedSkit->
Animations[(int)DeviceChar].push_back(StartTimes[i]);
233 LedSkit->
Animations[(int)DeviceChar].push_back(StartTime-StartTimes[i]);
234 LedSkit->
Animations[(int)DeviceChar].push_back(Intensities[i]);
235 Devices.erase(Devices.begin()+i);
236 Intensities.erase(Intensities.begin()+i);
237 StartTimes.erase(StartTimes.begin()+i);
243 StartTime += (int)((
float)GetTime(BinaryData, ChunkLength)*TimeConversionRate);
244 if (ChunkLength == 4)
250 if (ChunkLength != 4 || BinaryData.
GetUChar() != 0x00 || BinaryData.
GetUChar() != 0xff ||
253 MC_WARNING(
"Invalid chunk ending, can't decode LED sequence");
259 MC_LOG(
"Decoded LED sequence: %s", name.c_str());
266 if (device > 255 ||
Animations[device].empty())
273 for (
unsigned int i = 0; i <
Animations[device].size()-2; i += 3)
275 float TargetValue = (float)
Animations[device][i+2] / 100;
276 bool GapBefore =
false;
293 const int Duration =
Animations[device][i+1] / 3;
296 0, Duration, Duration, Duration, 0,
false));
int16_t GetInt16(bool reverse_order=false)
Get a 16 bit integer from the current position.
std::string Name
LED name.
void AddGenerator(MAGeneratorBase &generator, bool in_front=false)
Add a new generator after the last internal generator.
MC::IntTable Animations
LED animations (first columns - start time, second - duration, third - intensity...)
static MALedSkit * DecodeLedData(const MCBinaryData &binary_data, const std::string &name)
Load LED sequence from binary data.
unsigned char GetUChar()
Get an unsigned char from the current position.
LED sequence (LED skit) class.
void Dump() const
Print the LED skit information.
#define MC_WARNING(...)
Warning macro.
std::string MCToStr(const T value, bool hex_manipulator=false)
Convert an other type to string with std::stringstream.
std::string GetString(unsigned int length, const std::string &additional_chars="")
Get a string from the current position.
#define foreach_i(_i, _iter, _container)
For each cycle with auto keyword and index values.
int GetDuration() const
Get skit duration.
MAGeneratorContainer * GetGeneratorContainer(unsigned int device) const
Get generator container for a device.
int SkitDuration
Skit duration (in msec)
void SetPosition(unsigned int position)
Set the cursor position.
MALedSkit()
Class constructor.
Generator container class.
float MCFloatInfinity()
Get float infinity.
int32_t GetInt32(bool reverse_order=false)
Get a 32 bit integer from the current position.
Periodic generator class (waveform _/‾\_)
#define MC_LOG(...)
Debug macro.
std::string GetName() const
Get the LED sequence name.
int GetPosition() const
Get the current position in the binary data.
bool IsPositionAtEnd() const
Check if the current position is at the end of the binary data.