You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(17) |
Jul
(84) |
Aug
(35) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
|
Feb
(15) |
Mar
(7) |
Apr
(6) |
May
|
Jun
(65) |
Jul
|
Aug
(22) |
Sep
|
Oct
|
Nov
|
Dec
|
From: NickS <nsc...@us...> - 2008-08-21 03:48:19
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000 In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv4830 Modified Files: ProximityDetectors.cs Log Message: updates to use new Maxbotics controller, which controls four detectors Index: ProximityDetectors.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/ProximityDetectors.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProximityDetectors.cs 19 Aug 2008 07:24:26 -0000 1.1 --- ProximityDetectors.cs 21 Aug 2008 03:47:45 -0000 1.2 *************** *** 3,6 **** --- 3,7 ---- using System.Text; using System.IO.Ports; + using System.Threading; namespace JellyTouch12000 *************** *** 18,26 **** private const string m_SerialPortA_name = "COM6"; private const string m_SerialPortB_name = "COM7"; - private const string m_SerialPortC_name = "COM8"; - private const string m_SerialPortD_name = "COM9"; ! private const int m_numDetectors = 4; ! private const int m_bufferSize = 8; private const float m_maxDelta = 0.5f; --- 19,25 ---- private const string m_SerialPortA_name = "COM6"; private const string m_SerialPortB_name = "COM7"; ! private const int m_numDetectors = 8; ! private int m_bufferSize = 1; private const float m_maxDelta = 0.5f; *************** *** 35,43 **** // serial ports talk to either the Maxbotics controllers, ! // or to the devices themselves private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! private SerialPort m_SerialPortC = new System.IO.Ports.SerialPort(); ! private SerialPort m_SerialPortD = new System.IO.Ports.SerialPort(); // we need to associate a detector to X number of ribs --- 34,47 ---- // serial ports talk to either the Maxbotics controllers, ! // or to the devices themselves. ! // if talking to a controller (the default), then 1 port reads 4 devices (so 4 ports = 8 devices) ! // if talking directly to a device, then thats 2 ports = 2 devices private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! ! // each controller has a thread to write the sensor configuration string, and ! // send sensor read commands (polling) ! private Thread m_ThreadControllerA = null; ! private Thread m_ThreadControllerB = null; // we need to associate a detector to X number of ribs *************** *** 69,74 **** this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); ! this.InitSerialPort(m_SerialPortC, m_SerialPortC_name, DataReceivedPortC); ! this.InitSerialPort(m_SerialPortD, m_SerialPortD_name, DataReceivedPortD); } --- 73,84 ---- this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); ! ! //start the thread to send sensor report commands ! m_ThreadControllerA = new Thread(new ThreadStart(ThreadControllerA)); ! m_ThreadControllerA.Name = "ThreadControllerA"; ! m_ThreadControllerA.Start(); ! m_ThreadControllerB = new Thread(new ThreadStart(ThreadControllerB)); ! m_ThreadControllerB.Name = "ThreadControllerB"; ! m_ThreadControllerB.Start(); } *************** *** 83,87 **** port.StopBits = StopBits.One; port.Handshake = Handshake.None; ! port.NewLine = "\r"; port.DataReceived += --- 93,97 ---- port.StopBits = StopBits.One; port.Handshake = Handshake.None; ! port.NewLine = "\r\n"; port.DataReceived += *************** *** 103,121 **** // //////////////////////////////////////////////////////////////////////////////// ! void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortA, 'A'); } ! void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB, 'B'); } ! void DataReceivedPortC(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortC, 'C'); } ! void DataReceivedPortD(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortD, 'D'); } --- 113,173 ---- // //////////////////////////////////////////////////////////////////////////////// ! private void ThreadControllerA() { ! ThreadController(m_SerialPortA); } ! private void ThreadControllerB() { ! ThreadController(m_SerialPortB); } ! private const int m_sleepTimeMs = 125; ! private void ThreadController(SerialPort port) { ! try ! { ! // configure each sensor for polled mode ! port.WriteLine("$100001"); ! Thread.Sleep(1000); ! port.WriteLine("$100101"); ! Thread.Sleep(1000); ! port.WriteLine("$100201"); ! Thread.Sleep(1000); ! port.WriteLine("$100301"); ! Thread.Sleep(1000); ! //port.WriteLine("$FF"); ! //Thread.Sleep(4000); ! ! // send a query sensor commands, this will kick-off the reading chain, where ! // the DataReceived routine will send another one after processing this one ! // comment out if you only want the range-check reports (far less reports) ! while (true) ! { ! port.WriteLine("$2000"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2001"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2002"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2003"); ! Thread.Sleep(m_sleepTimeMs); ! } ! } ! catch (Exception e) ! { ! //this is fatal! ! Console.WriteLine(e.ToString()); ! } ! } ! ! //////////////////////////////////////////////////////////////////////////////// ! // ! //////////////////////////////////////////////////////////////////////////////// ! void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) ! { ! DataReceived(m_SerialPortA, 'A'); } ! void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB, 'B'); } *************** *** 132,139 **** int detectorNum = -1; // the detector from which the reading was read // if the first char of the line of data received on the serial // port begins with 'R', then that means we are receiving data directly // from a detector ! if ((sData.Length == 4) && (caData[0] == 'R')) { char[] trimChars = { 'R' }; --- 184,243 ---- int detectorNum = -1; // the detector from which the reading was read + // CONTROLLER-DEVICE READ MODE: + // if the first char is a dollar-sign, then we are reading from the controller + if (caData[0] == '$') + { + //Console.WriteLine(caData); + int len = sData.Length; + + // check for sensor query report ($81) or sensor range change report ($91) + if ((len==7) && (((sData.Contains("$81")) || (sData.Contains("$91"))))) + { + char[] trimChars = { '$' }; + string sReport = sData.TrimStart(trimChars); + Int32 iReport = 0; + try + { + iReport = Int32.Parse(sReport,System.Globalization.NumberStyles.HexNumber); + } + catch + { + //Console.WriteLine(sRange); + return; // ignore crap reading + } + detectorNum = ((iReport & 0xFF00) >> 8); + int iDetNum = detectorNum; + if (portName == 'B') detectorNum += 4; // 4 detectors per controller + range = iReport & 0xFF; + //Console.WriteLine("detectorNum: " + detectorNum + ", range: " + range); + + // send a query sensor command + // comment out if you only want the range-check reports (far less reports) + // or if the polling thread is used + //string cmd = "$200" + iDetNum; ; + //if (portName == 'A') m_SerialPortA.WriteLine(cmd); + //else if (portName == 'B') m_SerialPortB.WriteLine(cmd); + } + else if ((len == 3) && (sData.Equals("$F0"))) + { + //Console.WriteLine("Controller command accepted on port " + portName); + return; + } + else if ((len == 3) && (sData.Equals("$F1"))) + { + Console.WriteLine("Controller command REJECTED on port " + portName); + return; + } + else if ((len == 13) && (sData.Equals("$900101010C10"))) + { + Console.WriteLine("Maxbotics controller v1.1.1 found on port " + portName); + return; + } + } + // DIRECT-DEVICE-READ MODE: // if the first char of the line of data received on the serial // port begins with 'R', then that means we are receiving data directly // from a detector ! else if ((sData.Length == 4) && (caData[0] == 'R')) { char[] trimChars = { 'R' }; *************** *** 142,146 **** { range = Int32.Parse(sRange); - if (range == 255) return; // this is an invalid reading } catch --- 246,249 ---- *************** *** 151,171 **** // figure-out which detector ! switch (portName) ! { ! case 'A': ! detectorNum = 0; ! break; ! case 'B': ! detectorNum = 1; ! break; ! case 'C': ! detectorNum = 2; ! break; ! case 'D': ! detectorNum = 3; ! break; ! default: ! return; ! } } else --- 254,261 ---- // figure-out which detector ! // note: in this code, we're talking directly to one device ! if (portName == 'A') detectorNum = 0; ! else if (portName == 'B') detectorNum = 1; ! else return; } else *************** *** 175,179 **** --- 265,273 ---- } + if (detectorNum == -1) return; // sanity-check + if (detectorNum >= m_numDetectors) return; // sanity-check + // threshold readings beyond our defined max, and within defined min + if (range == 255) return; // this is an invalid reading if (range > m_maxRange) range = m_maxRange; if (range < m_minRange) range = m_minRange; *************** *** 182,185 **** --- 276,280 ---- // are very small objects around. to alleviate this, clamp large // percent changes from the current average reading + /* int avgRange = m_rangeAvg[detectorNum]; int minFromAvg = avgRange - (int)(m_maxDelta * (float)avgRange); *************** *** 193,214 **** range = maxFromAvg; } ! if (m_printRange) Console.WriteLine(range); // for this detector range reading, keep a running average, in order // to smooth-out the jumpiness in the readings ! if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) ! { // manage circular buffer index ! m_rangeBufferPtr[detectorNum] = 0; } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) { ! sum += m_rangeBuffer[detectorNum][i]; } - m_rangeAvg[detectorNum] = sum / m_bufferSize; if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); - } catch (Exception e) --- 288,315 ---- range = maxFromAvg; } ! */ if (m_printRange) Console.WriteLine(range); // for this detector range reading, keep a running average, in order // to smooth-out the jumpiness in the readings ! if (m_bufferSize == 1) // no averaging ! { ! m_rangeAvg[detectorNum] = range; } ! else { ! if (++m_rangeBufferPtr[detectorNum] >= m_bufferSize) ! { // manage circular buffer index ! m_rangeBufferPtr[detectorNum] = 0; ! } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) ! { ! sum += m_rangeBuffer[detectorNum][i]; ! } ! m_rangeAvg[detectorNum] = sum / m_bufferSize; } if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); } catch (Exception e) *************** *** 259,268 **** (float)1 - ((float)m_rangeAvg[detector] / (float)m_maxRange); ! //Console.WriteLine(JellyApp.g_RibRangeDetect[i]); } } } - - m_dataLocked = false; } catch (Exception e) --- 360,367 ---- (float)1 - ((float)m_rangeAvg[detector] / (float)m_maxRange); ! //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); } } } } catch (Exception e) *************** *** 270,273 **** --- 369,374 ---- Console.WriteLine(e.ToString()); } + + m_dataLocked = false; } |
From: NickS <nsc...@us...> - 2008-08-21 03:47:00
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv4410 Modified Files: ProximityDetectors.cs Log Message: updates to use new Maxbotics controller, which controls four detectors Index: ProximityDetectors.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/ProximityDetectors.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ProximityDetectors.cs 17 Aug 2008 06:13:32 -0000 1.4 --- ProximityDetectors.cs 21 Aug 2008 03:46:55 -0000 1.5 *************** *** 3,6 **** --- 3,7 ---- using System.Text; using System.IO.Ports; + using System.Threading; namespace JellyBrain *************** *** 18,26 **** private const string m_SerialPortA_name = "COM6"; private const string m_SerialPortB_name = "COM7"; - private const string m_SerialPortC_name = "COM8"; - private const string m_SerialPortD_name = "COM9"; ! private const int m_numDetectors = 4; ! private const int m_bufferSize = 8; private const float m_maxDelta = 0.5f; --- 19,25 ---- private const string m_SerialPortA_name = "COM6"; private const string m_SerialPortB_name = "COM7"; ! private const int m_numDetectors = 8; ! private int m_bufferSize = 1; private const float m_maxDelta = 0.5f; *************** *** 35,43 **** // serial ports talk to either the Maxbotics controllers, ! // or to the devices themselves private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! private SerialPort m_SerialPortC = new System.IO.Ports.SerialPort(); ! private SerialPort m_SerialPortD = new System.IO.Ports.SerialPort(); // we need to associate a detector to X number of ribs --- 34,47 ---- // serial ports talk to either the Maxbotics controllers, ! // or to the devices themselves. ! // if talking to a controller (the default), then 1 port reads 4 devices (so 4 ports = 8 devices) ! // if talking directly to a device, then thats 2 ports = 2 devices private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! ! // each controller has a thread to write the sensor configuration string, and ! // send sensor read commands (polling) ! private Thread m_ThreadControllerA = null; ! private Thread m_ThreadControllerB = null; // we need to associate a detector to X number of ribs *************** *** 69,74 **** this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); ! this.InitSerialPort(m_SerialPortC, m_SerialPortC_name, DataReceivedPortC); ! this.InitSerialPort(m_SerialPortD, m_SerialPortD_name, DataReceivedPortD); } --- 73,84 ---- this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); ! ! //start the thread to send sensor report commands ! m_ThreadControllerA = new Thread(new ThreadStart(ThreadControllerA)); ! m_ThreadControllerA.Name = "ThreadControllerA"; ! m_ThreadControllerA.Start(); ! m_ThreadControllerB = new Thread(new ThreadStart(ThreadControllerB)); ! m_ThreadControllerB.Name = "ThreadControllerB"; ! m_ThreadControllerB.Start(); } *************** *** 83,87 **** port.StopBits = StopBits.One; port.Handshake = Handshake.None; ! port.NewLine = "\r"; port.DataReceived += --- 93,97 ---- port.StopBits = StopBits.One; port.Handshake = Handshake.None; ! port.NewLine = "\r\n"; port.DataReceived += *************** *** 103,121 **** // //////////////////////////////////////////////////////////////////////////////// ! void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortA, 'A'); } ! void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB, 'B'); } ! void DataReceivedPortC(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortC, 'C'); } ! void DataReceivedPortD(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortD, 'D'); } --- 113,173 ---- // //////////////////////////////////////////////////////////////////////////////// ! private void ThreadControllerA() { ! ThreadController(m_SerialPortA); } ! private void ThreadControllerB() { ! ThreadController(m_SerialPortB); } ! private const int m_sleepTimeMs = 125; ! private void ThreadController(SerialPort port) { ! try ! { ! // configure each sensor for polled mode ! port.WriteLine("$100001"); ! Thread.Sleep(1000); ! port.WriteLine("$100101"); ! Thread.Sleep(1000); ! port.WriteLine("$100201"); ! Thread.Sleep(1000); ! port.WriteLine("$100301"); ! Thread.Sleep(1000); ! //port.WriteLine("$FF"); ! //Thread.Sleep(4000); ! ! // send a query sensor commands, this will kick-off the reading chain, where ! // the DataReceived routine will send another one after processing this one ! // comment out if you only want the range-check reports (far less reports) ! while (true) ! { ! port.WriteLine("$2000"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2001"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2002"); ! Thread.Sleep(m_sleepTimeMs); ! port.WriteLine("$2003"); ! Thread.Sleep(m_sleepTimeMs); ! } ! } ! catch (Exception e) ! { ! //this is fatal! ! Console.WriteLine(e.ToString()); ! } ! } ! ! //////////////////////////////////////////////////////////////////////////////// ! // ! //////////////////////////////////////////////////////////////////////////////// ! void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) ! { ! DataReceived(m_SerialPortA, 'A'); } ! void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB, 'B'); } *************** *** 132,139 **** int detectorNum = -1; // the detector from which the reading was read // if the first char of the line of data received on the serial // port begins with 'R', then that means we are receiving data directly // from a detector ! if ((sData.Length == 4) && (caData[0] == 'R')) { char[] trimChars = { 'R' }; --- 184,243 ---- int detectorNum = -1; // the detector from which the reading was read + // CONTROLLER-DEVICE READ MODE: + // if the first char is a dollar-sign, then we are reading from the controller + if (caData[0] == '$') + { + //Console.WriteLine(caData); + int len = sData.Length; + + // check for sensor query report ($81) or sensor range change report ($91) + if ((len==7) && (((sData.Contains("$81")) || (sData.Contains("$91"))))) + { + char[] trimChars = { '$' }; + string sReport = sData.TrimStart(trimChars); + Int32 iReport = 0; + try + { + iReport = Int32.Parse(sReport,System.Globalization.NumberStyles.HexNumber); + } + catch + { + //Console.WriteLine(sRange); + return; // ignore crap reading + } + detectorNum = ((iReport & 0xFF00) >> 8); + int iDetNum = detectorNum; + if (portName == 'B') detectorNum += 4; // 4 detectors per controller + range = iReport & 0xFF; + //Console.WriteLine("detectorNum: " + detectorNum + ", range: " + range); + + // send a query sensor command + // comment out if you only want the range-check reports (far less reports) + // or if the polling thread is used + //string cmd = "$200" + iDetNum; ; + //if (portName == 'A') m_SerialPortA.WriteLine(cmd); + //else if (portName == 'B') m_SerialPortB.WriteLine(cmd); + } + else if ((len == 3) && (sData.Equals("$F0"))) + { + //Console.WriteLine("Controller command accepted on port " + portName); + return; + } + else if ((len == 3) && (sData.Equals("$F1"))) + { + Console.WriteLine("Controller command REJECTED on port " + portName); + return; + } + else if ((len == 13) && (sData.Equals("$900101010C10"))) + { + Console.WriteLine("Maxbotics controller v1.1.1 found on port " + portName); + return; + } + } + // DIRECT-DEVICE-READ MODE: // if the first char of the line of data received on the serial // port begins with 'R', then that means we are receiving data directly // from a detector ! else if ((sData.Length == 4) && (caData[0] == 'R')) { char[] trimChars = { 'R' }; *************** *** 142,146 **** { range = Int32.Parse(sRange); - if (range == 255) return; // this is an invalid reading } catch --- 246,249 ---- *************** *** 151,171 **** // figure-out which detector ! switch (portName) ! { ! case 'A': ! detectorNum = 0; ! break; ! case 'B': ! detectorNum = 1; ! break; ! case 'C': ! detectorNum = 2; ! break; ! case 'D': ! detectorNum = 3; ! break; ! default: ! return; ! } } else --- 254,261 ---- // figure-out which detector ! // note: in this code, we're talking directly to one device ! if (portName == 'A') detectorNum = 0; ! else if (portName == 'B') detectorNum = 1; ! else return; } else *************** *** 175,179 **** --- 265,273 ---- } + if (detectorNum == -1) return; // sanity-check + if (detectorNum >= m_numDetectors) return; // sanity-check + // threshold readings beyond our defined max, and within defined min + if (range == 255) return; // this is an invalid reading if (range > m_maxRange) range = m_maxRange; if (range < m_minRange) range = m_minRange; *************** *** 182,185 **** --- 276,280 ---- // are very small objects around. to alleviate this, clamp large // percent changes from the current average reading + /* int avgRange = m_rangeAvg[detectorNum]; int minFromAvg = avgRange - (int)(m_maxDelta * (float)avgRange); *************** *** 193,214 **** range = maxFromAvg; } ! if (m_printRange) Console.WriteLine(range); // for this detector range reading, keep a running average, in order // to smooth-out the jumpiness in the readings ! if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) ! { // manage circular buffer index ! m_rangeBufferPtr[detectorNum] = 0; } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) { ! sum += m_rangeBuffer[detectorNum][i]; } - m_rangeAvg[detectorNum] = sum / m_bufferSize; if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); - } catch (Exception e) --- 288,315 ---- range = maxFromAvg; } ! */ if (m_printRange) Console.WriteLine(range); // for this detector range reading, keep a running average, in order // to smooth-out the jumpiness in the readings ! if (m_bufferSize == 1) // no averaging ! { ! m_rangeAvg[detectorNum] = range; } ! else { ! if (++m_rangeBufferPtr[detectorNum] >= m_bufferSize) ! { // manage circular buffer index ! m_rangeBufferPtr[detectorNum] = 0; ! } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) ! { ! sum += m_rangeBuffer[detectorNum][i]; ! } ! m_rangeAvg[detectorNum] = sum / m_bufferSize; } if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); } catch (Exception e) *************** *** 263,268 **** } } - - m_dataLocked = false; } catch (Exception e) --- 364,367 ---- *************** *** 270,273 **** --- 369,374 ---- Console.WriteLine(e.ToString()); } + + m_dataLocked = false; } |
From: Jeremy <mh...@us...> - 2008-08-19 07:27:51
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv402 Added Files: RibProximityDetect.cs Log Message: --- NEW FILE: RibProximityDetect.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RibProximityDetect : Animation { public RibProximityDetect() { for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { JellyApp.g_RibRangeDetect[i] = 0; } m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "RibProximityDetect"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { if (JellyApp.g_RibRangeDetect[rib] == 0.0) continue; int maxRow = (int)(JellyApp.g_RibRangeDetect[rib] * JellyApp.g_iLightsPerRib); if (maxRow >= JellyApp.g_iLightsPerRib) continue; for (int row = 0; row <= maxRow; row++) { keyframe.m_Brightness[rib, row] = 1.0f; } } } } } |
From: Jeremy <mh...@us...> - 2008-08-19 07:24:30
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000 In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv31494 Added Files: MidiInterface.cs ProximityDetectors.cs Log Message: --- NEW FILE: MidiInterface.cs --- using System; using System.Runtime.InteropServices; namespace JellyTouch12000 { //////////////////////////////////////////////////////////////////////////////// // MIDI interface to the RedSound Voyager 1 Beat Xtractor //////////////////////////////////////////////////////////////////////////////// /* * Midi code borrowed heavily from the CSharpMidiToolkitV5_demo by Leslie Sanford * Web: http://www.codeproject.com/KB/audio-video/MIDIToolkit.aspx * Email: jab...@ho... */ public class MidiInterface { /// Represents MIDI input device capabilities. [StructLayout(LayoutKind.Sequential)] public struct MidiInCaps { #region MidiInCaps Members /// <summary> /// Manufacturer identifier of the device driver for the Midi output /// device. /// </summary> public short mid; /// <summary> /// Product identifier of the Midi output device. /// </summary> public short pid; /// <summary> /// Version number of the device driver for the Midi output device. The /// high-order byte is the major version number, and the low-order byte /// is the minor version number. /// </summary> public int driverVersion; /// <summary> /// Product name. /// </summary> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string name; /// <summary> /// Optional functionality supported by the device. /// </summary> public int support; #endregion } // Represents the method that handles messages from Windows. private delegate void MidiInProc(int handle, int msg, int instance, int param1, int param2); #region Win32 MIDI Input Functions and Constants [DllImport("winmm.dll")] private static extern int midiInOpen(ref int handle, int deviceID, MidiInProc proc, int instance, int flags); [DllImport("winmm.dll")] private static extern int midiInClose(int handle); [DllImport("winmm.dll")] private static extern int midiInStart(int handle); [DllImport("winmm.dll")] private static extern int midiInStop(int handle); [DllImport("winmm.dll")] private static extern int midiInReset(int handle); [DllImport("winmm.dll")] private static extern int midiInPrepareHeader(int handle, IntPtr headerPtr, int sizeOfMidiHeader); [DllImport("winmm.dll")] private static extern int midiInUnprepareHeader(int handle, IntPtr headerPtr, int sizeOfMidiHeader); [DllImport("winmm.dll")] private static extern int midiInAddBuffer(int handle, IntPtr headerPtr, int sizeOfMidiHeader); [DllImport("winmm.dll")] private static extern int midiInGetDevCaps(int deviceID, ref MidiInCaps caps, int sizeOfMidiInCaps); [DllImport("winmm.dll")] private static extern int midiInGetNumDevs(); private const int MIDI_IO_STATUS = 0x00000020; private const int MIM_OPEN = 0x3C1; // 961 private const int MIM_CLOSE = 0x3C2; // 962 private const int MIM_DATA = 0x3C3; // 963 private const int MIM_LONGDATA = 0x3C4; // 964 private const int MIM_ERROR = 0x3C5; // 965 private const int MIM_LONGERROR = 0x3C6;// 966 private const int MIM_MOREDATA = 0x3CC; private const int MHDR_DONE = 0x00000001; private const int MMSYSERR_ALLOCATED = 4; private const int MMSYSERR_BADDB = 14; private const int MMSYSERR_BADDEVICEID = 2; private const int MMSYSERR_BADERRNUM = 9; private const int MMSYSERR_DELETEERROR = 18; private const int MMSYSERR_ERROR = 1; private const int MMSYSERR_HANDLEBUSY = 12; private const int MMSYSERR_INVALFLAG = 10; private const int MMSYSERR_INVALHANDLE = 5; private const int MMSYSERR_INVALIDALIAS = 13; private const int MMSYSERR_INVALPARAM = 11; private const int MMSYSERR_KEYNOTFOUND = 15; private const int MMSYSERR_LASTERROR = 20; private const int MMSYSERR_NODRIVER = 6; private const int MMSYSERR_NODRIVERCB = 20; private const int MMSYSERR_NOERROR = 0; private const int MMSYSERR_NOMEM = 7; private const int MMSYSERR_NOTENABLED = 3; private const int MMSYSERR_NOTSUPPORTED = 8; private const int MMSYSERR_READERROR = 16; private const int MMSYSERR_VALNOTFOUND = 19; private const int MMSYSERR_WRITEERROR = 17; private const int CALLBACK_FUNCTION = 196608; private const int MIDI_CLK_TICK = 0xf8; private const int MIDI_CLK_START = 0xfa; private const int MIDI_CLK_CONTINUE = 0xfb; private const int MIDI_CLK_STOP = 0xfc; #endregion /// <summary> /// Interface to the Beat Xtractor starts here /// MidiCallback is called by the lowe-level Windows midi driver on each midi message /// </summary> private MidiInProc _midiInProc; private int _midiBeatXtractor; private const short USB_UNO_MIDI_IN_DEVID = 2637; private int _midiSyncCodeCounter = 0; //private int _midiLastTimecode; //private int _midiBPM; private bool _midiJellyBeat = false; private void MidiCallback(int handle, int msg, int instance, int param1, int param2) { if (msg == MIM_DATA) { if (param1 == MIDI_CLK_TICK) { if (++_midiSyncCodeCounter >= 24) //24 sync codes per quarter note (a beat) { if (_midiJellyBeat) JellyApp.g_Beat = true; // cause JellyBrain to react to beat _midiSyncCodeCounter = 0; //int _midiTimecodeDelta = param2 - _midiLastTimecode; //_midiLastTimecode = param2; //_midiBPM = (int)(60000 * (double)(1 / (double)_midiTimecodeDelta)); } } else if (param1 == MIDI_CLK_START) { _midiJellyBeat = true; } else if (param1 == MIDI_CLK_CONTINUE) { _midiJellyBeat = true; } else if (param1 == MIDI_CLK_STOP) { _midiJellyBeat = false; } } } public void MidiOpen() { // setup midi-in monitor of the Voyager Beat Xtractor (see MidiCallback above) int numMidiDevs = midiInGetNumDevs(); if (numMidiDevs > 0) { for (int devNum = 0; devNum < numMidiDevs; devNum++) { // get info on this device to make sure its the BeatXtractor USB interface MidiInCaps midiInCaps = new MidiInCaps(); int mmResult = midiInGetDevCaps ( devNum, ref midiInCaps, Marshal.SizeOf(typeof(MidiInCaps)) ); if (mmResult == MMSYSERR_NOERROR) { /* Open the MIDI-In device if the known midi-to-USB device is detected */ if (midiInCaps.mid == USB_UNO_MIDI_IN_DEVID) { _midiInProc = MidiCallback; mmResult = midiInOpen (ref _midiBeatXtractor, devNum, _midiInProc, 0, CALLBACK_FUNCTION); if (mmResult == MMSYSERR_NOERROR) { mmResult = midiInStart(_midiBeatXtractor); if (mmResult == MMSYSERR_NOERROR) { System.Console.WriteLine("Successfully opened and started MIDI-In interface."); } } } } } } } } } --- NEW FILE: ProximityDetectors.cs --- using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; namespace JellyTouch12000 { public class ProximityDetectors { /* configurables: * - com port numbers, * - number of sonar detectors, * - number of range-readings to keep in a buffer for averaging (to smooth) * - max percent change that is allowed from reading to reading (clamped) * - max range reading, in inches, beyond which readings should be ignored * - min range reading, in inches, within which we consider maximally close */ private const string m_SerialPortA_name = "COM6"; private const string m_SerialPortB_name = "COM7"; private const string m_SerialPortC_name = "COM8"; private const string m_SerialPortD_name = "COM9"; private const int m_numDetectors = 4; private const int m_bufferSize = 8; private const float m_maxDelta = 0.5f; private const Int32 m_maxRange = 96; // inches private const Int32 m_minRange = 30; // inches private bool m_printRawData = false; private bool m_printRange = false; private bool m_printAvgRange = false; // serial ports talk to either the Maxbotics controllers, // or to the devices themselves private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortC = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortD = new System.IO.Ports.SerialPort(); // we need to associate a detector to X number of ribs private int m_ribsPerDetector = JellyApp.g_iTotalRibs / m_numDetectors; // buffer range-readings and average, to smooth jumpiness private Int32[][] m_rangeBuffer = new Int32[m_numDetectors][]; private Int32[] m_rangeBufferPtr = new Int32[m_numDetectors]; private Int32[] m_rangeAvg = new Int32[m_numDetectors]; // simple data protection of JellyBrain global rib detect values private bool m_dataLocked = false; //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Init() { for (int detector = 0; detector < m_numDetectors; detector++) { m_rangeBuffer[detector] = new Int32[m_bufferSize]; for (int i = 0; i < m_bufferSize; i++) { m_rangeBuffer[detector][i] = m_maxRange; } m_rangeBufferPtr[detector] = 0; m_rangeAvg[detector] = m_maxRange; } this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); this.InitSerialPort(m_SerialPortC, m_SerialPortC_name, DataReceivedPortC); this.InitSerialPort(m_SerialPortD, m_SerialPortD_name, DataReceivedPortD); } private void InitSerialPort(SerialPort port, string portName, SerialDataReceivedEventHandler handler) { port.PortName = portName; port.BaudRate = 9600; port.DataBits = 8; port.Parity = Parity.None; port.StopBits = StopBits.One; port.Handshake = Handshake.None; port.NewLine = "\r"; port.DataReceived += new SerialDataReceivedEventHandler(handler); try { port.Open(); Console.Write("Successfully opened "); Console.WriteLine(portName); } catch (Exception e) { Console.WriteLine(e.ToString()); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { DataReceived(m_SerialPortA, 'A'); } void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { DataReceived(m_SerialPortB, 'B'); } void DataReceivedPortC(object sender, SerialDataReceivedEventArgs e) { DataReceived(m_SerialPortC, 'C'); } void DataReceivedPortD(object sender, SerialDataReceivedEventArgs e) { DataReceived(m_SerialPortD, 'D'); } void DataReceived(SerialPort port, char portName) { try { //read a newline-terminated string of data waiting in the device buffer string sData = port.ReadLine(); char[] caData = sData.ToCharArray(); if (m_printRawData) Console.WriteLine(sData); Int32 range = -1; // the range-reading, in inches, read from a detector int detectorNum = -1; // the detector from which the reading was read // if the first char of the line of data received on the serial // port begins with 'R', then that means we are receiving data directly // from a detector if ((sData.Length == 4) && (caData[0] == 'R')) { char[] trimChars = { 'R' }; string sRange = sData.TrimStart(trimChars); try { range = Int32.Parse(sRange); if (range == 255) return; // this is an invalid reading } catch { //Console.WriteLine(sRange); return; // ignore crap reading } // figure-out which detector switch (portName) { case 'A': detectorNum = 0; break; case 'B': detectorNum = 1; break; case 'C': detectorNum = 2; break; case 'D': detectorNum = 3; break; default: return; } } else { Console.WriteLine(sData); return; } // threshold readings beyond our defined max, and within defined min if (range > m_maxRange) range = m_maxRange; if (range < m_minRange) range = m_minRange; // readings can fluctuate wilding from reading to reading if there // are very small objects around. to alleviate this, clamp large // percent changes from the current average reading int avgRange = m_rangeAvg[detectorNum]; int minFromAvg = avgRange - (int)(m_maxDelta * (float)avgRange); if (range < minFromAvg) { range = minFromAvg; } int maxFromAvg = (int)(m_maxDelta * (float)avgRange) + avgRange; if (range > maxFromAvg) { range = maxFromAvg; } if (m_printRange) Console.WriteLine(range); // for this detector range reading, keep a running average, in order // to smooth-out the jumpiness in the readings if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) { // manage circular buffer index m_rangeBufferPtr[detectorNum] = 0; } m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; Int32 sum = 0; for (int i = 0; i < m_bufferSize; i++) { sum += m_rangeBuffer[detectorNum][i]; } m_rangeAvg[detectorNum] = sum / m_bufferSize; if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); } catch (Exception e) { Console.WriteLine(e.ToString()); } // now update the rib lighting based on the detector values // use a simple synchronization lock, since this DataReceived routine // can be executed concurrently by multiple ports if ( ! m_dataLocked) this.UpdateRibRangeDetectValues(); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void UpdateRibRangeDetectValues() { try { m_dataLocked = true; // simple data protection of JellyBrain global // update the JellyBrain rib proximity detect values with // a value ranging from 0 to 1, where 0 is infinitely // far away, and 1 is as near as possible to the rib (detector) // start by setting clearing all values for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { JellyApp.g_RibRangeDetect[i] = 0; } for (int detector = 0; detector < m_numDetectors; detector++) { int startRib = detector * m_ribsPerDetector; int endRib = startRib + m_ribsPerDetector; for (int i = startRib; i < endRib; i++) { // if range-reading is within our defined min zone, // then consider it a maximal reading if (m_rangeAvg[detector] <= m_minRange) { JellyApp.g_RibRangeDetect[i] = (float)0.99; } else // scale 0 to 1, using maxRange as a threshold { JellyApp.g_RibRangeDetect[i] = (float)1 - ((float)m_rangeAvg[detector] / (float)m_maxRange); //Console.WriteLine(JellyApp.g_RibRangeDetect[i]); } } } m_dataLocked = false; } catch (Exception e) { Console.WriteLine(e.ToString()); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Close() { m_SerialPortA.Close(); m_SerialPortB.Close(); } } } |
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/bin/x86/Release In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/bin/x86/Release Added Files: Interop.Excel.dll Interop.Microsoft.Office.Core.dll Interop.VBIDE.dll led_array_05.xls test.tga Log Message: JellyTouch first commit. --- NEW FILE: test.tga --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.Microsoft.Office.Core.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: led_array_05.xls --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.VBIDE.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.Excel.dll --- (This appears to be a binary file; contents omitted.) |
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/bin/x86/Debug In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/bin/x86/Debug Added Files: Interop.Excel.dll Interop.Microsoft.Office.Core.dll Interop.VBIDE.dll led_array_05.xls test.tga Log Message: JellyTouch first commit. --- NEW FILE: test.tga --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.Microsoft.Office.Core.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: led_array_05.xls --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.VBIDE.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Interop.Excel.dll --- (This appears to be a binary file; contents omitted.) |
From: Jeremy <mh...@us...> - 2008-08-19 07:08:38
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Content In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/Content Added Files: Background.fx Content.contentproj DebugFont.spritefont Log Message: JellyTouch first commit. --- NEW FILE: DebugFont.spritefont --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Content.contentproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Background.fx --- float4x4 WorldViewProj; float2 vScroll; Texture texture0; sampler textureSampler = sampler_state { Texture = <texture0>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; struct VertexShaderInput { float4 Position : POSITION0; float2 TexCoord0 : TEXCOORD0; }; struct VertexShaderOutput { float4 Position : POSITION0; float2 TexCoord0 : TEXCOORD0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; output.Position = mul(input.Position, WorldViewProj); //use an effect param to scroll these bad boys //output.TexCoord0.x = input.TexCoord0.x + fScroll.x; //output.TexCoord0.y = input.TexCoord0.y + fScroll.y; output.TexCoord0 = input.TexCoord0 + vScroll; return output; } float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 { return tex2D(textureSampler, input.TexCoord0); } technique Technique1 { pass Pass1 { AlphaBlendEnable = TRUE; SrcBlend = SrcAlpha; DestBlend = InvSrcAlpha; //FillMode = SOLID; CullMode = NONE; VertexShader = compile vs_1_1 VertexShaderFunction(); PixelShader = compile ps_1_1 PixelShaderFunction(); } } |
From: Jeremy <mh...@us...> - 2008-08-19 07:08:38
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Transitions In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/Transitions Added Files: BrightnessBlend.cs InterruptedBroadcast.cs RandomDissolve.cs RowReveal.cs Log Message: JellyTouch first commit. --- NEW FILE: BrightnessBlend.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Transitions { class BrightnessBlend : Transition { float m_currentPercentAnimationA = 0.5f; override public string GetTransitionName() { return "BrightnessBlend"; } public override void Reset() { } override public void Update() { // let's start out by letting both of our animations animate base.UpdateAnimations(); // this transition does make use of brightness, so we should set the // target frame to be the max of the two animations // TODO kellyp -- should i cap this to some value where brightness looks // good? we might want to blend 2 fast animations which // are both set to 1 m_SubFramesPerKeyFrame = Math.Max(m_animA.GetSubFramesPerKeyFrame(), m_animB.GetSubFramesPerKeyFrame()); m_targetKey.m_TotalSubFrames = m_SubFramesPerKeyFrame; float timePercent = (float)m_stopwatch.GetElapsedTimeSecs() / m_durationSeconds; m_currentPercentAnimationA = timePercent; // now let's get both of the keyframes and blend them into our target // add up both brightness values for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { float aBrightness = (m_animA.KeyFrame.m_Brightness[i, j] * m_currentPercentAnimationA); float bBrightness = (m_animB.KeyFrame.m_Brightness[i, j] * (1.0f - m_currentPercentAnimationA)); m_targetKey.m_Brightness[i, j] = aBrightness + bBrightness; } } } } } --- NEW FILE: InterruptedBroadcast.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Transitions { class InterruptedBroadcast : Transition { Random m_random = new Random(Environment.TickCount); override public string GetTransitionName() { return "InterruptedBroadcast"; } override public void Reset() { } override public void Update() { // TODO kellyp -- later we should not have a manual call // to update the animations here... we should evaluate this like an expression tree base.UpdateAnimations(); float timePercent = (float)m_stopwatch.GetElapsedTimeSecs() / m_durationSeconds; int iTimePercent = (int)(timePercent * 100.0f); int randomPercent = m_random.Next(0, 99); for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { // let's shake the dice and see what chance we have of playing A or B if (randomPercent < iTimePercent) { m_targetKey.m_Brightness[i, j] = m_animB.KeyFrame.m_Brightness[i, j]; } else { m_targetKey.m_Brightness[i, j] = m_animA.KeyFrame.m_Brightness[i, j]; } } } } } } --- NEW FILE: RowReveal.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Transitions { class RowReveal : Transition { override public string GetTransitionName() { return "RowReveal"; } override public void Reset() { } override public void Update() { // TODO kellyp -- later we should not have a manual call // to update the animations here... we should evaluate this like an expression tree base.UpdateAnimations(); float timePercent = (float)m_stopwatch.GetElapsedTimeSecs() / m_durationSeconds; // let's start from the bottom (0 based is the top of the dome) int currentRow = JellyApp.g_iLightsPerRib - (int)(timePercent * JellyApp.g_iLightsPerRib); for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { if (j >= currentRow) { m_targetKey.m_Brightness[i, j] = m_animB.KeyFrame.m_Brightness[i, j]; } else { m_targetKey.m_Brightness[i, j] = m_animA.KeyFrame.m_Brightness[i, j]; } } } } } } --- NEW FILE: RandomDissolve.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Transitions { class RandomDissolve : Transition { // we use this to keep track of the pixels underneath we have already exposed... KeyFrame m_dissolveMask = new KeyFrame(); Random m_random = new Random(Environment.TickCount); int m_pixelsRevealed = 0; override public string GetTransitionName() { return "RandomDissolve"; } override public void Reset() { m_pixelsRevealed = 0; m_dissolveMask.SetBrightness(0.0f); } override public void Update() { // TODO kellyp -- later we should not have a manual call // to update the animations here... we should evaluate this like an expression tree base.UpdateAnimations(); // let's figure out how many pixels to reveal this frame float timePercent = (float)m_stopwatch.GetElapsedTimeSecs() / m_durationSeconds; float totalPixels = JellyApp.g_iLightsPerRib * JellyApp.g_iTotalRibs; int totalExpectedRevealed = (int)(totalPixels * timePercent); int totalThisFrame = totalExpectedRevealed - m_pixelsRevealed; while(totalThisFrame > 0) { if(timePercent > 0.95f) { FillInMaskLinear(); } else { bool success = FillInMaskRandom(3); if(!success) { FillInMaskLinear(); } } m_pixelsRevealed++; totalThisFrame--; } // now let's go through our mask and decide which pixels should show animA // and which should show animB // go through linearly until we find a pixel which hasn't been lit up yet for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { if (m_dissolveMask.m_Brightness[i, j] > 0.0f) { m_targetKey.m_Brightness[i, j] = m_animB.KeyFrame.m_Brightness[i, j]; } else { m_targetKey.m_Brightness[i, j] = m_animA.KeyFrame.m_Brightness[i, j]; } } } } void FillInMaskLinear() { // go through linearly until we find a pixel which hasn't been lit up yet for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { if (m_dissolveMask.m_Brightness[i, j] < 1.0f) { m_dissolveMask.m_Brightness[i, j] = 1.0f; return; } } } } bool FillInMaskRandom(int retryAttempts) { while(retryAttempts > 0) { int randomRib = m_random.Next(0, JellyApp.g_iTotalRibs); int randomRow = m_random.Next(0, JellyApp.g_iLightsPerRib); if (m_dissolveMask.m_Brightness[randomRib, randomRow] < 1.0f) { m_dissolveMask.m_Brightness[randomRib, randomRow] = 1.0f; return true; } retryAttempts--; } // we failed our retries return false; } } } |
From: Jeremy <mh...@us...> - 2008-08-19 07:08:38
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Properties In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/Properties Added Files: AssemblyInfo.cs Log Message: JellyTouch first commit. --- NEW FILE: AssemblyInfo.cs --- (This appears to be a binary file; contents omitted.) |
From: Jeremy <mh...@us...> - 2008-08-19 07:08:38
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Animations/Algorithms In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/Animations/Algorithms Added Files: GameOfLife.cs Perlin.cs Log Message: JellyTouch first commit. --- NEW FILE: GameOfLife.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations.Algorithms { // Cartesian point class public class Point { public int x; public int y; public Point(int x, int y) { this.x = x; this.y = y; } } public class GameOfLife { // RULES: // birth: 3 neighbors // survive: 2 or 3 neighbors private List<int> _birth_pals = new List<int>(new int[] { 3 }); private List<int> _survive_pals = new List<int>(new int[] { 2, 3 }); private int _grid_width; private int _grid_height; private int _life_span; // # of generations that a cell can age private int _cur_generation; // # of total generations that have passed private int[,] _gridcur; private int[,] _gridnxt; private int[,] _gridswap; #region Accessors public int GridWidth { get { return _grid_width; } } public int GridHeight { get { return _grid_height; } } public int[,] GameGrid { get { return _gridcur; } } public int LifeSpan { get { return _life_span; } set { _life_span = LifeSpan; } } public int CurGeneration { get { return _cur_generation; } } #endregion #region ctor public GameOfLife(int grid_width, int grid_height, int life_span) { _grid_width = grid_width; _grid_height = grid_height; _life_span = life_span; _cur_generation = 0; _gridcur = new int[_grid_width, _grid_height]; _gridnxt = new int[_grid_width, _grid_height]; ZeroGrids(); } #endregion #region Init Grid // Init grids to zeroes private void ZeroGrids() { // columns for (int x = 0; x < _grid_width; x++) { // rows for (int y = 0; y < _grid_height; y++) { _gridcur[x, y] = 0; _gridnxt[x, y] = 0; } } } // Init specified grid to zeroes private void ZeroGrid(int[,] grid) { // columns for (int x = 0; x < _grid_width; x++) { // rows for (int y = 0; y < _grid_height; y++) { grid[x, y] = 0; } } } #endregion #region Load Grid // Load pattern into grid public string LoadPattern(List<Point> pat) { return LoadPattern(pat, 0, 0, false); } // Load pattern into grid, clear grid if flag is asserted public string LoadPattern(List<Point> pat, bool clear_grid) { return LoadPattern(pat, 0, 0, clear_grid); } // Load pattern into grid, bottom justify if flag is asserted, pad w/ specified amount public string LoadPattern(List<Point> pat, bool bottom_justify, int bottom_pad) { int dy = bottom_justify ? (_grid_height - bottom_pad) : 0; return LoadPattern(pat, 0, dy, false); } // Load pattern into grid, translate points prior to loading, clear grid if flag is asserted public string LoadPattern(List<Point> pat, int dx, int dy, bool clear_grid) { string error = null; try { if (clear_grid) ZeroGrid(_gridcur); foreach (Point p in pat) { int newx = p.x + dx; int newy = p.y + dy; WrapLoc(ref newx, ref newy); _gridcur[newx, newy] = 1; } } catch (Exception ex) { error = ex.ToString(); } return error; } #endregion #region Translate Grid // Translate points currently in grid public string TranslateGrid(int dx, int dy) { string error = null; try { for (int x = 0; x < _grid_width; x++) { for (int y = 0; y < _grid_height; y++) { int newx = x + dx; int newy = y + dy; WrapLoc(ref newx, ref newy); _gridnxt[newx, newy] = _gridcur[x, y]; } } _gridswap = _gridcur; _gridcur = _gridnxt; _gridnxt = _gridswap; //ZeroGrid(_gridnxt); } catch (Exception ex) { error = ex.ToString(); } return error; } #endregion #region Play Game // Play single GOL generation public string PlayGeneration() { string error = null; _cur_generation++; try { for (int x = 0; x < _grid_width; x++) { for (int y = 0; y < _grid_height; y++) { // Pals will return between 0 and 8 (* := candidates, t := target) // * * * // * t * // * * * int pals = TallyPals(x, y); // if alive if (_gridcur[x, y] == 1) { // if pal count is not in _survive_pals rule set if (!_survive_pals.Contains(pals)) { // age++ if (_gridcur[x, y] < _life_span) _gridnxt[x, y] = _gridcur[x, y] + 1; // old people die... else _gridnxt[x, y] = 0; } // else survive else _gridnxt[x, y] = 1; } // else if in age decay else if (_gridcur[x, y] > 1) { // if pal count is in _birth_pals rule set, be reborn!! if (_birth_pals.Contains(pals)) _gridnxt[x, y] = 1; else { // age++ if (_gridcur[x, y] < _life_span) _gridnxt[x, y] = _gridcur[x, y] + 1; // old people die... else _gridnxt[x, y] = 0; } } // else dead else { // if pal count is in _birth_pals rule set, live my pet, live!! if (_birth_pals.Contains(pals)) _gridnxt[x, y] = 1; else _gridnxt[x, y] = 0; } } } _gridswap = _gridcur; _gridcur = _gridnxt; _gridnxt = _gridswap; //ZeroGrid(_gridnxt); } catch (Exception ex) { error = ex.ToString(); } return error; } #endregion #region Utils // Count up # of cells alive in the target cell's Moore neighborhood private int TallyPals(int x, int y) { int pals = 0; // Tally which neighbors are alive // * * * // * t * // * * * pals = CheckPal(x - 1, y - 1) + //NW CheckPal(x, y - 1) + //N CheckPal(x + 1, y - 1) + //NE CheckPal(x - 1, y) + //W CheckPal(x + 1, y) + //E CheckPal(x - 1, y + 1) + //SW CheckPal(x, y + 1) + //S CheckPal(x + 1, y + 1); //SE return pals; } // Check for pal alive at given coordinates (wrap coordinate if out of bounds) // Return 1 if alive, 0 for dead & aging cells private int CheckPal(int x, int y) { WrapLoc(ref x, ref y); return _gridcur[x, y] == 1 ? 1 : 0; } // Wrap given x & y coordinates if necessary private void WrapLoc(ref int x, ref int y) { if (x <= -1) x = _grid_width - 1; else if (x >= _grid_width) x = 0; if (y <= -1) y = _grid_height - 1; else if (y >= _grid_height) y = 0; } #endregion } } --- NEW FILE: Perlin.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations.Algorithms { class Perlin { Random r = new Random(); int r1 = 0; int r2 = 0; int r3 = 0; public double octaves = 8; // USER ADJUSTABLE public double persistence = .65; // USER ADJUSTABLE public double coverage = 0; // USER ADJUSTABLE public double density = 1; // USER ADJUSTABLE public double initialFrequency = .015; // USER ADJUSTABLE public double initialAmplitude = 1; // USER ADJUSTABLE public Perlin() { r1 = r.Next(1000, 10000); r2 = r.Next(100000, 1000000); r3 = r.Next(1000000000, 2000000000); } public double PerlinNoise2d(int x, int y) { double total = 0.0f; double amplitude = initialAmplitude; double frequency = initialFrequency; for (int lcv = 0; lcv < octaves; lcv++) { total = total + Smooth(x * frequency, y * frequency) * amplitude; frequency = frequency * 2; amplitude = amplitude * persistence; } total = (total + coverage) * density; return total; } double Smooth(double x, double y) { double n1 = Noise((int)x, (int)y); double n2 = Noise((int)x + 1, (int)y); double n3 = Noise((int)x, (int)y + 1); double n4 = Noise((int)x + 1, (int)y + 1); double i1 = Interpolate(n1, n2, x - (int)x); double i2 = Interpolate(n3, n4, x - (int)x); return Interpolate(i1, i2, y - (int)y); } double Noise(int x, int y) { int n = x + y * 57; n = (n << 13) ^ n; return (1.0 - ((n * (n * n * r1 + r2) + r3) & 0x7fffffff) / 1073741824.0); } double Interpolate(double x, double y, double a) { double val = (1 - Math.Cos(a * Math.PI)) * .5; return x * (1 - val) + y * val; } } } |
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954/Animations Added Files: AccidentalSpiral.cs AllOff.cs AllOn.cs BouncingRings.cs Growie.cs GrowieCC.cs GrowieCS.cs Hypocycloid.cs JixelColorCycle.cs JixelColorCycleFade.cs JixelColorCycle_02.cs LifeAcorn.cs LifeBaseAnimation.cs LifeDiehard.cs LifeFlapper.cs LifeOscillatorP8.cs LifePufferP16C2.cs LifeSpaceShips.cs LifeSpaceShips_02.cs Lissajous.cs OneColor.cs PerlinNoise.cs Phyllotaxy.cs PolarRose.cs RibColorCycle.cs RibColorCycleFade.cs RibColorCycleFade_02.cs RibColorCycleFade_03.cs RibTrails.cs RowColorCycleFade.cs RowCycle.cs SevenBandFreqShow.cs SexWorms.cs SpectrumColors.cs SpectrumDiscs.cs SpectrumJixels.cs SpectrumRadar.cs SpectrumRadar_02.cs SpinningRows.cs SpinningSpectrum.cs Spiral.cs StraightSine.cs StraightSine_02.cs StraightSine_03.cs Whitney.cs Worms.cs Log Message: JellyTouch first commit. --- NEW FILE: GrowieCC.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { public class GrowieCC : Animation { public override string GetAnimationName() { return "GrowieCC"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int jixelrow = 0; jixelrow < JellyApp.g_iLightsPerRib; jixelrow++) { float ribvalue = (float)rib + 1.0f; float rowvalue = (float)jixelrow + 1.0f; LED led = LEDInfo.GetLED(rib, jixelrow); // use this one to get the true X,Y coordinates(when the spreadsheet is loaded) //float brightness = (float)(Math.Sin(delta * led.X * led.Y)); // this one just uses the index, not the position! float brightness = (float)(Math.Sin(m_Delta * ribvalue * rowvalue)); // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 brightness += 1.0f; brightness /= 2.0f; // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, jixelrow] = JellyApp.ClampBrightness(brightness); } } m_Delta += 0.2f; } public float m_Delta = 0.0f; } } --- NEW FILE: LifeSpaceShips.cs --- using System; using System.Collections.Generic; using System.Text; using JellyTouch12000.Animations.Algorithms; namespace JellyTouch12000.Animations { public class LifeSpaceShips : LifeBaseAnimation { #region ctor public LifeSpaceShips() : base() { InitAnimation(); } public LifeSpaceShips(int life_span, bool jixel_precision) : base(life_span, jixel_precision) { InitAnimation(); } // Setup Animation private void InitAnimation() { _name = "LifeSpaceShips"; #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(16, 0), new Point(17, 0), new Point(13, 1), new Point(16, 1), new Point(17, 1), new Point(18, 1), new Point(14, 2), new Point(15, 2), new Point(16, 2), new Point(17, 2), new Point(14, 4), new Point(12, 5), new Point(13, 5), new Point(14, 5), new Point(12, 6), new Point(15, 6), new Point(16, 8), new Point(17, 8), new Point(14, 9), new Point(17, 9), new Point(12, 10), new Point(17, 10), new Point(18, 10), new Point(13, 11), new Point(15, 11), new Point(17, 11), new Point(12, 12), new Point(13, 12), new Point(15, 13), new Point(16, 13), new Point(16, 14), new Point(14, 15), new Point(12, 16), new Point(13, 16), new Point(15, 16), new Point(16, 16), new Point(13, 17), new Point(14, 17), new Point(15, 17), new Point(13, 18), new Point(14, 18), new Point(13, 19), new Point(12, 20), new Point(13, 20), new Point(14, 20), new Point(14, 22), new Point(8, 23), new Point(9, 23), new Point(14, 23), new Point(17, 23), new Point(6, 24), new Point(12, 24), new Point(13, 24), new Point(16, 24), new Point(17, 24), new Point(5, 25), new Point(10, 25), new Point(17, 25), new Point(0, 26), new Point(5, 26), new Point(7, 26), new Point(8, 26), new Point(9, 26), new Point(10, 26), new Point(0, 27), new Point(2, 27), new Point(4, 27), new Point(5, 27), new Point(6, 27), new Point(0, 28), new Point(2, 28) }); if (_jixel_precision) _gol.LoadPattern(_pattern); else _gol.LoadPattern(_pattern, 0, 30, false); _pattern = new List<Point>(new Point[] { new Point(1, 0), new Point(2, 0), new Point(3, 0), new Point(0, 1), new Point(4, 1), new Point(5, 1), new Point(7, 2), new Point(0, 3), new Point(4, 3), new Point(8, 3), new Point(9, 3), new Point(0, 4), new Point(4, 4), new Point(7, 4), new Point(4, 5), new Point(5, 5), new Point(0, 6), new Point(4, 6), new Point(0, 7), new Point(4, 7), new Point(2, 8), new Point(3, 8), new Point(4, 8), new Point(2, 10), new Point(3, 10), new Point(4, 10), new Point(0, 11), new Point(4, 11), new Point(0, 12), new Point(4, 12), new Point(4, 13), new Point(5, 13), new Point(0, 14), new Point(4, 14), new Point(7, 14), new Point(0, 15), new Point(4, 15), new Point(8, 15), new Point(9, 15), new Point(7, 16), new Point(0, 17), new Point(4, 17), new Point(5, 17), new Point(1, 18), new Point(2, 18), new Point(3, 18) }); if (_jixel_precision) _gol.LoadPattern(_pattern); else _gol.LoadPattern(_pattern, 0, 30, false); #endregion } #endregion public override void UpdateKeyFrame(KeyFrame keyframe) { base.UpdateKeyFrame(keyframe); } } } --- NEW FILE: SpectrumRadar.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SpectrumRadar : Animation { KeyFrame m_previousKeyFrame = null; int m_radarRibIndex = 0; float m_brightnessDecay = 0.93f; public override string GetAnimationName() { return "SpectrumRadar"; } public SpectrumRadar() { // reset the peak detectors JellyApp.g_SevenBandSpectrumPeak = 0; m_SubFramesPerKeyFrame = 5; } override public void UpdateKeyFrame(KeyFrame keyframe) { // get 7 bands of spectrum data int[] spectrum = JellyApp.g_SevenBandSpectrum; float peak = JellyApp.g_SevenBandSpectrumPeak; float currentSpectrumMax = -1.0f; for (int i = 0; i < spectrum.Length; i++) { if (spectrum[i] > currentSpectrumMax) { currentSpectrumMax = spectrum[i]; } } // first let's start with the data we had from the previous frame if (m_previousKeyFrame != null) { // copy the brightness data from the previous frame for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { // we get teh previous values , but decay them slightly keyframe.m_Brightness[i,j] = (m_previousKeyFrame.m_Brightness[i, j] * m_brightnessDecay); } } } // and let's clear out the rib that the radar is currently on Rib radarRib = keyframe.GetRib(m_radarRibIndex); radarRib.SetBrightness(0.0f); // and now do a trail based on the peak //int height = (int)((currentSpectrumMax / peak) * JellyApp.g_iLightsPerRib); //height %= JellyApp.g_iLightsPerRib; //radarRib.TrailEffect(0, height, Rib.RibDirection.UP); // draw a trail for each spectrum with a different color for (int i = 0; i < spectrum.Length; i++) { // here let's decide if we want to use the max spectrum value of this frame, //or if we want to use the overall peak float spectrumMax = currentSpectrumMax; if (!JellyApp.g_NormalizeSpectrumDataEachKeyFrame) { spectrumMax = peak; } int height = (int)((spectrum[i] / spectrumMax) * JellyApp.g_iLightsPerRib); height %= JellyApp.g_iLightsPerRib; JixelColor color = (JixelColor)i; radarRib.TrailEffect(0, height, Rib.RibDirection.UP, color, false); } m_radarRibIndex++; m_radarRibIndex %= JellyApp.g_iTotalRibs; m_previousKeyFrame = keyframe; } } } --- NEW FILE: RibTrails.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RibTrails : Animation { private float m_CurrentRowIndexFLOAT = 0.0f; private float m_RowDelta = 0.03f; public override string GetAnimationName() { return "RibTrails"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { Rib ribObject = keyframe.GetRib(rib); Rib.RibDirection direction = Rib.RibDirection.UP; // truncate this float value, and then mod it to wrap ribObject.TrailEffect(((int)m_CurrentRowIndexFLOAT % JellyApp.g_iLightsPerRib), 30, direction); m_CurrentRowIndexFLOAT += m_RowDelta; } } } } --- NEW FILE: SevenBandFreqShow.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SevenBandFreqShow : Animation { public SevenBandFreqShow() { // reset the peak detectors JellyApp.g_SevenBandSpectrumPeak = 0; m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "SevenBandFreqShow"; } override public void UpdateKeyFrame(KeyFrame keyframe) { // get 7 bands of spectrum data int[] spectrum = JellyApp.g_SevenBandSpectrum; float peak = JellyApp.g_SevenBandSpectrumPeak; float currentSpectrumMax = -1.0f; for(int i = 0; i < spectrum.Length; i++) { if (spectrum[i] > currentSpectrumMax) { currentSpectrumMax = spectrum[i]; } } for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { int bandNo = rib % spectrum.Length; float bandVal = spectrum[bandNo]; if (bandVal == 0) continue; // here let's decide if we want to use the max spectrum value of this frame, //or if we want to use the overall peak float spectrumMax = currentSpectrumMax; if (!JellyApp.g_NormalizeSpectrumDataEachKeyFrame) { spectrumMax = peak; } int maxRow = (int)((bandVal / spectrumMax) * JellyApp.g_iLightsPerRib); if (maxRow >= JellyApp.g_iLightsPerRib) continue; for (int row = 0; row < maxRow; row++) { keyframe.m_Brightness[rib, row] = 1.0f; } } } } } --- NEW FILE: Spiral.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class Spiral : Animation { private int m_CurrentRowIndex = 0; private int m_CurrentRibIndex = 0; public override string GetAnimationName() { return "Spiral"; } override public void UpdateKeyFrame(KeyFrame keyframe) { keyframe.m_Brightness[m_CurrentRibIndex, m_CurrentRowIndex] = 1.0f; m_CurrentRibIndex++; // see if we've gone around this row one time. if(m_CurrentRibIndex >= (JellyApp.g_iTotalRibs - 1)) { // wrap around the rib m_CurrentRibIndex = 0; m_CurrentRowIndex++; if(m_CurrentRowIndex >= (JellyApp.g_iLightsPerRib - 1)) { // wrap back up to the top row m_CurrentRowIndex = 0; } } } } } --- NEW FILE: Worms.cs --- using System; using System.Collections.Generic; using System.Text; using System.Collections; namespace JellyTouch12000.Animations { class Worms : Animation { class DomePosition { public int m_ribPos = 0; public int m_rowPos = 0; } class Worm { // a max length to which the worm can grow int m_maxLength = 0; // a list of positions public ArrayList m_positionList = new ArrayList(); Random m_random = null; public Worm(int maxLength, int randomSeed) { m_random = new Random(randomSeed); // start out with a random position DomePosition firstPos = new DomePosition(); firstPos.m_ribPos = m_random.Next(0, JellyApp.g_iTotalRibs); firstPos.m_rowPos = m_random.Next(0, JellyApp.g_iLightsPerRib); // set the max length m_maxLength = maxLength; // add in the first position m_positionList.Add(firstPos); } public void UpdateFrame() { if (m_positionList.Count >= m_maxLength) { // remove from the 'end' which is the beginning of this list m_positionList.RemoveAt(0); } // let's move the worm in some random position DomePosition currentHeadPos = (DomePosition)m_positionList[m_positionList.Count - 1]; DomePosition newHeadPos = new DomePosition(); newHeadPos.m_ribPos = currentHeadPos.m_ribPos; newHeadPos.m_rowPos = currentHeadPos.m_rowPos; // this random looks a bit weird, but C# returns a value greater than or equal to the min // but LESS THAN the max int ribDelta = m_random.Next(-1, 2); int rowDelta = m_random.Next(-1, 2); newHeadPos.m_ribPos += ribDelta; newHeadPos.m_rowPos += rowDelta; // handle wrapping around from one end of the dome to another newHeadPos.m_ribPos += JellyApp.g_iTotalRibs; newHeadPos.m_rowPos += JellyApp.g_iLightsPerRib; // now make sure that the new position is in bounds newHeadPos.m_ribPos %= JellyApp.g_iTotalRibs; newHeadPos.m_rowPos %= JellyApp.g_iLightsPerRib; // add this new position to the list m_positionList.Add(newHeadPos); } } public override string GetAnimationName() { return "Worms"; } int m_maxWorms = 10; int m_maxWormLength = 10; ArrayList m_wormList = new ArrayList(); public Worms() { // let's update this guy fast!!! m_SubFramesPerKeyFrame = 1; Random globalRandom = new Random(Environment.TickCount); // create a number of worms randomized over the dome for (int i = 0; i < m_maxWorms; i++) { Worm newWorm = new Worm(m_maxWormLength, globalRandom.Next()); m_wormList.Add(newWorm); } } override public void UpdateKeyFrame(KeyFrame keyframe) { // go through all the worms, update them and then render them foreach (Worm worm in m_wormList) { worm.UpdateFrame(); // and now that we have updated the worm, let's render it on the dome foreach (DomePosition pos in worm.m_positionList) { // right now we draw all of the worm at 100% keyframe.m_Brightness[pos.m_ribPos, pos.m_rowPos] = 1.0f; } } } } } --- NEW FILE: Hypocycloid.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Growie.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { public class Growie : Animation { public Growie() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "Growie"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { float ribvalue = (float)rib + 1.0f; float rowvalue = (float)row + 1.0f; LED led = LEDInfo.GetLED(rib, row); // use this one to get the true X,Y coordinates(when the spreadsheet is loaded) //float brightness = (float)(Math.Sin(delta * led.X * led.Y)); // this one just uses the index, not the position! float brightness = (float)(Math.Sin(m_Delta * ribvalue * rowvalue)); // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 brightness += 1.0f; brightness /= 2.0f; // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, row] = JellyApp.ClampBrightness(brightness); } } m_Delta += 0.002f; } public float m_Delta = 0.0f; } } --- NEW FILE: RowColorCycleFade.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RowColorCycleFade : Animation { public override string GetAnimationName() { return "RowColorCycleFade"; } public float GetSineBrightness (float offset) { float brightness = (float)(((Math.Sin(m_Delta+offset))+1)/2); JellyApp.ClampBrightness(brightness); return brightness; } public override void UpdateKeyFrame(KeyFrame keyframe) { int frameCount = GetKeyFrameCount(); //for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) //{ for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { //float ribvalue = (float)rib + 1.0f; //float rowvalue = (float)row + 1.0f; float myoffset = (float)row / 7.0f; keyframe.m_Brightness[rib, row] = GetSineBrightness(myoffset); } } m_Delta += 0.2f; } public float m_Delta = 0.0f; } } --- NEW FILE: GrowieCS.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { public class GrowieCS : Animation { public override string GetAnimationName() { return "GrowieCS"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int jixelrow = 0; jixelrow < JellyApp.g_iLightsPerRib; jixelrow++) { float ribvalue = (float)rib + 1.0f; float rowvalue = (float)jixelrow + 1.0f; LED led = LEDInfo.GetLED(rib, jixelrow); // use this one to get the true X,Y coordinates(when the spreadsheet is loaded) //float brightness = (float)(Math.Sin(delta * led.X * led.Y)); // this one just uses the index, not the position! float brightness = (float)(Math.Sin(m_Delta * ribvalue * rowvalue)); // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 brightness += 1.0f; brightness /= 2.0f; // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, jixelrow] = JellyApp.ClampBrightness(brightness); } } m_Delta += 0.2f; } public float m_Delta = 0.0f; } } --- NEW FILE: RowCycle.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RowCycle : Animation { public RowCycle() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "RowCycle"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { int frameCount = GetKeyFrameCount(); // cycle through turning on all the rows Row rowObject = keyframe.GetRow(frameCount % JellyApp.g_iLightsPerRib); rowObject.SetBrightness(1.0f); } } } } } --- NEW FILE: LifeSpaceShips_02.cs --- using System; using System.Collections.Generic; using System.Text; using JellyTouch12000.Animations.Algorithms; namespace JellyTouch12000.Animations { public class LifeSpaceShips_02 : LifeBaseAnimation { #region ctor public LifeSpaceShips_02() : base() { InitAnimation(); } public LifeSpaceShips_02(int life_span, bool jixel_precision) : base(life_span, jixel_precision) { InitAnimation(); } // Setup Animation private void InitAnimation() { _name = "LifeSpaceShips_02"; #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(16, 0), new Point(17, 0), new Point(13, 1), new Point(16, 1), new Point(17, 1), new Point(18, 1), new Point(14, 2), new Point(15, 2), new Point(16, 2), new Point(17, 2), new Point(14, 4), new Point(12, 5), new Point(13, 5), new Point(14, 5), new Point(12, 6), new Point(15, 6), new Point(16, 8), new Point(17, 8), new Point(14, 9), new Point(17, 9), new Point(12, 10), new Point(17, 10), new Point(18, 10), new Point(13, 11), new Point(15, 11), new Point(17, 11), new Point(12, 12), new Point(13, 12), new Point(15, 13), new Point(16, 13), new Point(16, 14), new Point(14, 15), new Point(12, 16), new Point(13, 16), new Point(15, 16), new Point(16, 16), new Point(13, 17), new Point(14, 17), new Point(15, 17), new Point(13, 18), new Point(14, 18), new Point(13, 19), new Point(12, 20), new Point(13, 20), new Point(14, 20), new Point(14, 22), new Point(8, 23), new Point(9, 23), new Point(14, 23), new Point(17, 23), new Point(6, 24), new Point(12, 24), new Point(13, 24), new Point(16, 24), new Point(17, 24), new Point(5, 25), new Point(10, 25), new Point(17, 25), new Point(0, 26), new Point(5, 26), new Point(7, 26), new Point(8, 26), new Point(9, 26), new Point(10, 26), new Point(0, 27), new Point(2, 27), new Point(4, 27), new Point(5, 27), new Point(6, 27), new Point(0, 28), new Point(2, 28) }); if (_jixel_precision) _gol.LoadPattern(_pattern); else { _gol.LoadPattern(_pattern, 3, 3, false); _gol.LoadPattern(_pattern, 3, 35, false); } _pattern = new List<Point>(new Point[] { new Point(1, 0), new Point(2, 0), new Point(3, 0), new Point(0, 1), new Point(4, 1), new Point(5, 1), new Point(7, 2), new Point(0, 3), new Point(4, 3), new Point(8, 3), new Point(9, 3), new Point(0, 4), new Point(4, 4), new Point(7, 4), new Point(4, 5), new Point(5, 5), new Point(0, 6), new Point(4, 6), new Point(0, 7), new Point(4, 7), new Point(2, 8), new Point(3, 8), new Point(4, 8), new Point(2, 10), new Point(3, 10), new Point(4, 10), new Point(0, 11), new Point(4, 11), new Point(0, 12), new Point(4, 12), new Point(4, 13), new Point(5, 13), new Point(0, 14), new Point(4, 14), new Point(7, 14), new Point(0, 15), new Point(4, 15), new Point(8, 15), new Point(9, 15), new Point(7, 16), new Point(0, 17), new Point(4, 17), new Point(5, 17), new Point(1, 18), new Point(2, 18), new Point(3, 18) }); if (_jixel_precision) _gol.LoadPattern(_pattern); else { _gol.LoadPattern(_pattern, 3, 3, false); _gol.LoadPattern(_pattern, 3, 35, false); } #endregion } #endregion public override void UpdateKeyFrame(KeyFrame keyframe) { base.UpdateKeyFrame(keyframe); } } } --- NEW FILE: LifeDiehard.cs --- using System; using System.Collections.Generic; using System.Text; using JellyTouch12000.Animations.Algorithms; namespace JellyTouch12000.Animations { public class LifeDiehard : LifeBaseAnimation { #region ctor public LifeDiehard() : base() { InitAnimation(); } public LifeDiehard(int life_span, bool jixel_precision) : base(life_span, jixel_precision) { InitAnimation(); } // Setup Animation private void InitAnimation() { _name = "LifeDiehard"; #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(6, 0), new Point(0, 1), new Point(1, 1), new Point(1, 2), new Point(5, 2), new Point(6, 2), new Point(7, 2) }); #endregion if (_jixel_precision) _gol.LoadPattern(_pattern, true, 5); else _gol.LoadPattern(_pattern, true, 30); } #endregion public override void UpdateKeyFrame(KeyFrame keyframe) { base.UpdateKeyFrame(keyframe); } } } --- NEW FILE: SpectrumColors.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SpectrumColors : Animation { public override string GetAnimationName() { return "SpectrumColors"; } public SpectrumColors() { // reset the peak detectors JellyApp.g_SevenBandSpectrumPeak = 0; m_SubFramesPerKeyFrame = 5; } override public void UpdateKeyFrame(KeyFrame keyframe) { // get 7 bands of spectrum data int[] spectrum = JellyApp.g_SevenBandSpectrum; float peak = JellyApp.g_SevenBandSpectrumPeak; float currentSpectrumMax = -1.0f; for (int i = 0; i < spectrum.Length; i++) { if (spectrum[i] > currentSpectrumMax) { currentSpectrumMax = spectrum[i]; } } // first let's start with the data we had from the previous frame /* if (m_previousKeyFrame != null) { // copy the brightness data from the previous frame for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { // we get teh previous values , but decay them slightly keyframe.m_Brightness[i, j] = (m_previousKeyFrame.m_Brightness[i, j] * m_brightnessDecay); } } } */ // go through each rib since we will do the same thing to each one for(int ribIndex = 0; ribIndex < JellyApp.g_iTotalRibs; ribIndex++) { // and let's clear out the rib that the radar is currently on Rib rib = keyframe.GetRib(ribIndex); // and now do a pass for each color using spectrum data for each one for (int i = 0; i < spectrum.Length; i++) { // here let's decide if we want to use the max spectrum value of this frame, //or if we want to use the overall peak float spectrumMax = currentSpectrumMax; if (!JellyApp.g_NormalizeSpectrumDataEachKeyFrame) { spectrumMax = peak; } int height = (int)((spectrum[i] / spectrumMax) * JellyApp.g_iLightsPerRib); height %= JellyApp.g_iLightsPerRib; JixelColor color = (JixelColor)i; rib.TrailEffect(0, height, Rib.RibDirection.UP, color, false); } } } } } --- NEW FILE: LifeFlapper.cs --- using System; using System.Collections.Generic; using System.Text; using JellyTouch12000.Animations.Algorithms; namespace JellyTouch12000.Animations { public class LifeFlapper : LifeBaseAnimation { #region ctor public LifeFlapper() : base() { InitAnimation(); } public LifeFlapper(int life_span, bool jixel_precision) : base(life_span, jixel_precision) { InitAnimation(); } // Setup Animation private void InitAnimation() { _name = "LifeFlapper"; #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(4, 0), new Point(5, 0), new Point(6, 0), new Point(7, 0), new Point(8, 0), new Point(9, 0), new Point(2, 1), new Point(3, 1), new Point(9, 1), new Point(0, 2), new Point(1, 2), new Point(3, 2), new Point(9, 2), new Point(4, 3), new Point(8, 3), new Point(6, 4), new Point(6, 5), new Point(7, 5), new Point(5, 6), new Point(6, 6), new Point(7, 6), new Point(8, 6), new Point(5, 7), new Point(6, 7), new Point(8, 7), new Point(9, 7), new Point(7, 8), new Point(8, 8) }); #endregion if (_jixel_precision) _gol.LoadPattern(_pattern); { _gol.LoadPattern(_pattern, 3, 3, false); _gol.LoadPattern(_pattern, 3, 18, false); _gol.LoadPattern(_pattern, 3, 33, false); _gol.LoadPattern(_pattern, 3, 48, false); _gol.LoadPattern(_pattern, 3, 63, false); } } #endregion public override void UpdateKeyFrame(KeyFrame keyframe) { base.UpdateKeyFrame(keyframe); } } } --- NEW FILE: StraightSine.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { public class StraightSine : Animation { public StraightSine() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "StraightSine"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { //float ribvalue = (float)rib + 1.0f; float rowvalue = (float)row + 1.0f; LED led = LEDInfo.GetLED(rib, row); // use this one to get the true X,Y coordinates(when the spreadsheet is loaded) //float brightness = (float)(Math.Sin(delta * led.X * led.Y)); // this one just uses the index, not the position! float brightness = (float)(Math.Sin(m_Delta * rowvalue)); // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 brightness += 1.0f; brightness /= 2.0f; // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, row] = JellyApp.ClampBrightness(brightness); } } m_Delta += 0.002f; } public float m_Delta = 0.0f; } } --- NEW FILE: RibColorCycleFade_03.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RibColorCycleFade_03 : Animation { public int m_CurrentRibIndex = 0; public override string GetAnimationName() { return "RibColorCycleFade_03"; } //public int myRibIndex = 0; public override void UpdateKeyFrame(KeyFrame keyframe) { int frameCount = GetKeyFrameCount(); float mybrightness = (((frameCount / 10) % 10) / 10.0f); //if (mybrightness >= .8) // myRibIndex++; //m_CurrentRibIndex = myRibIndex % JellyApp.g_iTotalRibs; m_CurrentRibIndex=(frameCount/100 % JellyApp.g_iTotalRibs); Rib ribObject = keyframe.GetRib(m_CurrentRibIndex); // int colorIndex = frameCount % (int)Color.MAX_COLOR; ribObject.SetBrightness(mybrightness); } } } --- NEW FILE: JixelColorCycleFade.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class JixelColorCycleFade : Animation { public override string GetAnimationName() { return "JixelColorCycleFade"; } public override void UpdateKeyFrame(KeyFrame keyframe) { int frameCount = GetKeyFrameCount(); //for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) //{ for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { // this one just uses the index, not the position! // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 float brightness = (float)(((Math.Sin(m_Delta))+1)/2); // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, 16] = JellyApp.ClampBrightness(brightness); keyframe.m_Brightness[rib, 17] = JellyApp.ClampBrightness(brightness); keyframe.m_Brightness[rib, 18] = JellyApp.ClampBrightness(brightness); keyframe.m_Brightness[rib, 19] = JellyApp.ClampBrightness(brightness); keyframe.m_Brightness[rib, 20] = JellyApp.ClampBrightness(brightness); } m_Delta += 0.1f; } public float m_Delta = 0.0f; } } //public override void UpdateKeyFrame(KeyFrame keyframe) // { // int frameCount = GetKeyFrameCount(); // float mybrightness = (frameCount % 10) / 10.0f; // m_CurrentRibIndex = (frameCount / 10) % JellyApp.g_iTotalRibs; // Rib ribObject = keyframe.GetRib(m_CurrentRibIndex); // ribObject.SetBrightness(mybrightness); // } --- NEW FILE: JixelColorCycle.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class JixelColorCycle : Animation { public JixelColorCycle() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "JixelColorCycle"; } public override void UpdateKeyFrame(KeyFrame keyframe) { int frameCount = GetKeyFrameCount(); for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int jixelIndex = 0; jixelIndex < JellyApp.g_iJixelsPerRib; jixelIndex++) { Jixel jixel = keyframe.GetJixel(rib, jixelIndex); // turn on each different color with each keyframe keyframe.SetColorBrightness((JixelColor)(frameCount % JellyApp.g_iColorsPerJixel), 1.0f); } } } } } --- NEW FILE: StraightSine_02.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { public class StraightSine_02 : Animation { public StraightSine_02() { m_SubFramesPerKeyFrame = 7; } public override string GetAnimationName() { return "StraightSine_02"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { //float ribvalue = (float)rib + 1.0f; float rowvalue = (float)row + 1.0f; LED led = LEDInfo.GetLED(rib, row); // use this one to get the true X,Y coordinates(when the spreadsheet is loaded) //float brightness = (float)(Math.Sin(delta * led.X * led.Y)); // this one just uses the index, not the position! float brightness = (float)(Math.Sin(m_Delta * 5 * rowvalue)); // sin is -1.0 to 1.0 so let's get it 0.0 to 1.0 brightness += 1.0f; brightness /= 2.0f; // let's clamp in case i screwed up my calculations!!! :) keyframe.m_Brightness[rib, row] = JellyApp.ClampBrightness(brightness); } } m_Delta += 0.002f; } public float m_Delta = 0.0f; } } --- NEW FILE: LifePufferP16C2.cs --- using System; using System.Collections.Generic; using System.Text; using JellyBrain.Animations.Algorithms; namespace JellyBrain.Animations { public class LifePufferP16C2 : Animation { private List<Point> _pattern; private int _generations; private int _lights_or_jixels; // GOL cells map to: 1 == lights, 2 == jixels private GameOfLife _gol; #region ctor public LifePufferP16C2() { // 8 generations, treat lights as GOL cells Init(8, 1); } public LifePufferP16C2(int generations, int lights_or_jixels) { Init(generations, lights_or_jixels); } // Setup GOL parameters // Sets # of generations until cell death and how GOL cells are interpreted. private void Init(int generations, int lights_or_jixels) { #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(4, 0), new Point(5, 0), new Point(6, 0), new Point(7, 0), new Point(8, 0), new Point(9, 0), new Point(2, 1), new Point(3, 1), new Point(9, 1), new Point(0, 2), new Point(1, 2), new Point(3, 2), new Point(9, 2), new Point(4, 3), new Point(8, 3), new Point(6, 4), new Point(6, 5), new Point(7, 5), new Point(5, 6), new Point(6, 6), new Point(7, 6), new Point(8, 6), new Point(5, 7), new Point(6, 7), new Point(8, 7), new Point(9, 7), new Point(7, 8), new Point(8, 8) }); #endregion _generations = generations; _lights_or_jixels = lights_or_jixels; // y range will equal jixel count if (_lights_or_jixels == 2) _gol = new GameOfLife(JellyBrain.g_iTotalRibs, JellyBrain.g_iJixelsPerRib, _generations); // y range will equal light count else _gol = new GameOfLife(JellyBrain.g_iTotalRibs, JellyBrain.g_iLightsPerRib, _generations); _gol.LoadPattern(_pattern); _gol.Translate(0, 50); } #endregion public override string GetAnimationName() { return "LifePufferP16C2"; } public override void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyBrain.g_iTotalRibs; rib++) { for (int jixel = 0; jixel < JellyBrain.g_iJixelsPerRib; jixel++) { int base_jixel_row = (JellyBrain.g_iColorsPerJixel * jixel); // Use generation value to select a single LED in the jixel if (_lights_or_jixels == 2) { // Get current game cell int gcell = _gol.GameGrid[rib, jixel]; // If cell is alive (1) or aged within color range supported (e.g. 2-8) if (gcell > 0 && gcell <= JellyBrain.g_iColorsPerJixel) { // Light one of the jixel colors keyframe.m_Brightness[rib, base_jixel_row + gcell - 1] = 1.0f; } } // Use generation value to drive LED brightnes (increasingly dim for older generations) else { // Iterate on each LED in jixel for (int row = base_jixel_row; row < (JellyBrain.g_iColorsPerJixel + base_jixel_row); row++) { // Get current game cell int gcell = _gol.GameGrid[rib, row]; // If cell is alive (1) or aged within color range supported (e.g. 2-8) if (gcell > 0 && gcell <= JellyBrain.g_iColorsPerJixel) { keyframe.m_Brightness[rib, row] = (1 / gcell) * 1.0f; } } } } } // Tick the GOL _gol.PlayGeneration(); } } } --- NEW FILE: AllOff.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class AllOff : Animation { public AllOff() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "AllOff"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { keyframe.SetBrightness(0.0f); } } } } } --- NEW FILE: AllOn.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class AllOn : Animation { public AllOn() { m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "AllOn"; } override public void UpdateKeyFrame(KeyFrame keyframe) { keyframe.SetBrightness(1.0f); } } } --- NEW FILE: LifeAcorn.cs --- using System; using System.Collections.Generic; using System.Text; using JellyTouch12000.Animations.Algorithms; namespace JellyTouch12000.Animations { public class LifeAcorn : LifeBaseAnimation { #region ctor public LifeAcorn() : base() { InitAnimation(); } public LifeAcorn(int life_span, bool jixel_precision) : base(life_span, jixel_precision) { InitAnimation(); } // Setup Animation private void InitAnimation() { _name = "LifeAcorn"; #region Initialize pattern _pattern = new List<Point>(new Point[] { new Point(1, 0), new Point(3, 1), new Point(0, 2), new Point(1, 2), new Point(4, 2), new Point(5, 2), new Point(6, 2) }); #endregion if (_jixel_precision) _gol.LoadPattern(_pattern, true, 5); else _gol.LoadPattern(_pattern, true, 30); } #endregion public override void UpdateKeyFrame(KeyFrame keyframe) { base.UpdateKeyFrame(keyframe); } } } --- NEW FILE: SpectrumRadar_02.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SpectrumRadar2 : Animation { KeyFrame m_previousKeyFrame = null; int m_radarRibIndex = 0; float m_brightnessDecay = 0.93f; // change this to determine which 'jixel row' we start drawing at int m_startJixelRow = 3; public override string GetAnimationName() { return "SpectrumRadar_02"; } public SpectrumRadar2() { // reset the peak detectors JellyApp.g_SevenBandSpectrumPeak = 0; m_SubFramesPerKeyFrame = 3; } override public void UpdateKeyFrame(KeyFrame keyframe) { // get 7 bands of spectrum data int[] spectrum = JellyApp.g_SevenBandSpectrum; float peak = JellyApp.g_SevenBandSpectrumPeak; float currentSpectrumMax = -1.0f; for (int i = 0; i < spectrum.Length; i++) { if (spectrum[i] > currentSpectrumMax) { currentSpectrumMax = spectrum[i]; } } // first let's start with the data we had from the previous frame if (m_previousKeyFrame != null) { // copy the brightness data from the previous frame for (int i = 0; i < JellyApp.g_iTotalRibs; i++) { for (int j = 0; j < JellyApp.g_iLightsPerRib; j++) { keyframe.m_Brightness[i, j] = (m_previousKeyFrame.m_Brightness[i, j] * m_brightnessDecay); } } } // and let's clear out the rib that the radar is currently on Rib radarRib = keyframe.GetRib(m_radarRibIndex); radarRib.SetBrightness(0.0f); // work on each band for (int i = 0; i < spectrum.Length; i++) { int jixelRow = i + m_startJixelRow; Jixel jixel = keyframe.GetJixel(m_radarRibIndex, jixelRow); // here let's decide if we want to use the max spectrum value of this frame, //or if we want to use the overall peak float spectrumMax = currentSpectrumMax; if (!JellyApp.g_NormalizeSpectrumDataEachKeyFrame) { spectrumMax = peak; } float spectrumRatio = (spectrum[i] / spectrumMax); // determine how many LEDs to turn on per jixel based on the percentage // of energy in this band normalized compared to the other bands for (int color = 0; color < JellyApp.g_iColorsPerJixel; color++) { float colorThreshold = (float)color / (float)JellyApp.g_iColorsPerJixel; if (spectrumRatio > colorThreshold && colorThreshold > 0.0f) { jixel.SetColorBrightness((JixelColor)color, 1.0f); } } } m_radarRibIndex++; m_radarRibIndex %= JellyApp.g_iTotalRibs; m_previousKeyFrame = keyframe; } } } --- NEW FILE: OneColor.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class OneColor : Animation { private int m_coloridx; public OneColor() { m_SubFramesPerKeyFrame = 1; m_coloridx = 7; } public override string GetAnimationName() { return "OneColor"; } public void CycleToNextColor() { if (++m_coloridx >= JellyApp.g_iColorsPerJixel) m_coloridx = 0; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { for (int row = 0; row < JellyApp.g_iLightsPerRib; row++) { int jixel = row % JellyApp.g_iColorsPerJixel; if (jixel == m_coloridx) { Row rowObject = keyframe.GetRow(row); rowObject.SetBrightness(1.0f); } } } } } } --- NEW FILE: AccidentalSpiral.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { // TODO kellyp -- i don't know how i did this but it ends up with a pretty cool spiral effect // when i was really trying to do a "matrix" rain trails type effect class AccidentalSpiral : Animation { private int m_CurrentRowIndex = 0; public AccidentalSpiral() { m_SubFramesPerKeyFrame = 3; } public override string GetAnimationName() { return "AccidentalSpiral"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyApp.g_iTotalRibs; rib++) { Rib ribObject = keyframe.GetRib(rib); Rib.RibDirection direction = Rib.RibDirection.DOWN; ribObject.TrailEffect(m_CurrentRowIndex, 10, direction); m_CurrentRowIndex++; // make sure this wraps m_CurrentRowIndex %= JellyApp.g_iLightsPerRib; } } } } --- NEW FILE: SpinningRows.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SpinningRows : Animation { // this keeps track of which rib each row is on private int[] m_CurrentRibIndexArray; // this is the contructor for the class public SpinningRows() { m_CurrentRibIndexArray = new int[JellyApp.g_iLightsPerRib]; m_SubFramesPerKeyFrame = 3; Random random = new Random(Environment.TickCount); // set these all for(int i = 0; i < JellyApp.g_iLightsPerRib; i++) { m_CurrentRibIndexArray[i] = random.Next(0, JellyApp.g_iTotalRibs - 1); } } public override string GetAnimationName() { return "SpinningRows"; } override public void UpdateKeyFrame(KeyFrame keyframe) { int frameCount = GetKeyFrameCount(); // let's go through each row and update it for(int row = 0; row < JellyApp.g_iLightsPerRib; row++) { // cycle every other row in a different direction around the dome Row.RowDirection direction = Row.RowDirection.LEFT; if (row % 2 == 0) { m_CurrentRibIndexArray[row]++; // wrap back if(m_CurrentRibIndexArray[row] == JellyApp.g_iTotalRibs) { m_CurrentRibIndexArray[row] = 0; } direction = Row.RowDirection.RIGHT; } else { m_CurrentRibIndexArray[row]--; // wrap back if (m_CurrentRibIndexArray[row] < 0) { m_CurrentRibIndexArray[row] = JellyApp.g_iTotalRibs - 1; } direction = Row.RowDirection.LEFT; } // let's do a trail effect instead! WOOO!!! //keyframe.m_Brightness[m_CurrentRibIndexArray[row], row] = 1.0f; Row rowObject = keyframe.GetRow(row); rowObject.TrailEffect(m_CurrentRibIndexArray[row], 4, direction); } } } } --- NEW FILE: SpinningSpectrum.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class SpinningSpectrum : Animation { double m_sinWaveIncrement = 0.02; double m_currentSinValue = 0.0f; double m_currentRibIndex = 0.0f; double m_sinFactor = 1.5f; public override string GetAnimationName() { return "SpinningSpectrum"; } public SpinningSpectrum() { // reset the peak detectors JellyApp.g_SevenBandSpectrumPeak = 0; m_SubFramesPerKeyFrame = 3; } override public void UpdateKeyFrame(KeyFrame keyframe) { // get 7 bands of spectrum data int[] spectrum = JellyApp.g_SevenBandSpectrum; float peak = JellyApp.g_SevenBandSpectrumPeak; float currentSpectrumMax = -1.0f; for (int i = 0; i < spectrum.Length; i++) { if (spectrum[i] > currentSpectrumMax) { currentSpectrumMax = spectrum[i]; } } int startingRibIndex = (int)m_currentRibIndex; startingRibIndex %= JellyApp.g_iTotalRibs; //Console.WriteLine("Current rib index : " + startingRibIndex); for (int i = 0; i < 7; i++) { int ribIndex = i + startingRibIndex; ribIndex %= JellyApp.g_iTotalRibs; Rib rib = keyframe.GetRib(ribIndex); int height = (int)((spectrum[i] / currentSpectrumMax) * JellyApp.g_iLightsPerRib); height %= JellyApp.g_iLightsPerRib; rib.TrailEffect(0, height, Rib.RibDirection.UP, JixelColor.ALL_COLORS, false); } // finally, let's increment the rib index using a sine function m_currentSinValue += m_sinWaveIncrement; m_currentRibIndex += m_sinFactor * Math.Sin(m_currentSinValue); } } } --- NEW FILE: PolarRose.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: RibColorCycleFade.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000.Animations { class RibColorCycleFade : Animation { public override string GetAnimationName() { return "RibColorCycleFade"; } public override void UpdateKeyFrame(KeyFrame keyframe)... [truncated message content] |
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000 In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv18954 Added Files: Animation.cs AnimationListForm.Designer.cs AnimationListForm.cs AnimationListForm.resx Game.ico GameThumbnail.png HardwareInterface.cs JellyApp.cs JellyBrain.cs JellyTouch12000.csproj JellyTouch12000.sln JellyView.cs Jixel.cs KeyFrame.cs KeyFramePulses.cs LEDInfo.cs MessageClient.cs MessageServer.cs NetworkMessage.cs PlanarTouchSurface.cs Program.cs RadialTouchSurface.cs Rib.cs Row.cs StopWatch.cs SubFrame.cs TouchBackground.cs TouchJixel.cs TouchLED.cs TouchSurface.cs Transition.cs USBDevice.cs Log Message: JellyTouch first commit. --- NEW FILE: StopWatch.cs --- /* Copyright (c) 2006, Corey Goldberg StopWatch.cs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. */ using System; namespace JellyTouch12000 { public class StopWatch { private DateTime startTime; private DateTime stopTime; private bool running = false; public void Start() { this.startTime = DateTime.Now; this.running = true; } public void Stop() { this.stopTime = DateTime.Now; this.running = false; } // elaspsed time in milliseconds public double GetElapsedTime() { TimeSpan interval; if (running) interval = DateTime.Now - startTime; else interval = stopTime - startTime; return interval.TotalMilliseconds; } // elaspsed time in seconds public double GetElapsedTimeSecs() { TimeSpan interval; if (running) interval = DateTime.Now - startTime; else interval = stopTime - startTime; return interval.TotalSeconds; } /* // sample usage public static void Main(String[] args) { StopWatch s = new StopWatch(); s.Start(); // code you want to time goes here s.Stop(); Console.WriteLine("elapsed time in milliseconds: " + s.GetElapsedTime()); } */ } } --- NEW FILE: RadialTouchSurface.cs --- using System; using System.Collections.Generic; using System.Text; using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace JellyTouch12000 { class RadialTouchSurface : TouchSurface { //point list //BasicEffect m_BasicEffect; //VertexDeclaration m_VertexDecl; //VertexPositionNormalTexture[] m_PointList; const float m_fInnerDiameter = 100.0f; const float m_fInnerRadius = m_fInnerDiameter / 2.0f; float m_fRadiansPerRib = 0.0f; float m_fRibLength = 0.0f; float m_fJixelSpacing = 0.0f; private bool m_bAutoChangeBrushColor = true; //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public RadialTouchSurface(JellyApp app) : base(app) { m_Name = "Radial"; InitBasicEffect(); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// void InitBasicEffect() { // m_VertexDecl = new VertexDeclaration(m_Graphics.GraphicsDevice, VertexPositionNormalTexture.VertexElements); // m_BasicEffect = new BasicEffect(m_Graphics.GraphicsDevice, null); // m_BasicEffect.DiffuseColor = new Vector3(1.0f, 0.0f, 1.0f); // m_BasicEffect.World = m_MatWorld; // m_BasicEffect.View = m_MatView; // m_BasicEffect.Projection = m_MatProj; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected override void InitMatrices() { int iBackBufferHeight = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; int iBackBufferWidth = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; int iHalfHeight = iBackBufferHeight / 2; int iHalfWidth = iBackBufferWidth / 2; //setup the matrices for the hardware m_MatWorld = Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f)); m_MatView = Matrix.CreateLookAt(new Vector3(0, 0, 1), new Vector3(0, 0, 0.0f), Vector3.Up); m_MatProj = Matrix.CreateOrthographic(1024, 768, 1.0f, 2000.0f); //TODO: get rid of these not-so-magic numbers m_MatWorldViewProj = m_MatWorld * m_MatView * m_MatProj; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected override void InitJixels() { int iBackBufferHeight = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; int iBackBufferWidth = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; int iNumJixels = JellyApp.g_iTotalRibs * JellyApp.g_iJixelsPerRib; //m_PointList = new VertexPositionNormalTexture[iNumJixels]; m_fRadiansPerRib = ( MathHelper.Pi * 2.0f ) / JellyApp.g_iTotalRibs; m_fRibLength = (iBackBufferHeight / 2.0f) - m_fInnerRadius; //actual rib length from above is ~ m_fJixelSpacing = m_fRibLength / JellyApp.g_iJixelsPerRib; Matrix matRotation = Matrix.CreateRotationZ(m_fRadiansPerRib); Vector3 vDir = Vector3.Right; //build the fan but running down each rib for (int iCurRib = 0; iCurRib < JellyApp.g_iTotalRibs; ++iCurRib ) { for (int iCurRow = 0; iCurRow < JellyApp.g_iJixelsPerRib; ++iCurRow) { m_Jixels[iCurRow, iCurRib] = new TouchJixel(); m_Jixels[iCurRow, iCurRib].Position = vDir * ((iCurRow * m_fJixelSpacing) + m_fInnerDiameter / 2); } vDir = Vector3.Transform(vDir, matRotation); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// List<TouchJixel> m_SelectedJixels = new List<TouchJixel>(5); //enough for the cross, maybe we should make this a member and static in size? //these will be flat brushes //private int iBrushWidthRadius = 2; //private int iBrushHeightRadius = 3; protected override void UpdateJixels(GameTime gameTime) { int iBackBufferHeight = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; int iBackBufferWidth = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; int iHorizontalSpacing = iBackBufferWidth / JellyApp.g_iTotalRibs; int iVerticalSpacing = iBackBufferHeight / JellyApp.g_iJixelsPerRib; int iX = m_iMouseX - (int)(iBackBufferWidth / 2.0f); int iY = m_iMouseY - (int)(iBackBufferHeight / 2.0f); Vector3 vMousePos = new Vector3(iX, iY, 0); m_SelectedJixels.Clear(); int iRow = 0; int iRib = 0; float fDistFromCenter = vMousePos.Length(); if (fDistFromCenter < (m_fJixelSpacing * JellyApp.g_iJixelsPerRib) + m_fInnerRadius && fDistFromCenter > (m_fInnerRadius * 0.5f)) { float fDot = Vector3.Dot(vMousePos, Vector3.Up); float fAngle = (float)Math.Acos(vMousePos.X / fDistFromCenter); if (fDot > 0) fAngle = MathHelper.Pi * 2 - fAngle; fAngle += m_fRadiansPerRib / 2; float fRow = (fDistFromCenter - m_fInnerRadius) / m_fJixelSpacing; iRow = (int)fRow; iRib = (int)(fAngle / m_fRadiansPerRib); iRib = (int)MathHelper.Clamp(iRib, 0, JellyApp.g_iTotalRibs - 1); iRow = (int)MathHelper.Clamp(iRow, 0, JellyApp.g_iJixelsPerRib- 1); //m_iCurrentJixel = (iRib * JellyApp.g_iJixelsPerRib) + iRow; //m_iCurrentJixel = (int)MathHelper.Clamp(m_iCurrentJixel, 0, JellyApp.g_iJixelsPerRib*JellyApp.g_iTotalRibs-1); //add the middle jixel TouchJixel jixel = m_Jixels[iRow, iRib]; m_SelectedJixels.Add(jixel); // Color types //Rainbow //inverted rainbow //Single color switch (m_BrushType) { case BrushType.DIAMOND: DiamondBrush(iRow, iRib); break; case BrushType.ROW: RowBrush(iRow, iRib); break; case BrushType.RIB: RibBrush(iRow, iRib); break; case BrushType.BOX: BoxBrush(iRow, iRib); break; //single point selected already case BrushType.POINT: break; default: break; } } Monitor.Enter(this); if(m_bMouseDown) { foreach(TouchJixel jixel in m_SelectedJixels) { //jixel.Color = JixelColor.RED; //TODO: current color // jixel.Color = m_CurrentColor; } //TouchJixel jixel = m_Jixels[iRow, iRib]; //jixel.Color = JixelColor.RED; } foreach (TouchJixel jixel in m_Jixels) { jixel.Update(gameTime); } Monitor.Exit(this); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void DiamondBrush(int iRow, int iRib) { //set up the selected jixels for (int iSelectedRow = -m_iBrushRadius; iSelectedRow < m_iBrushRadius + 1; ++iSelectedRow) { int iSelRow = (int)MathHelper.Clamp(iSelectedRow + iRow, 0, JellyApp.g_iJixelsPerRib - 1); for (int iSelectedRib = -m_iBrushRadius + Math.Abs(iSelectedRow); iSelectedRib < (m_iBrushRadius + 1) - Math.Abs(iSelectedRow); ++iSelectedRib) { int iSelRib = (int)MathHelper.Clamp(iSelectedRib + iRib, 0, JellyApp.g_iTotalRibs - 1); m_SelectedJixels.Add(m_Jixels[iSelRow, iSelRib]); } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void RowBrush(int iRow, int iRib) { for (int iSelectedRib = -m_iBrushRadius; iSelectedRib < m_iBrushRadius + 1; ++iSelectedRib) { int iSelRib = (int)MathHelper.Clamp(iSelectedRib + iRib, 0, JellyApp.g_iTotalRibs - 1); m_SelectedJixels.Add(m_Jixels[iRow, iSelRib]); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void RibBrush(int iRow, int iRib) { for (int iSelectedRow = -m_iBrushRadius; iSelectedRow < m_iBrushRadius + 1; ++iSelectedRow) { int iSelRow = (int)MathHelper.Clamp(iSelectedRow + iRow, 0, JellyApp.g_iJixelsPerRib - 1); m_SelectedJixels.Add(m_Jixels[iSelRow, iRib]); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void BoxBrush(int iRow, int iRib) { for (int iSelectedRow = -m_iBrushRadius; iSelectedRow < m_iBrushRadius + 1; ++iSelectedRow) { int iSelRow = (int)MathHelper.Clamp(iSelectedRow + iRow, 0, JellyApp.g_iJixelsPerRib - 1); for (int iSelectedRib = -m_iBrushRadius; iSelectedRib < m_iBrushRadius + 1; ++iSelectedRib) { int iSelRib = (int)MathHelper.Clamp(iSelectedRib + iRib, 0, JellyApp.g_iTotalRibs - 1); m_SelectedJixels.Add(m_Jixels[iSelRow, iSelRib]); } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// override protected void LBPressed() { if(m_bAutoChangeBrushColor) { int iColor = (int)m_CurrentColor; iColor = (iColor + 1) % JellyApp.g_iColorsPerJixel; m_CurrentColor = (JixelColor)iColor; } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected override void RenderJixels(GameTime gameTime) { foreach (TouchJixel jixel in m_Jixels) { jixel.Render(); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected override void UpdateKeyboard(GameTime gameTime) { //check for color keys KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Up)) { m_iBrushRadius++; } else if (kState.IsKeyDown(Keys.Down)) { m_iBrushRadius--; m_iBrushRadius = Math.Max(m_iBrushRadius, 1); } else if (kState.IsKeyDown(Keys.Right)) { TouchJixel.FadeDelta = TouchJixel.FadeDelta + 0.01f; } else if (kState.IsKeyDown(Keys.Left)) { TouchJixel.FadeDelta = TouchJixel.FadeDelta - 0.01f; MathHelper.Clamp(TouchJixel.FadeDelta, 0.01f, 2.0f); } else if(kState.IsKeyDown(Keys.RightControl) || kState.IsKeyDown(Keys.RightControl)) { m_BrushType = (BrushType)((int)(m_BrushType + 1) % (int)BrushType.NUM_BRUSHES); } else if(kState.IsKeyDown(Keys.Escape)) { m_BrushType = BrushType.DIAMOND; TouchJixel.FadeDelta = 0.075f; m_iBrushRadius = 2; } //switch on the keys pressed to select color //if(kState.IsKeyDown(Keys.Z)) //{ // m_CurrentColor = JixelColor.PURPLE; //} //else if (kState.IsKeyDown(Keys.X)) //{ // m_CurrentColor = JixelColor.BLUE; //} //else if (kState.IsKeyDown(Keys.C)) //{ // m_CurrentColor = JixelColor.GREEN; //} //else if (kState.IsKeyDown(Keys.V)) //{ // m_CurrentColor = JixelColor.YELLOW; //} //else if (kState.IsKeyDown(Keys.B)) //{ // m_CurrentColor = JixelColor.ORANGE; //} //else if (kState.IsKeyDown(Keys.N)) //{ // m_CurrentColor = JixelColor.RED; //} //else if (kState.IsKeyDown(Keys.M)) //{ // m_CurrentColor = JixelColor.PINK; //} //else if (kState.IsKeyDown(Keys.OemComma)) //{ // m_CurrentColor = JixelColor.WHITE; //} } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// } } --- NEW FILE: Transition.cs --- // this is the base class for transitions. we will start by using these // for simple uses (like blending from one animation to the next) // but then later we may use these in some sort of genetic algorithm using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000 { abstract class Transition { // right now for simplicity we will call these A and B // but later we might want to add a list so we can "daisy chain" // animations through the transition protected Animation m_animA = null; protected Animation m_animB = null; // if this is negative, let's let it keep going protected float m_durationSeconds = -1.0f; protected StopWatch m_stopwatch = new StopWatch(); // our 'target' keyframe that we transition into protected KeyFrame m_targetKey = new KeyFrame(); // this should probably always play fast (1) unless the animations are doing brightness // blending in which case we should probably do the Math.Max() of the two animations protected int m_SubFramesPerKeyFrame = 1; abstract public string GetTransitionName(); abstract public void Update(); abstract public void Reset(); public KeyFrame KeyFrame { get { return m_targetKey; } } public Animation GetTargetAnimation() { return m_animB; } public bool IsTransitionActive() { return (m_durationSeconds > 0.0f && m_stopwatch.GetElapsedTimeSecs() < m_durationSeconds); } protected void UpdateAnimations() { UpdateAnimation(m_animA); UpdateAnimation(m_animB); } private void UpdateAnimation(Animation anim) { if (anim != null) { anim.KeyFrame.ResetFrame(); anim.KeyFrame.TotalSubFrames = anim.GetSubFramesPerKeyFrame(); anim.UpdateKeyFrame(anim.KeyFrame); anim.IncrementKeyFrameCount(); } } public void StartTransition(float durationSeconds, Animation a, Animation b) { m_durationSeconds = durationSeconds; m_animA = a; m_animB = b; // start the clock!!! m_stopwatch.Start(); // call the child class to implement the Init() call Reset(); } } } --- NEW FILE: JellyApp.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: MessageClient.cs --- using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; namespace JellyTouch12000 { public class MessageClient { TcpClient m_Client = new TcpClient(); string m_ServerName = Dns.GetHostName(); //TODO: expand beyond localhost //bool JellyApp.m_useUdp = true; // set to true to use connectionless UDP public bool Connected { get { if (JellyApp.m_useUdp) return true; // UDP is connectionless else if (m_Client != null) { return m_Client.Client.Connected; } return false; } } //////////////////////////////////////////////////////////////////////////////// // will reconnect if already connected //////////////////////////////////////////////////////////////////////////////// public void Connect() { if (JellyApp.m_useUdp) return; // UDP is connectionless Disconnect(); try { m_Client = new TcpClient(); m_Client.Connect(m_ServerName, 2055); Console.WriteLine("Connected."); } catch(Exception e) { Console.WriteLine(e.ToString()); //Console.WriteLine("Trying again in 10 seconds..."); //Thread.Sleep(10000); //TODO: move this out one level //Connect(); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void SendFrame(SubFrame frame) { byte[] frameData = frame.ToByteArray(); NetworkMessage nm = new NetworkMessage(); nm.iMessageID = NetworkMessage.MID_FRAME; nm.iDataSize = frameData.Length; nm.data = frameData; byte[] messageBuffer = nm.ToByteArray(); if (JellyApp.m_useUdp) { UdpClient m_UdpClient = new UdpClient(); m_UdpClient.Send(messageBuffer, messageBuffer.Length, m_ServerName, 2055); } else { NetworkStream ns = m_Client.GetStream(); try { ns.Write(messageBuffer, 0, messageBuffer.Length); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine("Trying again in 10 seconds..."); Thread.Sleep(10000); Connect(); } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Disconnect() { if (JellyApp.m_useUdp) return; // UDP is connectionless else if (m_Client.Connected) { NetworkMessage nm = new NetworkMessage(); nm.iMessageID = NetworkMessage.MID_DISCONNECT; nm.iDataSize = 0; NetworkStream ns = m_Client.GetStream(); byte[] messageBuffer = nm.ToByteArray(); ns.Write(messageBuffer, 0, messageBuffer.Length); m_Client.Client.Disconnect(false); m_Client.Client.Close(); } } } } --- NEW FILE: HardwareInterface.cs --- using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Windows.Forms; namespace JellyTouch12000 { public enum HardwareType { Serial = 0, USB, NUM_HARDWARE_TYPES } public class HardwareInterface { private USBDevice m_UsbDevice; private SerialPort m_SerialPort; public string com = "COM4"; public HardwareType m_Type = HardwareType.USB; public void InitComChannel() { switch(m_Type) { case HardwareType.USB: InitUsbDevice(); break; case HardwareType.Serial: InitSerialPort(); break; } } public void InitUsbDevice() { m_UsbDevice = new USBDevice(); //enumerate devices uint iNumDevices = 0; FT_STATUS result = m_UsbDevice.CreateDeviceInfoList(ref iNumDevices); for (uint iDevice = 0; iDevice < iNumDevices; ++iDevice) { result = m_UsbDevice.GetDeviceInfoDetail(iDevice); if (result != FT_STATUS.FT_OK) { MessageBox.Show("Error: GetDeviceInfoDetail failed."); return; } else { result = m_UsbDevice.OpenByDescription(m_UsbDevice.Description); if (result != FT_STATUS.FT_OK) { MessageBox.Show("Error: failed to open port"); } result = m_UsbDevice.SetBaudRate((uint)USBDevice.FT_BAUD_1000000); if (result != FT_STATUS.FT_OK) { MessageBox.Show("assholefeeever"); } result = m_UsbDevice.SetDataCharacteristics(8, 1, 0); if (result != FT_STATUS.FT_OK) { MessageBox.Show("assholefeeever"); } } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void InitSerialPort() { m_SerialPort = new System.IO.Ports.SerialPort(); m_SerialPort.PortName = com; m_SerialPort.BaudRate = 115200; //m_SerialPort.BaudRate = 230400; m_SerialPort.DataBits = 8; m_SerialPort.Parity = Parity.None; m_SerialPort.StopBits = StopBits.One; m_SerialPort.Handshake = Handshake.None; //m_SerialPort.Handshake = Handshake.RequestToSend; //m_SerialPort.Handshake = Handshake.XOnXOff; m_SerialPort.ReadTimeout = 500; m_SerialPort.WriteTimeout = 500; try { m_SerialPort.Open(); } catch (Exception e) { MessageBox.Show(e.ToString(),"Error opening COM port",MessageBoxButtons.OK,MessageBoxIcon.Error); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void SendFrame(SubFrame frame) { switch(m_Type) { case HardwareType.USB: SendFrameUSB(frame); break; case HardwareType.Serial: SendFrameSerial(frame); break; } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void SendFrameUSB(SubFrame frame) { uint iBytesWritten = 0; byte[] buffer = frame.ToHardwareByteArray(); m_UsbDevice.Write(ref buffer[0], (uint)buffer.Length, ref iBytesWritten); if (iBytesWritten < buffer.Length) { int i = 12; i++; } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void SendFrameSerial(SubFrame frame) { if (m_SerialPort != null && m_SerialPort.IsOpen) { byte[] buffer = frame.ToHardwareByteArray(); m_SerialPort.Write(buffer, 0, buffer.Length); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Close() { m_SerialPort.Close(); } } } --- NEW FILE: NetworkMessage.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000 { public class NetworkMessage { //////////////////////////////////////////////////////////////////////////////// public int iMessageID; public int iDataSize; public Byte[] data; public const int MID_TEST = -1; public const int MID_DISCONNECT = 1; public const int MID_FRAME = 2; // messages from JellyEars, delivered to port 2056 public const int JELLYEARS_BEAT = 10; // a 'beat' of music has occurred public const int JELLYEARS_7BAND_FREQ = 11; // array of frequency spectrum data public const int JELLYEARS_FULLBAND_FREQ = 12; // array of frequency spectrum data public byte[] ToByteArray() { Byte[] msgBuffer = BitConverter.GetBytes(iMessageID); Byte[] sizeBuffer = BitConverter.GetBytes(iDataSize); int iSendBufferSize; if (iDataSize > 0) iSendBufferSize = msgBuffer.Length + sizeBuffer.Length + data.Length; else iSendBufferSize = msgBuffer.Length + sizeBuffer.Length; Byte[] sendBuffer = new Byte[iSendBufferSize]; //copy the message id in msgBuffer.CopyTo(sendBuffer, 0); //copy the size in sizeBuffer.CopyTo(sendBuffer, 4); //if we have data, add it into the buffer if (iDataSize > 0) { //getting the offset in the buffer to add the data section int iOffset = msgBuffer.Length + sizeBuffer.Length; //copy the actual data in data.CopyTo(sendBuffer, iOffset); } //send the buffer return sendBuffer; } } } --- NEW FILE: JellyTouch12000.csproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: TouchSurface.cs --- using System; using System.Collections.Generic; using System.Text; using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace JellyTouch12000 { //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public class TouchSurface { protected GraphicsDeviceManager m_Graphics = JellyApp.GraphicsManager; protected TouchJixel[,] m_Jixels = null; protected TouchBackground m_Background = null; //TODO: move these to a global class //protected int m_iNumRibs = 36; //protected int m_iNumJixelsPerRib = 10; protected bool m_bMouseDown = false; protected JixelColor m_CurrentColor; //protected Vector3 m_vDiffuse = Vector3(1, 1, 0); //protected BrushType m_BrushType = BrushType.DIAMOND; protected BrushType m_BrushType = BrushType.BOX; public BrushType BrushType { get { return m_BrushType; } } //protected int m_iCurrentJixel = 2; protected string m_Name = null; public string Name { get { return m_Name; } //set { m_Name = value; } } protected JellyApp m_App = null; protected Matrix m_MatWorld; protected Matrix m_MatView; protected Matrix m_MatProj; protected Matrix m_MatWorldViewProj; protected int m_iMouseX = 0; protected int m_iMouseY = 0; //currently this is being used for the point sprite lists protected SpriteBatch m_SpriteBatch = null; //TODO: this might go away? //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public TouchSurface(JellyApp app) { m_Name = "TouchSurfaceBase"; m_App = app; m_Jixels = new TouchJixel[JellyApp.g_iJixelsPerRib,JellyApp.g_iTotalRibs]; InitMatrices(); InitTextures(); InitBackground(); InitJixels(); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void InitJixels() {} //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected void InitTextures() { m_SpriteBatch = new SpriteBatch(m_Graphics.GraphicsDevice); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void InitMatrices() { int iBackBufferHeight = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; int iBackBufferWidth = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; int iHalfHeight = iBackBufferHeight / 2; int iHalfWidth = iBackBufferWidth / 2; //setup the matrices for the hardware m_MatWorld = Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f)); m_MatView = Matrix.CreateLookAt(new Vector3(iHalfWidth, iHalfHeight, 1), new Vector3(iHalfWidth, iHalfHeight, 0.0f), Vector3.Up); m_MatProj = Matrix.CreateOrthographic(1024, -768, 1.0f, 2000.0f); //TODO: get rid of these not-so-magic numbers m_MatWorldViewProj = m_MatWorld * m_MatView * m_MatProj; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void InitBackground() { m_Background = new TouchBackground(m_App); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Render(GameTime gameTime) { m_Background.Render(gameTime); RenderJixels(gameTime); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void RenderJixels(GameTime gameTime) {} //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// protected void UpdateMouse(GameTime gameTime) { int iBackBufferHeight = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight; int iBackBufferWidth = m_Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth; //grab the mouse and pick a jixel MouseState mouseState = Mouse.GetState(); m_iMouseX = (int)MathHelper.Clamp(mouseState.X, 0, iBackBufferWidth - 1); m_iMouseY = (int)MathHelper.Clamp(mouseState.Y, 0, iBackBufferHeight - 1); bool bMouseDown = mouseState.LeftButton == ButtonState.Pressed; if(bMouseDown && !m_bMouseDown) { LBPressed(); } m_bMouseDown = bMouseDown; } protected int m_iBrushRadius = 1; public int BrushRadius { get { return m_iBrushRadius; } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void LBPressed() { } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void UpdateKeyboard(GameTime gameTime) {} //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// virtual protected void UpdateJixels(GameTime gameTime) { Monitor.Enter(this); Monitor.Exit(this); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Update(GameTime gameTime) { UpdateMouse(gameTime); UpdateKeyboard(gameTime); UpdateJixels(gameTime); m_Background.Update(gameTime); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public SubFrame ToSubFrame() { Monitor.Enter(this); KeyFrame keyFrame = new KeyFrame(1); for(int iCurRib = 0; iCurRib < JellyApp.g_iTotalRibs; ++iCurRib) { for(int iCurJixel= 0; iCurJixel < JellyApp.g_iJixelsPerRib; ++iCurJixel) { TouchJixel tJixel = m_Jixels[iCurJixel,iCurRib]; Jixel jixel = keyFrame.GetJixel(iCurRib, iCurJixel); //Rib rib = keyFrame.GetRib(iCurRib); //rib.SetColorBrightness(tJixel.Color, 1.0f); //rib.SetColorBrightness(tJixel.Color, 1.0f); if (tJixel.Color == JixelColor.OFF) { jixel.SetColorBrightness(tJixel.Color, 0.0f); } else { jixel.SetColorBrightness(tJixel.Color, 1.0f); } } } SubFrame subFrame = keyFrame.GenerateSingleSubFrame(); Monitor.Exit(this); return subFrame; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// } } --- NEW FILE: Game.ico --- (This appears to be a binary file; contents omitted.) --- NEW FILE: JellyView.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000 { class JellyView { //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// JellyView() { } } } --- NEW FILE: JellyTouch12000.sln --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Rib.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyTouch12000 { public class Rib { public enum RibDirection { UP = 0, DOWN } public Rib(KeyFrame frame, int ribIndex) { m_RibIndex = ribIndex; m_Frame = frame; } public void SetBrightness(float brightness) { // let's set this brightness across the entire rib!!! for (int i = 0; i < JellyApp.g_iLightsPerRib; i++) { m_Frame.m_Brightness[m_RibIndex, i] = brightness; } } public void SetColorBrightness(JixelColor color, float brightness) { for (int i = 0; i < JellyApp.g_iLightsPerRib; i++) { if (i % JellyApp.g_iColorsPerJixel == (int)color) { m_Frame.m_Brightness[m_RibIndex, i] = brightness; } } } public void SetRowBrightness(int rowIndex, float brightness) { if (rowIndex >= 0 && rowIndex < JellyApp.g_iLightsPerRib) { m_Frame.m_Brightness[m_RibIndex, rowIndex] = 1.0f; } } // simple "default parameter" behavior in C# public void TrailEffect(int startingRowIndex, int length, RibDirection direction) { TrailEffect(startingRowIndex, length, direction, JixelColor.ALL_COLORS, true); } public void TrailEffect(int startingRowIndex, int length, RibDirection direction, JixelColor color, bool decreaseBrightness) { float brightnessDelta = 1.0f / length; float currentBrightness = 1.0f; int currentIndex = startingRowIndex; for (int i = 0; i < length; i++) { int correctedRowIndex = (currentIndex + JellyApp.g_iLightsPerRib) % JellyApp.g_iLightsPerRib; if (color == JixelColor.ALL_COLORS || correctedRowIndex % JellyApp.g_iColorsPerJixel == (int)color) { m_Frame.m_Brightness[m_RibIndex, correctedRowIndex] = currentBrightness; } if (direction == RibDirection.UP) { currentIndex--; } else { currentIndex++; } // for some animations, we won't want to decrease the brightness for a 'gradiant' effect if (decreaseBrightness) { currentBrightness -= brightnessDelta; } // let's clamp it in case currentBrightness = JellyApp.ClampBrightness(currentBrightness); } } private int m_RibIndex; private KeyFrame m_Frame; } } --- NEW FILE: MessageServer.cs --- using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Threading; using System.Net; using System.Net.Sockets; namespace JellyTouch12000 { class MessageServer { private int m_port; private TcpListener m_Listener; private Socket m_Socket = null; private string m_HostName = Dns.GetHostName(); private Byte[] m_byReceiveBuffer = new Byte[4096]; public Queue m_ReceiveBuffers = new Queue(); private ArrayList m_Messages = new ArrayList(); private Thread m_Thread = null; private int m_unknownMessageCount = 0; public bool IsConnected { get { if (JellyApp.m_useUdp) return true; // UDP is connectionless else if (m_Socket != null) { return m_Socket.Connected; } return false; } } ////////////////////////////////////////////////////////////////////////// // Callbacks public delegate void ConnectionDelegate(); public delegate void FrameReceivedDelegate(byte[] frameData); public ConnectionDelegate _connected; public FrameReceivedDelegate _frameRecieved; //public ConnectionDelegate _disconnected; //public FrameAvailableDelegate _frameAvailable; //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public MessageServer(int port) { m_port = port; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Start() { //start the thread to look for connections m_Thread = new Thread(new ThreadStart(Service)); m_Thread.Name = "FrameServer"; m_Thread.Start(); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Stop() { //kill the main server thread try { if (m_Thread.IsAlive) { //SendDisconnect() m_Thread.Abort(); } } catch (ThreadAbortException e) { Console.WriteLine("Properly Caught thread abort exception\n{0}", e.ToString()); } catch (Exception e) { Console.WriteLine(e.ToString()); } } /////////////////////////////////////////////////////////////////////////// // the connection thread /////////////////////////////////////////////////////////////////////////// private void Service() { try { IPHostEntry ipEntry = Dns.GetHostEntry(m_HostName); m_Listener = new TcpListener(ipEntry.AddressList[0], m_port); m_Listener.Start(); if (JellyApp.m_useUdp) { // listen for UDP packets on port specified in constructor UdpClient m_UdpClient = new UdpClient(m_port); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); while (true) { // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = m_UdpClient.Receive(ref RemoteIpEndPoint); //add the received bytes to the packet buffer Array.Copy(receiveBytes, 0, m_byReceiveBuffer, 0, receiveBytes.Length); QueueReceivedData(receiveBytes.Length); //process queued messages HandleMessages(); } } else { //Look for a TCP connection while (m_Socket == null || !m_Socket.Connected) { if (m_Listener.Pending()) { //accept the pending socket connection m_Socket = m_Listener.AcceptSocket(); if (m_Socket.Connected) { if (_connected != null) { _connected(); } } } else { Thread.Sleep(1000); } } SetupReceiveCallback(); //we're connected so now we can start looking for data while (m_Socket.Connected) { HandleMessages(); //Thread.Sleep(10); } Console.WriteLine("Disconnected"); } } catch (Exception e) { //this is fatal! Console.WriteLine(e.ToString()); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void HandleMessages() { bool bSuccess = AssembleMessages(); if (bSuccess) { try { Monitor.Enter(this); foreach (NetworkMessage nm in m_Messages) { //NetworkMessage nm = (NetworkMessage)obj; switch (nm.iMessageID) { case NetworkMessage.MID_DISCONNECT: HandleDisconnect(); break; case NetworkMessage.MID_FRAME: HandleFrameMessage(nm); break; case NetworkMessage.MID_TEST: HandleTest(); break; case NetworkMessage.JELLYEARS_BEAT: Console.WriteLine("JellyEars BEAT msg"); break; case NetworkMessage.JELLYEARS_7BAND_FREQ: //Console.WriteLine("JellyEars 7 BAND FREQ msg"); { // stuff the data in our global storage for (int i = 0; i < 7; i++) { JellyApp.g_SevenBandSpectrum[i] = BitConverter.ToInt32(nm.data, i * 4); // find the current max peak if (JellyApp.g_SevenBandSpectrum[i] > JellyApp.g_SevenBandSpectrumPeak) JellyApp.g_SevenBandSpectrumPeak = JellyApp.g_SevenBandSpectrum[i]; } } break; case NetworkMessage.JELLYEARS_FULLBAND_FREQ: //Console.WriteLine("JellyEars FULL BAND FREQ msg"); { // resize, if necessary int dataSize = nm.data.Length / 4; int fullSpectrumSize = JellyApp.g_FullSpectrum.Length; if (dataSize != fullSpectrumSize) JellyApp.g_FullSpectrum = new int[dataSize]; // stuff the data in our global storage for (int i = 0; i < fullSpectrumSize; i++) { JellyApp.g_FullSpectrum[i] = BitConverter.ToInt32(nm.data, i * 4); // find the current max peak if (JellyApp.g_FullSpectrum[i] > JellyApp.g_FullSpectrumPeak) JellyApp.g_FullSpectrumPeak = JellyApp.g_FullSpectrum[i]; } } break; default: String msg; msg = "Unknown NetworkMessage ID: "; msg += nm.iMessageID; msg += " (unknown msgs: "; msg += ++m_unknownMessageCount; msg += ")"; Console.WriteLine(msg); break; } } //if (m_Messages.Count > 0) { ResetTimeWithoutMessage(); } m_Messages.Clear(); } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { Monitor.Exit(this); } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void HandleFrameMessage(NetworkMessage nm) { if (_frameRecieved != null) _frameRecieved(nm.data); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void HandleDisconnect() { m_Socket.Disconnect(false); m_Socket.Close(); } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private void HandleTest() { } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private NetworkMessage MessageBufferToNetworkMessage(Byte[] buffer) { NetworkMessage nm = new NetworkMessage(); nm.iMessageID = GetMessageID(buffer); nm.iDataSize = GetDataSize(buffer); //copy the actual data in nm.data = new Byte[nm.iDataSize]; Array.Copy(buffer, 8, nm.data, 0, nm.iDataSize); return nm; } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// private bool AssembleMessages() { bool bSuccess = true; try { Monitor.Enter(this); //thread safety int iTotalBufferSize = 0; int iOffset = 0; Byte[] AllMessageBuffer = null; Byte[] shrinkingBuffer = null; bool bDone = false; int iBuffers = m_ReceiveBuffers.Count; int iMessageSize = 0; //Bail out early if there are no recv buffers available if (iBuffers != 0) { //get the size of all the network packets foreach (Object obj in m_ReceiveBuffers) { Byte[] localObj = (Byte[])obj; iTotalBufferSize += localObj.Length; } //create a buffer big enough to hold all the messages AllMessageBuffer = new Byte[iTotalBufferSize]; AllMessageBuffer.Initialize(); //make sure we have atleast 8 bytes; necessary to get message ID and datasize bool bOkToProcess = false; if (iTotalBufferSize >= 8) { iMessageSize = GetDataSize(AllMessageBuffer) + 8; if (AllMessageBuffer.Length >= iMessageSize) { bOkToProcess = true; } } if (bOkToProcess) { //copy all the buffers into the huge buffer for (int i = 0; i < iBuffers; i++) { Byte[] recvBuffer = (Byte[])m_ReceiveBuffers.Dequeue(); Array.Copy(recvBuffer, 0, AllMessageBuffer, iOffset, recvBuffer.Length); iOffset += recvBuffer.Length; } //run through the huge buffer and get out each packet while (!bDone) { iOffset = 0; iMessageSize = GetDataSize(AllMessageBuffer) + 8; Byte[] messageBuffer = new Byte[iMessageSize]; //if the remaining buffer is long enough to contain // this whole message copy it in, and then dance. if (AllMessageBuffer.Length >= iMessageSize) { Array.Copy(AllMessageBuffer, 0, messageBuffer, 0, iMessageSize); iOffset = iMessageSize; NetworkMessage nm = MessageBufferToNetworkMessage(messageBuffer); m_Messages.Add(nm); if (AllMessageBuffer.Length - iMessageSize > 0) { shrinkingBuffer = new Byte[AllMessageBuffer.Length - iOffset]; Array.Copy(AllMessageBuffer, iOffset, shrinkingBuffer, 0, shrinkingBuffer.Length); AllMessageBuffer = new Byte[shrinkingBuffer.Length]; AllMessageBuffer.Initialize(); Array.Copy(shrinkingBuffer, 0, AllMessageBuffer, 0, shrinkingBuffer.Length); } else { bDone = true; } } else { bDone = true; } } //if anything is left over, re-queue it and leave if (AllMessageBuffer.Length != iMessageSize) { //this won't work if the queue has changed in the mean time Queue localQueue = new Queue(m_ReceiveBuffers.Count + 1); //add our remaining buffer on first localQueue.Enqueue(AllMessageBuffer); //now add all of what's in the ReceiveBuffers queue on top while (m_ReceiveBuffers.Count > 0) { Byte[] localBytes = (Byte[])m_ReceiveBuffers.Dequeue(); localQueue.Enqueue(localBytes); } //copy the new queue into the ReceiveBuffers queue while (localQueue.Count > 0) { m_ReceiveBuffers.Enqueue(localQueue.Dequeue()); } } } else { } } } catch (NullReferenceException nre) { Console.WriteLine(nre.ToString()); m_Messages.Clear(); bSuccess = false; } catch (Exception e) { Console.WriteLine(e.ToString()); bSuccess = false; } finally { //Console.WriteLine("{0} message built in AssembleMessages();",m_Messages.Count); Monitor.Exit(this); } return bSuccess; } ... [truncated message content] |
From: Jeremy <mh...@us...> - 2008-08-19 04:37:48
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Transitions In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv26243/Transitions Log Message: Directory /cvsroot/jellyfish12000/CVSROOT/JellyTouch12000/Transitions added to the repository |
From: NickS <nsc...@us...> - 2008-08-17 06:14:06
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv4306 Modified Files: ProximityDetectors.cs Log Message: many improvement, mostly in data smoothing, and cleaner coding Index: ProximityDetectors.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/ProximityDetectors.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProximityDetectors.cs 16 Aug 2008 06:44:34 -0000 1.3 --- ProximityDetectors.cs 17 Aug 2008 06:13:32 -0000 1.4 *************** *** 8,30 **** public class ProximityDetectors { private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! private const int m_numDetectors = 2; private int m_ribsPerDetector = JellyBrain.g_iTotalRibs / m_numDetectors; ! // buffer readings and average, to smooth jumpiness ! private const int m_bufferSize = 10; private Int32[][] m_rangeBuffer = new Int32[m_numDetectors][]; private Int32[] m_rangeBufferPtr = new Int32[m_numDetectors]; private Int32[] m_rangeAvg = new Int32[m_numDetectors]; ! // defines the maximum distance, in inches, that we consider ! // a valid range detection. anything over this value will set the ! // 'detected' range to -1, which means JellyBrain will ignore it. ! private const Int32 m_maxRangeThreshold = 144; ! private const Int32 m_minRange = 6; // detectors dont go lower than this ! public void Init() { --- 8,58 ---- public class ProximityDetectors { + /* configurables: + * - com port numbers, + * - number of sonar detectors, + * - number of range-readings to keep in a buffer for averaging (to smooth) + * - max percent change that is allowed from reading to reading (clamped) + * - max range reading, in inches, beyond which readings should be ignored + * - min range reading, in inches, within which we consider maximally close + */ + private const string m_SerialPortA_name = "COM6"; + private const string m_SerialPortB_name = "COM7"; + private const string m_SerialPortC_name = "COM8"; + private const string m_SerialPortD_name = "COM9"; + + private const int m_numDetectors = 4; + private const int m_bufferSize = 8; + + private const float m_maxDelta = 0.5f; + + private const Int32 m_maxRange = 96; // inches + private const Int32 m_minRange = 30; // inches + + + private bool m_printRawData = false; + private bool m_printRange = false; + private bool m_printAvgRange = false; + + // serial ports talk to either the Maxbotics controllers, + // or to the devices themselves private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); + private SerialPort m_SerialPortC = new System.IO.Ports.SerialPort(); + private SerialPort m_SerialPortD = new System.IO.Ports.SerialPort(); ! // we need to associate a detector to X number of ribs private int m_ribsPerDetector = JellyBrain.g_iTotalRibs / m_numDetectors; ! // buffer range-readings and average, to smooth jumpiness private Int32[][] m_rangeBuffer = new Int32[m_numDetectors][]; private Int32[] m_rangeBufferPtr = new Int32[m_numDetectors]; private Int32[] m_rangeAvg = new Int32[m_numDetectors]; ! // simple data protection of JellyBrain global rib detect values ! private bool m_dataLocked = false; + //////////////////////////////////////////////////////////////////////////////// + // + //////////////////////////////////////////////////////////////////////////////// public void Init() { *************** *** 32,38 **** { m_rangeBuffer[detector] = new Int32[m_bufferSize]; } ! this.InitSerialPort(m_SerialPortA, "COM8", DataReceivedPortA); ! this.InitSerialPort(m_SerialPortB, "COM9", DataReceivedPortB); } --- 60,74 ---- { m_rangeBuffer[detector] = new Int32[m_bufferSize]; + for (int i = 0; i < m_bufferSize; i++) + { + m_rangeBuffer[detector][i] = m_maxRange; + } + m_rangeBufferPtr[detector] = 0; + m_rangeAvg[detector] = m_maxRange; } ! this.InitSerialPort(m_SerialPortA, m_SerialPortA_name, DataReceivedPortA); ! this.InitSerialPort(m_SerialPortB, m_SerialPortB_name, DataReceivedPortB); ! this.InitSerialPort(m_SerialPortC, m_SerialPortC_name, DataReceivedPortC); ! this.InitSerialPort(m_SerialPortD, m_SerialPortD_name, DataReceivedPortD); } *************** *** 61,65 **** { Console.WriteLine(e.ToString()); - port.Close(); } } --- 97,100 ---- *************** *** 76,79 **** --- 111,122 ---- DataReceived(m_SerialPortB, 'B'); } + void DataReceivedPortC(object sender, SerialDataReceivedEventArgs e) + { + DataReceived(m_SerialPortC, 'C'); + } + void DataReceivedPortD(object sender, SerialDataReceivedEventArgs e) + { + DataReceived(m_SerialPortD, 'D'); + } void DataReceived(SerialPort port, char portName) *************** *** 81,127 **** try { ! //read data waiting in the buffer ! string dataStr = port.ReadLine(); ! //Console.WriteLine(str); ! // parse out the data (super simple!) ! if (dataStr.Length == 4) { ! char[] cRange = dataStr.ToCharArray(); ! if (cRange[0] == 'R') { ! char[] trimChars = { 'R' }; ! string sRange = dataStr.TrimStart(trimChars); ! Int32 range = Int32.Parse(sRange); ! //Console.WriteLine(range); ! // keep a running average, to try to smooth-out ! // the jumpiness in the readings ! int detectorNum=0; ! switch (portName) ! { ! case 'A': ! detectorNum = 0; ! break; ! case 'B': ! detectorNum = 1; ! break; ! default: ! break; ! } ! if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) ! { ! m_rangeBufferPtr[detectorNum] = 0; ! } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) ! { ! sum += m_rangeBuffer[detectorNum][i]; ! } ! m_rangeAvg[detectorNum] = sum / m_bufferSize; } } ! // else Console.WriteLine(str.Length); // update the JellyBrain rib proximity detect values with --- 124,234 ---- try { ! //read a newline-terminated string of data waiting in the device buffer ! string sData = port.ReadLine(); ! char[] caData = sData.ToCharArray(); ! if (m_printRawData) Console.WriteLine(sData); ! Int32 range = -1; // the range-reading, in inches, read from a detector ! int detectorNum = -1; // the detector from which the reading was read ! ! // if the first char of the line of data received on the serial ! // port begins with 'R', then that means we are receiving data directly ! // from a detector ! if ((sData.Length == 4) && (caData[0] == 'R')) { ! char[] trimChars = { 'R' }; ! string sRange = sData.TrimStart(trimChars); ! try { ! range = Int32.Parse(sRange); ! if (range == 255) return; // this is an invalid reading ! } ! catch ! { ! //Console.WriteLine(sRange); ! return; // ignore crap reading ! } ! // figure-out which detector ! switch (portName) ! { ! case 'A': ! detectorNum = 0; ! break; ! case 'B': ! detectorNum = 1; ! break; ! case 'C': ! detectorNum = 2; ! break; ! case 'D': ! detectorNum = 3; ! break; ! default: ! return; } } ! else ! { ! Console.WriteLine(sData); ! return; ! } ! ! // threshold readings beyond our defined max, and within defined min ! if (range > m_maxRange) range = m_maxRange; ! if (range < m_minRange) range = m_minRange; ! ! // readings can fluctuate wilding from reading to reading if there ! // are very small objects around. to alleviate this, clamp large ! // percent changes from the current average reading ! int avgRange = m_rangeAvg[detectorNum]; ! int minFromAvg = avgRange - (int)(m_maxDelta * (float)avgRange); ! if (range < minFromAvg) ! { ! range = minFromAvg; ! } ! int maxFromAvg = (int)(m_maxDelta * (float)avgRange) + avgRange; ! if (range > maxFromAvg) ! { ! range = maxFromAvg; ! } ! ! if (m_printRange) Console.WriteLine(range); ! ! // for this detector range reading, keep a running average, in order ! // to smooth-out the jumpiness in the readings ! if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) ! { // manage circular buffer index ! m_rangeBufferPtr[detectorNum] = 0; ! } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) ! { ! sum += m_rangeBuffer[detectorNum][i]; ! } ! m_rangeAvg[detectorNum] = sum / m_bufferSize; ! if (m_printAvgRange) Console.WriteLine(m_rangeAvg[detectorNum]); ! ! } ! catch (Exception e) ! { ! Console.WriteLine(e.ToString()); ! } ! ! // now update the rib lighting based on the detector values ! // use a simple synchronization lock, since this DataReceived routine ! // can be executed concurrently by multiple ports ! if ( ! m_dataLocked) this.UpdateRibRangeDetectValues(); ! } ! ! //////////////////////////////////////////////////////////////////////////////// ! // ! //////////////////////////////////////////////////////////////////////////////// ! private void UpdateRibRangeDetectValues() ! { ! try ! { ! m_dataLocked = true; // simple data protection of JellyBrain global // update the JellyBrain rib proximity detect values with *************** *** 137,162 **** for (int detector = 0; detector < m_numDetectors; detector++) { ! if ((m_rangeAvg[detector] > 0) && ! (m_rangeAvg[detector] < m_maxRangeThreshold)) { ! int startRib = detector * m_ribsPerDetector; ! int endRib = startRib + m_ribsPerDetector; ! for (int i = startRib; i < endRib; i++) { ! if (m_rangeAvg[detector] <= m_minRange) ! { ! JellyBrain.g_RibRangeDetect[i] = 1; ! } ! else ! { ! JellyBrain.g_RibRangeDetect[i] = ! (float)1 - ((float)m_rangeAvg[detector] / ! (float)m_maxRangeThreshold); ! } ! //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); } } } } catch (Exception e) --- 244,268 ---- for (int detector = 0; detector < m_numDetectors; detector++) { ! int startRib = detector * m_ribsPerDetector; ! int endRib = startRib + m_ribsPerDetector; ! for (int i = startRib; i < endRib; i++) { ! // if range-reading is within our defined min zone, ! // then consider it a maximal reading ! if (m_rangeAvg[detector] <= m_minRange) { ! JellyBrain.g_RibRangeDetect[i] = (float)0.99; ! } ! else // scale 0 to 1, using maxRange as a threshold ! { ! JellyBrain.g_RibRangeDetect[i] = ! (float)1 - ((float)m_rangeAvg[detector] / ! (float)m_maxRange); //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); } } } + + m_dataLocked = false; } catch (Exception e) |
From: NickS <nsc...@us...> - 2008-08-17 06:12:29
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv3866 Modified Files: RibProximityDetect.cs Log Message: minor cleanup Index: RibProximityDetect.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/RibProximityDetect.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RibProximityDetect.cs 14 Aug 2008 06:05:09 -0000 1.1 --- RibProximityDetect.cs 17 Aug 2008 06:12:24 -0000 1.2 *************** *** 26,33 **** { if (JellyBrain.g_RibRangeDetect[rib] == 0.0) continue; ! int maxRow = (int)(JellyBrain.g_RibRangeDetect[rib] * JellyBrain.g_iLightsPerRib); if (maxRow >= JellyBrain.g_iLightsPerRib) continue; for (int row = 0; row <= maxRow; row++) - //trying to light from bottom-up: //for (int row = JellyBrain.g_iLightsPerRib-1; row > maxRow; row--) { keyframe.m_Brightness[rib, row] = 1.0f; --- 26,33 ---- { if (JellyBrain.g_RibRangeDetect[rib] == 0.0) continue; ! int maxRow = (int)(JellyBrain.g_RibRangeDetect[rib] * ! JellyBrain.g_iLightsPerRib); if (maxRow >= JellyBrain.g_iLightsPerRib) continue; for (int row = 0; row <= maxRow; row++) { keyframe.m_Brightness[rib, row] = 1.0f; |
From: NickS <nsc...@us...> - 2008-08-16 06:44:41
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv19413 Modified Files: ProximityDetectors.cs Log Message: supports an arbitrary number of detectors; determines ribs per detector; tested and works with two detectors (each controlling 18 ribs). Index: ProximityDetectors.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/ProximityDetectors.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ProximityDetectors.cs 14 Aug 2008 06:05:07 -0000 1.2 --- ProximityDetectors.cs 16 Aug 2008 06:44:34 -0000 1.3 *************** *** 11,29 **** private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); // defines the maximum distance, in inches, that we consider // a valid range detection. anything over this value will set the // 'detected' range to -1, which means JellyBrain will ignore it. private const Int32 m_maxRangeThreshold = 144; - private const Int32 m_minRange = 6; // detectors dont go lower than this - private Int32[] m_rangeBuffer = new Int32[10]; - private int m_rangeBufferPtr = 0; - private Int32 m_rangeAvg; public void Init() { ! this.InitSerialPort(m_SerialPortA, "COM4", DataReceivedPortA); ! this.InitSerialPort(m_SerialPortB, "COM5", DataReceivedPortB); } --- 11,38 ---- private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); + private const int m_numDetectors = 2; + private int m_ribsPerDetector = JellyBrain.g_iTotalRibs / m_numDetectors; + + // buffer readings and average, to smooth jumpiness + private const int m_bufferSize = 10; + private Int32[][] m_rangeBuffer = new Int32[m_numDetectors][]; + private Int32[] m_rangeBufferPtr = new Int32[m_numDetectors]; + private Int32[] m_rangeAvg = new Int32[m_numDetectors]; + // defines the maximum distance, in inches, that we consider // a valid range detection. anything over this value will set the // 'detected' range to -1, which means JellyBrain will ignore it. private const Int32 m_maxRangeThreshold = 144; private const Int32 m_minRange = 6; // detectors dont go lower than this public void Init() { ! for (int detector = 0; detector < m_numDetectors; detector++) ! { ! m_rangeBuffer[detector] = new Int32[m_bufferSize]; ! } ! this.InitSerialPort(m_SerialPortA, "COM8", DataReceivedPortA); ! this.InitSerialPort(m_SerialPortB, "COM9", DataReceivedPortB); } *************** *** 61,72 **** void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortA); } void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB); } ! void DataReceived(SerialPort port) { try --- 70,81 ---- void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortA, 'A'); } void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortB, 'B'); } ! void DataReceived(SerialPort port, char portName) { try *************** *** 89,103 **** // keep a running average, to try to smooth-out // the jumpiness in the readings ! if (++m_rangeBufferPtr == m_rangeBuffer.Length) { ! m_rangeBufferPtr = 0; } ! m_rangeBuffer[m_rangeBufferPtr] = range; Int32 sum = 0; ! for (int i = 0; i < m_rangeBuffer.Length; i++) { ! sum += m_rangeBuffer[i]; } ! m_rangeAvg = sum / m_rangeBuffer.Length; } } --- 98,124 ---- // keep a running average, to try to smooth-out // the jumpiness in the readings ! int detectorNum=0; ! switch (portName) { ! case 'A': ! detectorNum = 0; ! break; ! case 'B': ! detectorNum = 1; ! break; ! default: ! break; } ! if (++m_rangeBufferPtr[detectorNum] == m_bufferSize) ! { ! m_rangeBufferPtr[detectorNum] = 0; ! } ! m_rangeBuffer[detectorNum][m_rangeBufferPtr[detectorNum]] = range; Int32 sum = 0; ! for (int i = 0; i < m_bufferSize; i++) { ! sum += m_rangeBuffer[detectorNum][i]; } ! m_rangeAvg[detectorNum] = sum / m_bufferSize; } } *************** *** 114,132 **** } ! if ((m_rangeAvg > 0) && (m_rangeAvg < m_maxRangeThreshold)) { ! for (int i = 0; i < JellyBrain.g_iTotalRibs; i++) { ! if (m_rangeAvg <= m_minRange) ! { ! JellyBrain.g_RibRangeDetect[i] = 1; ! } ! else { ! JellyBrain.g_RibRangeDetect[i] = ! (float)1 - ((float)m_rangeAvg / (float)m_maxRangeThreshold); ! } ! //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); } } --- 135,160 ---- } ! for (int detector = 0; detector < m_numDetectors; detector++) { ! if ((m_rangeAvg[detector] > 0) && ! (m_rangeAvg[detector] < m_maxRangeThreshold)) { ! int startRib = detector * m_ribsPerDetector; ! int endRib = startRib + m_ribsPerDetector; ! for (int i = startRib; i < endRib; i++) { ! if (m_rangeAvg[detector] <= m_minRange) ! { ! JellyBrain.g_RibRangeDetect[i] = 1; ! } ! else ! { ! JellyBrain.g_RibRangeDetect[i] = ! (float)1 - ((float)m_rangeAvg[detector] / ! (float)m_maxRangeThreshold); ! } ! //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); ! } } } |
From: NickS <nsc...@us...> - 2008-08-14 06:12:16
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyEars In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv6465 Modified Files: Beater.cpp Beater.h Control.cpp Control.h JellyEars.exe JellyEars.sln Painter.cpp Painter.h Views.cpp Views.h Log Message: updates in attempting software beat detection Index: Control.h =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Control.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Control.h 4 Jun 2008 03:10:19 -0000 1.6 --- Control.h 14 Aug 2008 06:12:12 -0000 1.7 *************** *** 41,74 **** private: ! HWND _hWnd; ! HINSTANCE _hInst; ! CurrentDir _currentDir; ! bool _isStopped; ! unsigned _bitsPerSample; ! unsigned _samplesPerSecond; ! unsigned _fftPoints; ! unsigned _samplesPerBuf; // nicks ! unsigned _buffersToSkip; ! unsigned _windowDivider; ! int _bpm; ! int _bpm_latency; ! Win::Button _buttonStart; ! Win::Button _buttonAbout; ! Win::EditReadOnly _edit_ffts_per_sec; ! Win::Combo _comboFreq; ! Win::Combo _comboPoints; ! Win::RadioButton _radio8; ! Win::RadioButton _radio16; Win::ScrollBarMap _scroll_fft_skips; ! Win::RadioButton _mike; ! Win::RadioButton _wave; ! Win::RadioButton _image; ! Win::Button _buttonFile; ! Win::Combo _editFile; Painter _painter; --- 41,74 ---- private: ! HWND _hWnd; ! HINSTANCE _hInst; ! CurrentDir _currentDir; ! bool _isStopped; ! unsigned _bitsPerSample; ! unsigned _samplesPerSecond; ! unsigned _fftPoints; ! unsigned _samplesPerBuf; // nicks ! unsigned _buffersToSkip; ! unsigned _windowDivider; ! int _bpm; ! int _bpm_latency; ! Win::Button _buttonStart; ! Win::Button _buttonAbout; ! Win::EditReadOnly _edit_ffts_per_sec; ! Win::Combo _comboFreq; ! Win::Combo _comboPoints; ! Win::RadioButton _radio8; ! Win::RadioButton _radio16; Win::ScrollBarMap _scroll_fft_skips; ! Win::RadioButton _mike; ! Win::RadioButton _wave; ! Win::RadioButton _image; ! Win::Button _buttonFile; ! Win::Combo _editFile; Painter _painter; Index: Painter.cpp =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Painter.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Painter.cpp 4 Jun 2008 03:10:20 -0000 1.9 --- Painter.cpp 14 Aug 2008 06:12:12 -0000 1.10 *************** *** 121,125 **** // nicks _fftTransformer->SetCompressionOnOffState ! (_viewSevenBandActive || _sevenBandSendActive); } catch (Win::Exception e) --- 121,128 ---- // nicks _fftTransformer->SetCompressionOnOffState ! (_viewSevenBandActive || _sevenBandSendActive); ! ! _fftTransformer->SetBeatDetectionOnOffState ! (_beatDetectorActive); } catch (Win::Exception e) *************** *** 242,246 **** _fftTransformer->SetCompressionOnOffState ! (GetSevenBandViewActive() || GetSevenBandSendActive()); } if (++_bufferCounter > _buffersToSkip) --- 245,252 ---- _fftTransformer->SetCompressionOnOffState ! (GetSevenBandViewActive() || GetSevenBandSendActive()); ! ! _fftTransformer->SetBeatDetectionOnOffState ! (_beatDetectorActive); } if (++_bufferCounter > _buffersToSkip) Index: Control.cpp =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Control.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Control.cpp 4 Jun 2008 03:10:19 -0000 1.10 --- Control.cpp 14 Aug 2008 06:12:12 -0000 1.11 *************** *** 34,37 **** --- 34,39 ---- }; + + BOOL CALLBACK AboutDlgProc (HWND hwnd, UINT message, UINT wParam, LPARAM lParam) *************** *** 101,108 **** _bitsPerSample (16), _samplesPerSecond (Wave::BASE_SAMPLES_SEC), ! _fftPoints (FFT_POINTS * 4), _samplesPerBuf (_fftPoints), _painter (hwnd), ! _beater (hwnd, _painter.GetJellyBrain()) // nicks beat detector { // Attach icon to main dialog --- 103,110 ---- _bitsPerSample (16), _samplesPerSecond (Wave::BASE_SAMPLES_SEC), ! _fftPoints (FFT_POINTS * 2), // default 512 points in the FFT _samplesPerBuf (_fftPoints), _painter (hwnd), ! _beater (hwnd, &_painter) // nicks beat detector { // Attach icon to main dialog *************** *** 134,138 **** _radioWD4.UnCheck (); ! _waveView.UnCheck(); _painter.SetWaveViewActive (_waveView.IsChecked()); --- 136,140 ---- _radioWD4.UnCheck (); ! _waveView.Check(); _painter.SetWaveViewActive (_waveView.IsChecked()); *************** *** 145,149 **** _edit_bpm.SetNumber(_bpm); ! _sevenBandSend.UnCheck (); // enable sending 7-band spectrum data packets _painter.SetSevenBandSendActive(_sevenBandSend.IsChecked()); --- 147,151 ---- _edit_bpm.SetNumber(_bpm); ! _sevenBandSend.Check (); // enable sending 7-band spectrum data packets _painter.SetSevenBandSendActive(_sevenBandSend.IsChecked()); *************** *** 178,183 **** _comboPoints.AddValue (8 * FFT_POINTS); // 3 _comboPoints.AddValue (16 * FFT_POINTS); // 4 ! assert (_fftPoints == 4 * FFT_POINTS); ! _comboPoints.SelectPos (2); // 4 * FFT_POINTS _painter.SetFormat (_samplesPerBuf, _samplesPerSecond, --- 180,185 ---- _comboPoints.AddValue (8 * FFT_POINTS); // 3 _comboPoints.AddValue (16 * FFT_POINTS); // 4 ! assert (_fftPoints == 2 * FFT_POINTS); ! _comboPoints.SelectPos (1); // 4 * FFT_POINTS _painter.SetFormat (_samplesPerBuf, _samplesPerSecond, *************** *** 196,199 **** --- 198,203 ---- } + + void DlgController::UpdateControls () { Index: Beater.h =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Beater.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Beater.h 4 Jun 2008 03:10:19 -0000 1.3 --- Beater.h 14 Aug 2008 06:12:12 -0000 1.4 *************** *** 5,13 **** #include "WinEx.h" #include "JellyBrain.h" class Beater: public ActiveObject { public: ! Beater (HWND hwndOwner, JellyBrain* jellyBrain); ~Beater (); --- 5,14 ---- #include "WinEx.h" #include "JellyBrain.h" + #include "Painter.h" class Beater: public ActiveObject { public: ! Beater (HWND hwndOwner, Painter* painter); ~Beater (); *************** *** 31,35 **** Win::Event _event; ! JellyBrain* _jellyBrain; int _tsecCounter; --- 32,37 ---- Win::Event _event; ! Painter* _painter; ! JellyBrain* _jellyBrain; int _tsecCounter; Index: Painter.h =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Painter.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Painter.h 4 Jun 2008 03:10:20 -0000 1.9 --- Painter.h 14 Aug 2008 06:12:12 -0000 1.10 *************** *** 126,134 **** bool GetBeatDetectorActive() { ! return _fftTransformer->GetBeatDetectionOnOffState(); } void SetBeatDetectorActive(bool state) { ! _fftTransformer->SetBeatDetectionOnOffState(state); } --- 126,138 ---- bool GetBeatDetectorActive() { ! return _beatDetectorActive; } void SetBeatDetectorActive(bool state) { ! _beatDetectorActive = state; ! } ! bool BeatDetected() ! { ! return _fftTransformer->BeatDetected(); } *************** *** 179,182 **** --- 183,187 ---- bool _sevenBandSendActive; bool _fullBandSendActive; + bool _beatDetectorActive; }; Index: JellyEars.exe =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/JellyEars.exe,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 Binary files /tmp/cvseks1bT and /tmp/cvsMTXKKD differ Index: Views.h =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Views.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Views.h 4 Jun 2008 03:10:20 -0000 1.4 --- Views.h 14 Aug 2008 06:12:12 -0000 1.5 *************** *** 41,44 **** --- 41,46 ---- int _points2; // Half the number of points = max freq int _point1kHz; // Point corresponding to 1kHz + + int _peak; }; Index: JellyEars.sln =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/JellyEars.sln,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JellyEars.sln 8 Jul 2007 22:34:50 -0000 1.1 --- JellyEars.sln 14 Aug 2008 06:12:12 -0000 1.2 *************** *** 10,15 **** EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution ! {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Debug|Win32.ActiveCfg = Debug|Win32 ! {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Debug|Win32.Build.0 = Debug|Win32 {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Release|Win32.ActiveCfg = Release|Win32 {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Release|Win32.Build.0 = Release|Win32 --- 10,15 ---- EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution ! {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Debug|Win32.ActiveCfg = Release|Win32 ! {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Debug|Win32.Build.0 = Release|Win32 {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Release|Win32.ActiveCfg = Release|Win32 {1E255492-CB39-49ED-BF7D-2FAE0C7EEA81}.Release|Win32.Build.0 = Release|Win32 Index: Views.cpp =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Views.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Views.cpp 4 Jun 2008 03:10:20 -0000 1.6 --- Views.cpp 14 Aug 2008 06:12:12 -0000 1.7 *************** *** 53,57 **** _xRecord (SCALE_WIDTH + 1), _points2 (0), ! _point1kHz (0) { HINSTANCE hInst = --- 53,58 ---- _xRecord (SCALE_WIDTH + 1), _points2 (0), ! _point1kHz (0), ! _peak (0) { HINSTANCE hInst = *************** *** 191,202 **** } int pts = fftTransformer.Points(); for (int i = 0; i < pts; i++ ) { ! int s = static_cast<int> (fftTransformer.GetIntensity(i)) / 128; ! if (s > 8) { COLORREF color = MapColor (s); canvas.Point (_xRecord, _height - i - 1, color); --- 192,213 ---- } + size_t colorRange = sizeof(ColorScale); int pts = fftTransformer.Points(); for (int i = 0; i < pts; i++ ) { ! #if 0 ! int s = static_cast<int> (fftTransformer.GetIntensity(i)) / 128; if (s > 8) { COLORREF color = MapColor (s); + #else + //int s = static_cast<int> (fftTransformer.GetIntensity(i)); + int s = static_cast<int> (fftTransformer.GetDegreeOfOnset(i)); + if (s > 100) + { + if (s > _peak) _peak = s; + float scalar = (float)s / (float)_peak; + COLORREF color = ColorScale[int(scalar * colorRange)]; + #endif canvas.Point (_xRecord, _height - i - 1, color); *************** *** 206,210 **** --- 217,223 ---- _xRecord += 2; if (_xRecord >= _width) + { _xRecord = SCALE_WIDTH + 1; + } // Draw vertical mark Index: Beater.cpp =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Beater.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Beater.cpp 4 Jun 2008 03:10:19 -0000 1.3 --- Beater.cpp 14 Aug 2008 06:12:11 -0000 1.4 *************** *** 4,11 **** #include "Beater.h" ! Beater::Beater (HWND hwndOwner, JellyBrain* jellyBrain) : _hwnd (hwndOwner), ! _jellyBrain (jellyBrain) { _event.Block (); _thread.Resume (); --- 4,43 ---- #include "Beater.h" ! ! HMIDIIN _midiBeatXtractor; ! UCHAR _midiErrStr[2048]; ! DWORD _midiLastTimecode; ! DWORD _midiTimecodeDelta; ! int _midiSyncCodeCounter=0; ! int _midiBPM; ! JellyBrain* _gJellyBrain; ! bool _gSendJellyBrainBeatPacket = false; ! void CALLBACK MidiCallback (HMIDIIN handle, ! UINT uMsg, ! DWORD dwInstance, ! DWORD dwParam1, ! DWORD dwParam2) ! { ! if ((uMsg == MM_MIM_DATA) && (dwParam1 == 0xF8)) ! { // got a sync code ! if (++_midiSyncCodeCounter >= 24) ! { ! _midiTimecodeDelta = dwParam2 - _midiLastTimecode; ! _midiLastTimecode = dwParam2; ! _midiSyncCodeCounter = 0; ! _midiBPM = int(60000 * (double)(1 / (double)_midiTimecodeDelta)); ! if (_gSendJellyBrainBeatPacket) _gJellyBrain->SendBeatMessage(); ! } ! } ! } ! ! ! Beater::Beater (HWND hwndOwner, Painter* painter) : _hwnd (hwndOwner), ! _painter (painter) { + _jellyBrain = painter->GetJellyBrain(); + _gJellyBrain = _jellyBrain; + _event.Block (); _thread.Resume (); *************** *** 21,24 **** --- 53,81 ---- _sendJellyBrainBeatPacket = false; + + // setup midi-in monitor of the Voyager Beat Xtractor (see MidiCallback above) + unsigned int numMidiDevs = midiInGetNumDevs(); + if (numMidiDevs) + { + for (unsigned int devNum = 0; devNum < numMidiDevs; devNum++) + { + // get info on this device to make sure its the BeatXtractor + MIDIINCAPS midiInCaps; + MMRESULT mmResult = midiInGetDevCaps + ( devNum, &midiInCaps, sizeof(midiInCaps) ); + if (mmResult == MMSYSERR_NOERROR) + { + /* Open the MIDI In device #0 */ + mmResult = midiInOpen + ( &_midiBeatXtractor, 0, (DWORD)MidiCallback, 0, CALLBACK_FUNCTION ); + if (mmResult == MMSYSERR_NOERROR) + { + mmResult = midiInStart( _midiBeatXtractor ); + } + } + // break here to see error text in _midiErrStr, if any + midiInGetErrorText (mmResult,(LPSTR)_midiErrStr,sizeof(_midiErrStr)); + } + } } *************** *** 32,36 **** for (;;) { ! Sleep(100); // wake-up every tenth second if (_isDying) return; --- 89,93 ---- for (;;) { ! Sleep(10); // wake-up every 100th second if (_isDying) return; *************** *** 38,41 **** --- 95,100 ---- Win::Lock lock (_critSect); + _gSendJellyBrainBeatPacket = _sendJellyBrainBeatPacket; + if (_beaterActive) { *************** *** 44,48 **** if (_generatorActive) { ! float rate = 1 / (( (float)_bpm / (float)600 )); if (_tsecCounter >= (int)rate) { --- 103,107 ---- if (_generatorActive) { ! float rate = 1 / (( (float)_bpm / (float)6000 )); if (_tsecCounter >= (int)rate) { *************** *** 56,64 **** --- 115,129 ---- } + if (_painter->BeatDetected()) + _sendBeat = true; + // if 'Beats' checkbox in 'JellyBrain Packets' box is checked, // and we have a beat to send (from either the Generator or the Detector), // then send a message to JellyBrain, to react to a beat if (_sendBeat && _sendJellyBrainBeatPacket) + { _jellyBrain->SendBeatMessage(); + _sendBeat = false; + } } } |
From: NickS <nsc...@us...> - 2008-08-14 06:12:16
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyEars/Audio In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv6465/Audio Modified Files: Fft.cpp Fft.h Log Message: updates in attempting software beat detection Index: Fft.cpp =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Audio/Fft.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Fft.cpp 4 Jun 2008 03:10:26 -0000 1.12 --- Fft.cpp 14 Aug 2008 06:12:13 -0000 1.13 *************** *** 45,48 **** --- 45,51 ---- } _currDoO = 0; + _beatDetected = false; + _peakDoO = 0; + _maxPeakDoO = 0; } *************** *** 348,355 **** // 2 in order to skip the DC component, and to avoid // checking boundaries (since we check f+1 and f-1) unsigned int sizeOfMagX = _magX[0].size(); ! for (unsigned int f=2; f < sizeOfMagX-1; f++) { int np = _magX[np_idx][f]; int p = _magX[p_idx][f]; int pp_f = _magX[pp_idx][f]; --- 351,371 ---- // 2 in order to skip the DC component, and to avoid // checking boundaries (since we check f+1 and f-1) + int sum = 0; + unsigned int startF = 2; //hack:HzToPoint(3000)/2; unsigned int sizeOfMagX = _magX[0].size(); ! for (unsigned int f=startF; f < sizeOfMagX-1; f++) { + #if 0 + // the 1994 Goto paper used 3 np timepoints + int np_f = _magX[np_idx][f]; + int np_fplus1 = _magX[np_idx][f+1]; + int np_fminus1 = _magX[np_idx][f-1]; + int np = np_f; + if (np_fplus1 < np) np = np_fplus1; + if (np_fminus1 < np) np = np_fminus1; + #else + // the 2001 Goto paper uses just 1 np timepoint int np = _magX[np_idx][f]; + #endif int p = _magX[p_idx][f]; int pp_f = _magX[pp_idx][f]; *************** *** 365,370 **** --- 381,402 ---- if (np > p) _degreeOfOnset[_currDoO][f] = np - pp; else _degreeOfOnset[_currDoO][f] = p - pp; + sum += _degreeOfOnset[_currDoO][f]; } } + // store the sum in the DC component slot, since its + // not being used + _degreeOfOnset[_currDoO][0] = sum; + + // find the peak in our set of onset vals + _peakDoO = 0; + for (unsigned int i=0; i < _degreeOfOnset.size(); i++) + { + int D = _degreeOfOnset[i][0]; + if (D > _peakDoO) + _peakDoO = D; + } + if (_peakDoO > _maxPeakDoO) + _maxPeakDoO = _peakDoO; + } Index: Fft.h =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyEars/Audio/Fft.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Fft.h 4 Jun 2008 03:10:26 -0000 1.9 --- Fft.h 14 Aug 2008 06:12:13 -0000 1.10 *************** *** 18,26 **** // Output: from i = 0 to points-1 ! double GetIntensity (unsigned i) const { - //assert (i < _points); - //return std::abs (_X[i])/_sqrtPoints; - // nicks assert (i < _points/2); --- 18,23 ---- // Output: from i = 0 to points-1 ! int GetIntensity (unsigned i) const { // nicks assert (i < _points/2); *************** *** 83,86 **** --- 80,89 ---- _doBeatDetection=state; }; + bool BeatDetected () + { + bool state = _beatDetected; + _beatDetected = false; + return state; + } // return frequency in Hz of a given point *************** *** 100,103 **** --- 103,116 ---- } + int GetDegreeOfOnset (unsigned i) const + { + assert (i < _points/2); + return _degreeOfOnset[_currDoO][i]; + } + int GetPeakDegreeOfOnset() const + { + return _peakDoO; + } + private: void DataIn (int *data, unsigned dataSize); *************** *** 136,141 **** std::vector<double> _HannWindow; bool _doBeatDetection; ! std::vector<std::vector<double>> _degreeOfOnset; int _currDoO; // idx into current _degreeOfOnset time }; --- 149,157 ---- std::vector<double> _HannWindow; bool _doBeatDetection; ! std::vector<std::vector<int>> _degreeOfOnset; int _currDoO; // idx into current _degreeOfOnset time + int _peakDoO; // max of D(t) + int _maxPeakDoO; // peak max of D(t) + bool _beatDetected; }; |
From: NickS <nsc...@us...> - 2008-08-14 06:05:41
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv3534 Modified Files: JellyBrain.cs JellyBrain.csproj ProximityDetectors.cs Log Message: added proximity detector animation Index: JellyBrain.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/JellyBrain.cs,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** JellyBrain.cs 15 Jun 2008 02:01:38 -0000 1.55 --- JellyBrain.cs 14 Aug 2008 06:05:07 -0000 1.56 *************** *** 68,72 **** public static ProximityDetectors m_ProximityDetectors = new ProximityDetectors(); ! public static int m_Range = 0; private static bool m_demoModeEnabled = false; --- 68,72 ---- public static ProximityDetectors m_ProximityDetectors = new ProximityDetectors(); ! public static float[] g_RibRangeDetect; private static bool m_demoModeEnabled = false; *************** *** 88,91 **** --- 88,93 ---- g_FullSpectrum = new int[0]; // gets resized when first packet arrives g_FullSpectrumPeak = 0; + + g_RibRangeDetect = new float[g_iTotalRibs]; } *************** *** 120,130 **** // read range data from ultrasonic sensor ! // UNCOMMENT to activate detector on COM2 ! //m_ProximityDetectors.InitSerialPort(); // jg // LEDInfo.LoadExcelSheet("led_array_05.xls"); ! int addedIndex = addedIndex = GlobalAnimationList.Add(new PerlinNoise()); DemoAnimationList.Add(GlobalAnimationList[addedIndex]); --- 122,134 ---- // read range data from ultrasonic sensor ! // UNCOMMENT to activate detectors on COM4 and 5 ! //m_ProximityDetectors.Init(); // jg // LEDInfo.LoadExcelSheet("led_array_05.xls"); ! int addedIndex = ! addedIndex = GlobalAnimationList.Add(new RibProximityDetect()); ! DemoAnimationList.Add(GlobalAnimationList[addedIndex]); addedIndex = GlobalAnimationList.Add(new PerlinNoise()); DemoAnimationList.Add(GlobalAnimationList[addedIndex]); *************** *** 342,349 **** } - case ConsoleKey.R: // range data - Console.WriteLine(m_Range); - break; - case ConsoleKey.Escape: { --- 346,349 ---- Index: JellyBrain.csproj =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/JellyBrain.csproj,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** JellyBrain.csproj 15 Jun 2008 02:01:38 -0000 1.42 --- JellyBrain.csproj 14 Aug 2008 06:05:07 -0000 1.43 *************** *** 69,72 **** --- 69,73 ---- <Compile Include="Animations\Phyllotaxy.cs" /> <Compile Include="Animations\PolarRose.cs" /> + <Compile Include="Animations\RibProximityDetect.cs" /> <Compile Include="Animations\RowColorCycleFade.cs" /> <Compile Include="Animations\JixelColorCycle_02.cs" /> Index: ProximityDetectors.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/ProximityDetectors.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProximityDetectors.cs 15 Jun 2008 02:01:39 -0000 1.1 --- ProximityDetectors.cs 14 Aug 2008 06:05:07 -0000 1.2 *************** *** 8,35 **** public class ProximityDetectors { ! private SerialPort m_SerialPort; ! public string com = "COM2"; ! public void InitSerialPort() { ! m_SerialPort = new System.IO.Ports.SerialPort(); ! m_SerialPort.PortName = com; ! m_SerialPort.BaudRate = 9600; ! m_SerialPort.DataBits = 8; ! m_SerialPort.Parity = Parity.None; ! m_SerialPort.StopBits = StopBits.One; ! m_SerialPort.Handshake = Handshake.None; - m_SerialPort.DataReceived += - new SerialDataReceivedEventHandler(DataReceived); - try { ! m_SerialPort.Open(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } --- 8,56 ---- public class ProximityDetectors { ! private SerialPort m_SerialPortA = new System.IO.Ports.SerialPort(); ! private SerialPort m_SerialPortB = new System.IO.Ports.SerialPort(); ! // defines the maximum distance, in inches, that we consider ! // a valid range detection. anything over this value will set the ! // 'detected' range to -1, which means JellyBrain will ignore it. ! private const Int32 m_maxRangeThreshold = 144; ! ! private const Int32 m_minRange = 6; // detectors dont go lower than this ! ! private Int32[] m_rangeBuffer = new Int32[10]; ! private int m_rangeBufferPtr = 0; ! private Int32 m_rangeAvg; ! ! public void Init() { ! this.InitSerialPort(m_SerialPortA, "COM4", DataReceivedPortA); ! this.InitSerialPort(m_SerialPortB, "COM5", DataReceivedPortB); ! } ! private void InitSerialPort(SerialPort port, ! string portName, ! SerialDataReceivedEventHandler handler) ! { ! port.PortName = portName; ! port.BaudRate = 9600; ! port.DataBits = 8; ! port.Parity = Parity.None; ! port.StopBits = StopBits.One; ! port.Handshake = Handshake.None; ! port.NewLine = "\r"; ! ! port.DataReceived += ! new SerialDataReceivedEventHandler(handler); try { ! port.Open(); ! Console.Write("Successfully opened "); ! Console.WriteLine(portName); } catch (Exception e) { Console.WriteLine(e.ToString()); + port.Close(); } } *************** *** 38,60 **** // //////////////////////////////////////////////////////////////////////////////// ! void DataReceived(object sender, SerialDataReceivedEventArgs e) { ! //read data waiting in the buffer ! string str = m_SerialPort.ReadExisting(); ! //Console.Write(str); ! // parse out the data (super simple!) ! if (str.Length == 5) { ! char[] cRange = str.ToCharArray(); ! if ((cRange[0] == 'R') && (cRange[4] == '\r')) { ! char[] trimChars = {'R','\r'}; ! string sRange = str.TrimStart(trimChars); ! Int32 range = Int32.Parse(sRange); ! JellyBrain.m_Range = range; ! //Console.WriteLine(range); } } } --- 59,139 ---- // //////////////////////////////////////////////////////////////////////////////// ! void DataReceivedPortA(object sender, SerialDataReceivedEventArgs e) { ! DataReceived(m_SerialPortA); ! } ! void DataReceivedPortB(object sender, SerialDataReceivedEventArgs e) ! { ! DataReceived(m_SerialPortB); ! } ! void DataReceived(SerialPort port) ! { ! try { ! //read data waiting in the buffer ! string dataStr = port.ReadLine(); ! //Console.WriteLine(str); ! ! // parse out the data (super simple!) ! if (dataStr.Length == 4) { ! char[] cRange = dataStr.ToCharArray(); ! if (cRange[0] == 'R') ! { ! char[] trimChars = { 'R' }; ! string sRange = dataStr.TrimStart(trimChars); ! Int32 range = Int32.Parse(sRange); ! //Console.WriteLine(range); ! ! // keep a running average, to try to smooth-out ! // the jumpiness in the readings ! if (++m_rangeBufferPtr == m_rangeBuffer.Length) ! { ! m_rangeBufferPtr = 0; ! } ! m_rangeBuffer[m_rangeBufferPtr] = range; ! Int32 sum = 0; ! for (int i = 0; i < m_rangeBuffer.Length; i++) ! { ! sum += m_rangeBuffer[i]; ! } ! m_rangeAvg = sum / m_rangeBuffer.Length; ! } ! } ! // else Console.WriteLine(str.Length); ! ! // update the JellyBrain rib proximity detect values with ! // a value ranging from 0 to 1, where 0 is infinitely ! // far away, and 1 is as near as possible to the rib (detector) ! ! // start by setting clearing all values ! for (int i = 0; i < JellyBrain.g_iTotalRibs; i++) ! { ! JellyBrain.g_RibRangeDetect[i] = 0; ! } ! ! if ((m_rangeAvg > 0) && (m_rangeAvg < m_maxRangeThreshold)) ! { ! for (int i = 0; i < JellyBrain.g_iTotalRibs; i++) ! { ! if (m_rangeAvg <= m_minRange) ! { ! JellyBrain.g_RibRangeDetect[i] = 1; ! } ! else ! { ! JellyBrain.g_RibRangeDetect[i] = ! (float)1 - ((float)m_rangeAvg / (float)m_maxRangeThreshold); ! } ! ! //Console.WriteLine(JellyBrain.g_RibRangeDetect[i]); ! } } } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } } *************** *** 64,68 **** public void Close() { ! m_SerialPort.Close(); } } --- 143,148 ---- public void Close() { ! m_SerialPortA.Close(); ! m_SerialPortB.Close(); } } |
From: NickS <nsc...@us...> - 2008-08-14 06:05:12
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv3534/Animations Added Files: RibProximityDetect.cs Log Message: added proximity detector animation --- NEW FILE: RibProximityDetect.cs --- using System; using System.Collections.Generic; using System.Text; namespace JellyBrain.Animations { class RibProximityDetect : Animation { public RibProximityDetect() { for (int i = 0; i < JellyBrain.g_iTotalRibs; i++) { JellyBrain.g_RibRangeDetect[i] = 0; } m_SubFramesPerKeyFrame = 1; } public override string GetAnimationName() { return "RibProximityDetect"; } override public void UpdateKeyFrame(KeyFrame keyframe) { for (int rib = 0; rib < JellyBrain.g_iTotalRibs; rib++) { if (JellyBrain.g_RibRangeDetect[rib] == 0.0) continue; int maxRow = (int)(JellyBrain.g_RibRangeDetect[rib] * JellyBrain.g_iLightsPerRib); if (maxRow >= JellyBrain.g_iLightsPerRib) continue; for (int row = 0; row <= maxRow; row++) //trying to light from bottom-up: //for (int row = JellyBrain.g_iLightsPerRib-1; row > maxRow; row--) { keyframe.m_Brightness[rib, row] = 1.0f; } } } } } |
From: NickS <nsc...@us...> - 2008-08-14 06:03:26
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv2341 Modified Files: SevenBandFreqShow.cs Log Message: start at row 20 to threshold to only strong signals Index: SevenBandFreqShow.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/SevenBandFreqShow.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SevenBandFreqShow.cs 14 Feb 2008 06:50:37 -0000 1.7 --- SevenBandFreqShow.cs 14 Aug 2008 06:02:51 -0000 1.8 *************** *** 49,53 **** int maxRow = (int)((bandVal / spectrumMax) * JellyBrain.g_iLightsPerRib); if (maxRow >= JellyBrain.g_iLightsPerRib) continue; ! for (int row = 0; row < maxRow; row++) { keyframe.m_Brightness[rib, row] = 1.0f; --- 49,54 ---- int maxRow = (int)((bandVal / spectrumMax) * JellyBrain.g_iLightsPerRib); if (maxRow >= JellyBrain.g_iLightsPerRib) continue; ! for (int row = 20; row <= maxRow; row++) // start at row 20 to threshold to only strong signals ! //trying to light from bottom-up: //for (int row = JellyBrain.g_iLightsPerRib-1; row > maxRow; row--) { keyframe.m_Brightness[rib, row] = 1.0f; |
From: NickS <nsc...@us...> - 2008-08-07 02:27:19
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv31571/Animations Modified Files: PerlinNoise.cs Log Message: fixed compilation problem with PerlinNoise: cannot create the static class Perlin Index: PerlinNoise.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/PerlinNoise.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PerlinNoise.cs 14 Jun 2008 06:13:55 -0000 1.3 --- PerlinNoise.cs 7 Aug 2008 02:27:15 -0000 1.4 *************** *** 19,23 **** // create our own Perlin instance ! Perlin m_perlin = new Perlin(); public override string GetAnimationName() --- 19,23 ---- // create our own Perlin instance ! //cannot create a static class: Perlin m_perlin = new Perlin(); public override string GetAnimationName() *************** *** 53,58 **** // update the algorithm ! m_perlin.initialFrequency = currentStartingFrequency; ! m_perlin.initialAmplitude = currentCoverage; for (int rib = 0; rib < JellyBrain.g_iTotalRibs; rib++) --- 53,58 ---- // update the algorithm ! Perlin.initialFrequency = currentStartingFrequency; ! Perlin.initialAmplitude = currentCoverage; for (int rib = 0; rib < JellyBrain.g_iTotalRibs; rib++) *************** *** 60,64 **** for (int row = 0; row < JellyBrain.g_iLightsPerRib; row++) { ! float noise = (float)m_perlin.PerlinNoise2d(rib, row); //////////////////////// --- 60,64 ---- for (int row = 0; row < JellyBrain.g_iLightsPerRib; row++) { ! float noise = (float)Perlin.PerlinNoise2d(rib, row); //////////////////////// |
From: NickS <nsc...@us...> - 2008-06-15 02:01:43
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv20256 Modified Files: JellyBrain.cs JellyBrain.csproj Added Files: ProximityDetectors.cs Log Message: added ProximityDetector class to read range data from ultrasonce sensor on COM2. valid range data, in inches, is printed to screen when 'r' is pressed (for development only). Index: JellyBrain.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/JellyBrain.cs,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** JellyBrain.cs 14 Jun 2008 22:21:24 -0000 1.54 --- JellyBrain.cs 15 Jun 2008 02:01:38 -0000 1.55 *************** *** 67,70 **** --- 67,73 ---- public static bool g_Beat = false; + public static ProximityDetectors m_ProximityDetectors = new ProximityDetectors(); + public static int m_Range = 0; + private static bool m_demoModeEnabled = false; *************** *** 116,119 **** --- 119,126 ---- m_MidiInterface.MidiOpen(); + // read range data from ultrasonic sensor + // UNCOMMENT to activate detector on COM2 + //m_ProximityDetectors.InitSerialPort(); + // jg // LEDInfo.LoadExcelSheet("led_array_05.xls"); *************** *** 335,338 **** --- 342,349 ---- } + case ConsoleKey.R: // range data + Console.WriteLine(m_Range); + break; + case ConsoleKey.Escape: { *************** *** 480,484 **** } Console.Out.WriteLine(" d: toggle demo mode " + demoEnabledString); ! Console.Out.WriteLine("\n ESC: quit"); } --- 491,495 ---- } Console.Out.WriteLine(" d: toggle demo mode " + demoEnabledString); ! Console.Out.WriteLine(" ESC: quit"); } Index: JellyBrain.csproj =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/JellyBrain.csproj,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** JellyBrain.csproj 14 Jun 2008 05:57:55 -0000 1.41 --- JellyBrain.csproj 15 Jun 2008 02:01:38 -0000 1.42 *************** *** 109,112 **** --- 109,113 ---- <Compile Include="NetworkMessage.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ProximityDetectors.cs" /> <Compile Include="Rib.cs" /> <Compile Include="Row.cs" /> --- NEW FILE: ProximityDetectors.cs --- using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; namespace JellyBrain { public class ProximityDetectors { private SerialPort m_SerialPort; public string com = "COM2"; public void InitSerialPort() { m_SerialPort = new System.IO.Ports.SerialPort(); m_SerialPort.PortName = com; m_SerialPort.BaudRate = 9600; m_SerialPort.DataBits = 8; m_SerialPort.Parity = Parity.None; m_SerialPort.StopBits = StopBits.One; m_SerialPort.Handshake = Handshake.None; m_SerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived); try { m_SerialPort.Open(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// void DataReceived(object sender, SerialDataReceivedEventArgs e) { //read data waiting in the buffer string str = m_SerialPort.ReadExisting(); //Console.Write(str); // parse out the data (super simple!) if (str.Length == 5) { char[] cRange = str.ToCharArray(); if ((cRange[0] == 'R') && (cRange[4] == '\r')) { char[] trimChars = {'R','\r'}; string sRange = str.TrimStart(trimChars); Int32 range = Int32.Parse(sRange); JellyBrain.m_Range = range; //Console.WriteLine(range); } } } //////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// public void Close() { m_SerialPort.Close(); } } } |
From: Kelly <hyp...@us...> - 2008-06-14 22:21:57
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23835/Animations Modified Files: AccidentalSpiral.cs BouncingRings.cs Growie.cs JixelColorCycle.cs JixelColorCycle_02.cs RibColorCycle.cs RowCycle.cs SexWorms.cs SpectrumDiscs.cs SpinningRows.cs StraightSine.cs StraightSine_02.cs Worms.cs Log Message: Added a "DemoAnimationList" of the types of animations we want in a demo. Fixed the speeds of several animations so that they work in a demo. Fixed a few bugs where Random() functions were not using the entire range. Tightened up the timings of animation display times and transition times. This is a fun demo to watch. YEEEEHAW!!! Index: SpinningRows.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/SpinningRows.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SpinningRows.cs 26 Jun 2007 00:20:20 -0000 1.2 --- SpinningRows.cs 14 Jun 2008 22:21:22 -0000 1.3 *************** *** 15,18 **** --- 15,20 ---- m_CurrentRibIndexArray = new int[JellyBrain.g_iLightsPerRib]; + m_SubFramesPerKeyFrame = 3; + Random random = new Random(Environment.TickCount); Index: RowCycle.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/RowCycle.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RowCycle.cs 23 Jun 2007 19:45:10 -0000 1.2 --- RowCycle.cs 14 Jun 2008 22:21:22 -0000 1.3 *************** *** 7,10 **** --- 7,15 ---- class RowCycle : Animation { + public RowCycle() + { + m_SubFramesPerKeyFrame = 1; + } + public override string GetAnimationName() { Index: BouncingRings.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/BouncingRings.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BouncingRings.cs 11 Jun 2008 05:12:44 -0000 1.1 --- BouncingRings.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 40,44 **** // random isn't bad, but there are some amazing emergent patterns which can come from // the more ordered animations ! newRing.m_currentRow = random.Next(0, JellyBrain.g_iLightsPerRib - 1); newRing.m_speed = 1.0f; // every other row will go a different direction --- 40,44 ---- // random isn't bad, but there are some amazing emergent patterns which can come from // the more ordered animations ! newRing.m_currentRow = random.Next(0, JellyBrain.g_iLightsPerRib); newRing.m_speed = 1.0f; // every other row will go a different direction Index: JixelColorCycle.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/JixelColorCycle.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JixelColorCycle.cs 25 Jun 2007 21:50:33 -0000 1.4 --- JixelColorCycle.cs 14 Jun 2008 22:21:22 -0000 1.5 *************** *** 7,10 **** --- 7,15 ---- class JixelColorCycle : Animation { + public JixelColorCycle() + { + m_SubFramesPerKeyFrame = 1; + } + public override string GetAnimationName() { Index: AccidentalSpiral.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/AccidentalSpiral.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AccidentalSpiral.cs 26 Jun 2007 00:39:42 -0000 1.1 --- AccidentalSpiral.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 10,13 **** --- 10,18 ---- { private int m_CurrentRowIndex = 0; + + public AccidentalSpiral() + { + m_SubFramesPerKeyFrame = 3; + } public override string GetAnimationName() Index: StraightSine.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/StraightSine.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StraightSine.cs 28 Jun 2007 22:54:04 -0000 1.1 --- StraightSine.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 7,10 **** --- 7,15 ---- public class StraightSine : Animation { + public StraightSine() + { + m_SubFramesPerKeyFrame = 1; + } + public override string GetAnimationName() { Index: Growie.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/Growie.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Growie.cs 23 Jun 2007 19:45:10 -0000 1.2 --- Growie.cs 14 Jun 2008 22:21:22 -0000 1.3 *************** *** 7,10 **** --- 7,15 ---- public class Growie : Animation { + public Growie() + { + m_SubFramesPerKeyFrame = 1; + } + public override string GetAnimationName() { Index: SpectrumDiscs.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/SpectrumDiscs.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SpectrumDiscs.cs 14 Feb 2008 06:50:38 -0000 1.3 --- SpectrumDiscs.cs 14 Jun 2008 22:21:22 -0000 1.4 *************** *** 31,35 **** for (int i = 0; i < m_TotalRows; i++) { ! m_CurrentRibIndexArray[i] = random.Next(0, m_TotalRows - 1); } } --- 31,35 ---- for (int i = 0; i < m_TotalRows; i++) { ! m_CurrentRibIndexArray[i] = random.Next(0, m_TotalRows); } } Index: JixelColorCycle_02.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/JixelColorCycle_02.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JixelColorCycle_02.cs 3 Jul 2007 21:33:52 -0000 1.1 --- JixelColorCycle_02.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 7,10 **** --- 7,15 ---- class JixelColorCycle_02 : Animation { + public JixelColorCycle_02() + { + m_SubFramesPerKeyFrame = 3; + } + public override string GetAnimationName() { Index: SexWorms.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/SexWorms.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SexWorms.cs 11 Jun 2008 05:12:44 -0000 1.1 --- SexWorms.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 35,40 **** DomePosition firstPos = new DomePosition(); ! firstPos.m_ribPos = m_random.Next(0, JellyBrain.g_iTotalRibs - 1); ! firstPos.m_rowPos = m_random.Next(0, JellyBrain.g_iLightsPerRib - 1); // set the max length --- 35,40 ---- DomePosition firstPos = new DomePosition(); ! firstPos.m_ribPos = m_random.Next(0, JellyBrain.g_iTotalRibs); ! firstPos.m_rowPos = m_random.Next(0, JellyBrain.g_iLightsPerRib); // set the max length Index: Worms.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/Worms.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Worms.cs 11 Jun 2008 05:12:44 -0000 1.2 --- Worms.cs 14 Jun 2008 22:21:23 -0000 1.3 *************** *** 31,36 **** DomePosition firstPos = new DomePosition(); ! firstPos.m_ribPos = m_random.Next(0, JellyBrain.g_iTotalRibs - 1); ! firstPos.m_rowPos = m_random.Next(0, JellyBrain.g_iLightsPerRib - 1); // set the max length --- 31,36 ---- DomePosition firstPos = new DomePosition(); ! firstPos.m_ribPos = m_random.Next(0, JellyBrain.g_iTotalRibs); ! firstPos.m_rowPos = m_random.Next(0, JellyBrain.g_iLightsPerRib); // set the max length *************** *** 82,87 **** } ! int m_maxWorms = 30; ! int m_maxWormLength = 15; ArrayList m_wormList = new ArrayList(); --- 82,87 ---- } ! int m_maxWorms = 10; ! int m_maxWormLength = 10; ArrayList m_wormList = new ArrayList(); Index: RibColorCycle.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/RibColorCycle.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RibColorCycle.cs 24 Jun 2007 22:43:56 -0000 1.3 --- RibColorCycle.cs 14 Jun 2008 22:21:22 -0000 1.4 *************** *** 7,10 **** --- 7,15 ---- class RibColorCycle : Animation { + public RibColorCycle() + { + m_SubFramesPerKeyFrame = 1; + } + public override string GetAnimationName() { Index: StraightSine_02.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Animations/StraightSine_02.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StraightSine_02.cs 28 Jun 2007 22:54:04 -0000 1.1 --- StraightSine_02.cs 14 Jun 2008 22:21:22 -0000 1.2 *************** *** 7,10 **** --- 7,15 ---- public class StraightSine_02 : Animation { + public StraightSine_02() + { + m_SubFramesPerKeyFrame = 7; + } + public override string GetAnimationName() { |
From: Kelly <hyp...@us...> - 2008-06-14 22:21:27
|
Update of /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Transitions In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv23835/Transitions Modified Files: BrightnessBlend.cs RandomDissolve.cs Log Message: Added a "DemoAnimationList" of the types of animations we want in a demo. Fixed the speeds of several animations so that they work in a demo. Fixed a few bugs where Random() functions were not using the entire range. Tightened up the timings of animation display times and transition times. This is a fun demo to watch. YEEEEHAW!!! Index: BrightnessBlend.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Transitions/BrightnessBlend.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BrightnessBlend.cs 14 Jun 2008 05:36:03 -0000 1.3 --- BrightnessBlend.cs 14 Jun 2008 22:21:24 -0000 1.4 *************** *** 26,29 **** --- 26,33 ---- // this transition does make use of brightness, so we should set the // target frame to be the max of the two animations + + // TODO kellyp -- should i cap this to some value where brightness looks + // good? we might want to blend 2 fast animations which + // are both set to 1 m_SubFramesPerKeyFrame = Math.Max(m_animA.GetSubFramesPerKeyFrame(), m_animB.GetSubFramesPerKeyFrame()); Index: RandomDissolve.cs =================================================================== RCS file: /cvsroot/jellyfish12000/CVSROOT/JellyBrain/Transitions/RandomDissolve.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RandomDissolve.cs 14 Jun 2008 05:36:03 -0000 1.3 --- RandomDissolve.cs 14 Jun 2008 22:21:24 -0000 1.4 *************** *** 97,102 **** while(retryAttempts > 0) { ! int randomRib = m_random.Next(0, JellyBrain.g_iTotalRibs - 1); ! int randomRow = m_random.Next(0, JellyBrain.g_iLightsPerRib - 1); if (m_dissolveMask.m_Brightness[randomRib, randomRow] < 1.0f) --- 97,102 ---- while(retryAttempts > 0) { ! int randomRib = m_random.Next(0, JellyBrain.g_iTotalRibs); ! int randomRow = m_random.Next(0, JellyBrain.g_iLightsPerRib); if (m_dissolveMask.m_Brightness[randomRib, randomRow] < 1.0f) |