public IEnumerable <int> Xeq(RunTime context) { context[0] = System.Drawing.Color.White; Task.Delay(500).Wait(); yield return(EndPoint.X); Task.Delay(500).Wait(); context[0] = System.Drawing.Color.Red; }
public static Task RunNow(Song song) { var cts = new CancellationTokenSource(); var tkn = cts.Token; var runtm = new RunTime(); var tsk = new Task(() => runtm.Run(tkn, song), tkn, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach); tsk.Start(); return(tsk); }
public static Song Open(ToolStripStatusLabel ssHoverSep, ToolStripStatusLabel ssHover, ToolStripStatusLabel ssSelectedSep, ToolStripStatusLabel ssSelected, string xmlname) { var song = Song.New(ssHoverSep, ssHover, ssSelectedSep, ssSelected); song.Selected.CollectionChanged += song.Selected_CollectionChanged; var xdoc = XDocument.Load(xmlname); var root = xdoc.Element("song"); string path = Path.GetPathRoot(Application.StartupPath).Replace("\\", ""); song.fileName = ((string)root.Attribute("filename")).Replace("@@path@@", path); song.DisplayInfoFileName = song.FileName + ".bin"; song.KeyFrames = root.Element("keyframes").Elements("keyframe") .Select(xml => new KeyFrame() { Measure = (int)xml.Attribute("measure"), BeatsPerMeasure = (xml.Attribute("beatspermeasure") == null ? 0 : (int)xml.Attribute("beatspermeasure")), Time = (float)xml.Attribute("time") }).ToList(); foreach (var xml in root.Element("lyrics").Elements("lyric")) { song.CreateLyric((string)xml.Attribute("text"), song.TimeMarkParse((string)xml.Attribute("time"))); } // load steps song.CreateStepBg(); foreach (var elm in root.Element("steps").Elements()) { if (elm.Name == "repeat") { for (int ndx = 1; ; ndx++) { var attrb = elm.Attribute("tm" + ndx); if (attrb == null) { break; } var measureOffset = (int)attrb; foreach (var sub in elm.Elements()) { stepHelper(song, sub, measureOffset); } } } else { stepHelper(song, elm, 0); } } var lup = root.Element("loop"); if (lup != null) { if (lup.Attribute("begin") != null) { song.LoopBeginPx = (int)lup.Attribute("begin"); } if (lup.Attribute("end") != null) { song.LoopEndPx = (int)lup.Attribute("end"); } } song.Order(); song.ResetPoints(); song.ArrangeSteps(); song.ResetPoints(); //Recalculate(); //bool y = false; //foreach (var step in stepManager.Steps) //{ // step.Brush = (y) ? Brushes.LightBlue : Brushes.Goldenrod; // y = !y; //} try { song.waveOutDevice = new WaveOut() { DesiredLatency = 100 }; song.ActiveStream = new Mp3FileReader(song.fileName); song.inputStream = new WaveChannel32(song.activeStream); logger.Info($"Ttl time:{song.inputStream.TotalTime}"); song.waveOutDevice.PlaybackStopped += song.waveOutDevice_PlaybackStopped; song.waveOutDevice.Init(song.inputStream); song.endmTm = (float)song.inputStream.TotalTime.TotalSeconds; song.musicEndPx = (int)(song.endmTm * Global.pxpersec); song.trackTime = (float)song.inputStream.TotalTime.TotalSeconds; var tkn = new CancellationTokenSource().Token; new WaveformSampler(song, tkn).Sample(); song.PlayerMode = PlayerMode.stopped; } catch (Exception ex) { song.dispose(); return(null); } //Colors[] clrtbl = new[] { Colors.Red, Colors.Blue, Colors.Yellow, Colors.Green, Colors.Orange }; //var lits = new Clr[5][]; //for (int ndx = 0; ndx < 5; ndx++) //{ // lits[ndx] = // Global.Instance.LitArray.Select((x, n) => // (x is MonoLit || x is FeatureLit) ? x.InitVal : // (Clr)clrtbl[(n + ndx) % 5]).ToArray(); //} //song.litValues = lits; var tsk = RunTime.RunNow(song); tsk.Wait(); return(song); }
public IEnumerable <int> Xeq(RunTime context) { this.context = context; //if (mode == 1) // appear one row @ a time - left to right //{ // int intr = (EndPoint.X - StartPoint.X) / 20; // for (int row = 0; row < 9; row++) // { // for (int col = 0; col < 11; col++) // context[bgnndx[row, col]] = bmi.Colors[bmi.Indices[row, col]]; // yield return StartPoint.X + intr * (row + 1); // } //} //else if (mode == 2 || mode == 4) // 2 = slide in from right and then out to left, 4 - slide in from right & stop //{ // for (int lup = 0; lup < 11; lup+=2) // { // for (int col = 0; col <= lup; col++) // copycol(col, 10 - lup + col); // yield return context.CurTime + 4; // } // if (mode == 2) // { // for (int lup = 2; lup <= 12; lup += 2) // { // int col; // for (col = lup; col < 11 && col - lup < 11; col++) // copycol(col, col - lup); // for (col = 11 - lup; col < 11; col++) // if (col >= 0) // restorecol(col); // yield return context.CurTime + 4; // }; // } // yield break; //} //else if (mode == 3) //{ // int thrds = (EndPoint.X - StartPoint.X) / 3; // int intr = thrds / 10; // for (int row = 0; row < 9; row++) // { // for (int col = 0; col < 11; col++) // context[bgnndx[row, col]] = bmi.Colors[bmi.Indices[row, col]]; // yield return context.CurTime + intr; // } // yield return StartPoint.X + thrds; // int pre = 0; // int nxt = 11; // int starttime = context.CurTime; // int endtime = context.CurTime + thrds; // while (context.CurTime < endtime) // { // float fraction = 2 * (context.CurTime - starttime) / (float)thrds; // if (fraction > 1) break; // for (int row = 0; row < 9; row++) // { // for (int col = 0; col < 11; col++) // context[bgnndx[row, col]] = factor(bmi.Colors[bmi.Indices[row, col + pre]], bmi.Colors[bmi.Indices[row, col + nxt]], fraction); // } // yield return context.CurTime + 4; // } // yield return endtime; // pre = 11; // nxt = 22; // starttime = context.CurTime; // endtime = EndPoint.X; // while (context.CurTime < endtime) // { // float fraction = 2 * (context.CurTime - starttime) / (float)thrds; // if (fraction > 1) break; // for (int row = 0; row < 9; row++) // { // for (int col = 0; col < 11; col++) // context[bgnndx[row, col]] = factor(bmi.Colors[bmi.Indices[row, col + pre]], bmi.Colors[bmi.Indices[row, col + nxt]], fraction); // } // yield return context.CurTime + 4; // } //} bool first = true; foreach (var tran in Transition.Transitions) { if (tran is StepTransition_Position) { if (first) { first = false; bgnndx = new int[9, 11]; int ndx = 0; foreach (var itm in Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => regex.IsMatch(v.Name)) .OrderByDescending(v => v.Row).ThenBy(v => v.Column)) { bgnndx[(ndx / 11), (ndx++ % 11)] = itm.GlobalIndex; } before = new SD.Color[9, 11]; for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { before[row, col] = context[bgnndx[row, col]]; } } } var poser = (StepTransition_Position)tran; int x = poser.X; int y = poser.Y; int steps = 0; do { for (int col = 0; col < 11; col++) { restorecol(col); } for (int row = 0, srcrow = row - y; row < 9; row++, srcrow++) { if ((srcrow >= 0) && (srcrow < 9)) { for (int col = 0, srccol = col - x; col < 11; col++, srccol++) { if ((srccol >= 0) && (srccol < 11)) { context[bgnndx[row, col]] = bmi.Pixels.Pixels[bmi.Indices[srcrow, srccol]]; } } } } x += poser.XStep; y += poser.YStep; steps++; yield return(context.CurTime + 4); } while (steps <= poser.Steps); } else if (tran is StepTransition_Fade) { var fader = (StepTransition_Fade)tran; switch (fader.Fade) { case 10: { //var fader = (StepTransition_Fade)tran; bgnColor[] initClr = Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => regex.IsMatch(v.Name)) .Select(l => new bgnColor() { clr = context.Colors[l.GlobalIndex], Ndx = l.GlobalIndex }) .ToArray(); float start = this.startTimeMark.Time; float endTime = this.endTimeMark.Time; int fade = 0; do { float fraction; if (start >= endTime) { fraction = 1; } else { fraction = Math.Min((context.CurTime - start) / (endTime - start), 1); } int ndx = 0; foreach (var bgn in initClr) { context[bgn.Ndx] = factor(bgn.clr, this.palet[ndx++], fraction); } fade++; yield return(context.CurTime + 4); } while (context.CurTime < endTime); } break; case 0: { var litx = Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => regex.IsMatch(v.Name)); if (selector != null) { litx = litx.Where(lit => selector(lit)); } if (orderby != null) { litx = litx.OrderBy(lit => orderby(lit)); } bgnColor[] initClr = litx .Select(l => new bgnColor() { clr = context[l.GlobalIndex], Ndx = l.GlobalIndex }) .ToArray(); int ndx = 0; foreach (var bgn in initClr) { context[bgn.Ndx] = this.palet[ndx++]; } } break; case 1: { bgnColor[] initClr = Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => regex.IsMatch(v.Name)) .Select(l => new bgnColor() { clr = context[(int)l.GlobalIndex], Ndx = (int)l.GlobalIndex }) .ToArray(); int ndx = 0; foreach (var bgn in initClr) { context[bgn.Ndx] = this.palet[ndx++]; } yield return(context.CurTime + 4); foreach (var bgn in initClr) { context[bgn.Ndx] = bgn.clr; } } break; } } else if (tran is StepTransition_Linear) { var linear = (StepTransition_Linear)tran; var litx = Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => regex.IsMatch(v.Name)); if (selector != null) { litx = litx.Where(lit => selector(lit)); } if (orderby != null) { litx = litx.OrderBy(lit => orderby(lit)); } int[][] lits; if (groupby != null) { lits = litx.GroupBy(lit => groupby(lit), (key, grp) => grp.Select(lit => lit.GlobalIndex).ToArray()).ToArray(); } else { lits = litx.Select(lit => new int[] { lit.GlobalIndex }).ToArray(); } float start = this.startTimeMark.Time; float endTime = this.endTimeMark.Time; var fade = linear.Fade; var backward = (mode & 1) > 0; var climb = (mode & 2) > 0; var rotate = (mode & 4) > 0; int ndx = 0; int indx = 0; if (rotate) { do { for (ndx = 0; ndx < lits.Count(); ndx++) { foreach (var indy in lits[backward ? lits.Count() - 1 - ndx : ndx]) { context[indy] = this.palet[ndx + indx]; } } indx += (backward) ? lits.Length - 1 : 1; yield return(context.CurTime + 4 * 4); } while (context.CurTime < endTime); } else if (!climb) { do { float fraction; if (start >= endTime) { fraction = 1; } else { fraction = Math.Min((context.CurTime - start) / (endTime - start), 1); } int newptr = (int)Math.Ceiling(lits.Count() * fraction); for (; ndx < newptr; ndx++) { foreach (var indy in lits[backward ? lits.Count() - 1 - ndx : ndx]) { context[indy] = this.palet[indx]; } indx++; } yield return(context.CurTime + 4); } while (context.CurTime < endTime); for (; ndx < lits.Count(); ndx++) { foreach (var indy in lits[backward ? lits.Count() - 1 - ndx : ndx]) { context[indy] = this.palet[indx]; } indx++; } } else { do { float fraction; if (start >= endTime) { fraction = 1; } else { fraction = Math.Min((context.CurTime - start) / (endTime - start), 1); } int newptr = (int)Math.Ceiling((lits.Count() - 1) * fraction); indx = 0; try { for (ndx = newptr; ndx >= 0; ndx--) { foreach (var indy in lits[backward ? lits.Count() - 1 - ndx : ndx]) { context[indy] = this.palet[indx]; } indx++; } } catch (Exception e) { } yield return(context.CurTime + 4); } while (context.CurTime < endTime); indx = 0; for (ndx = lits.Length - 1; ndx >= 0; ndx--) { foreach (var indy in lits[backward ? lits.Count() - 1 - ndx : ndx]) { context[indy] = this.palet[indx]; } indx++; } } } } //yield return EndPoint.X; //for (int row = 0; row < 9; row++) // for (int col = 0; col < 11; col++) // context[bgnndx[row, col]] = System.Drawing.Color.Black; }
public IEnumerable <int> Xeq(RunTime context) { this.context = context; shift = new uint[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint _________ = 0; for (int ndx = 0; ndx < msg.Length; ndx++) { FontUpdate font; Global.Instance.FontDict.TryGetValue(msg[ndx], out font); // <------ New Character ------> <------------- Current display --------------> // current keep-clear above current below keep-clear while ( interferes(font.Bits[00] | font.Bits[15], _________ | shift[00] | shift[01] | shift[15]) || interferes(font.Bits[01] | font.Bits[15], shift[00] | shift[01] | shift[02] | shift[15]) || interferes(font.Bits[02] | font.Bits[15], shift[01] | shift[02] | shift[03] | shift[15]) || interferes(font.Bits[03] | font.Bits[15], shift[02] | shift[03] | shift[04] | shift[15]) || interferes(font.Bits[04] | font.Bits[15], shift[03] | shift[04] | shift[05] | shift[15]) || interferes(font.Bits[05] | font.Bits[15], shift[04] | shift[05] | shift[06] | shift[15]) || interferes(font.Bits[06] | font.Bits[15], shift[05] | shift[06] | shift[07] | shift[15]) || interferes(font.Bits[07] | font.Bits[15], shift[06] | shift[07] | shift[08] | shift[15]) || interferes(font.Bits[08] | font.Bits[15], shift[07] | shift[08] | shift[09] | shift[15]) || interferes(font.Bits[09] | font.Bits[15], shift[08] | shift[09] | shift[10] | shift[15]) || interferes(font.Bits[10] | font.Bits[15], shift[09] | shift[10] | shift[11] | shift[15]) || interferes(font.Bits[11] | font.Bits[15], shift[10] | shift[11] | shift[12] | shift[15]) || interferes(font.Bits[12] | font.Bits[15], shift[11] | shift[12] | shift[13] | shift[15]) || interferes(font.Bits[13] | font.Bits[15], shift[12] | shift[13] | shift[14] | shift[15]) || interferes(font.Bits[14] | font.Bits[15], shift[13] | shift[14] | _________ | shift[15])) { doShift(); yield return(context.CurTime + steptime); } doShift(); yield return(context.CurTime + steptime); shift[0] |= font.Bits[0]; shift[1] |= font.Bits[1]; shift[2] |= font.Bits[2]; shift[3] |= font.Bits[3]; shift[4] |= font.Bits[4]; shift[5] |= font.Bits[5]; shift[6] |= font.Bits[6]; shift[7] |= font.Bits[7]; shift[8] |= font.Bits[8]; shift[9] |= font.Bits[9]; shift[10] |= font.Bits[10]; shift[11] |= font.Bits[11]; shift[12] |= font.Bits[12]; shift[13] |= font.Bits[13]; shift[14] |= font.Bits[14]; shift[15] |= font.Bits[15]; } while (((shift[0] | shift[1] | shift[2] | shift[3] | shift[4] | shift[5] | shift[7] | shift[8] | shift[9] | shift[10] | shift[11] | shift[12] | shift[13] | shift[14]) & 0xffffff) != 0) { doShift(); yield return(context.CurTime + steptime); } }
public IEnumerable <int> Xeq(RunTime context) { //this.context = context; //var trgt = (DisplayUpdate)Eval(_trgt); //if (!(trgt is DisplayUpdate)) // throw new Exception("Invalid target:" + _trgt); //var steps = trans.Steps.Max(); //var queue = new List<DisplayUpdate>(); //var intr = steps == 0 ? 0 : ((_stopTime - _startTime) / (steps)); //var prv = Global.Instance.curr; //var dta = Global.Instance.dta; //for (int stp = -_gap; stp < steps; stp++) //{ // var nxt = prv.Clone(); // for (int ndx = 0; ndx < 307; ndx++) // { // var stpno = trans.Steps[ndx]; // if (_reverse) stpno = (short)(steps - stpno); // if (stpno == stp) // nxt[dta[ndx]] = trgt[dta[ndx]]; // else if ((_gap > 0) && (stpno - stp == _gap)) // nxt[dta[ndx]] = false; // } // nxt.Time = tim; // tim += intr; // queue.Add(nxt); // prv = nxt; //} //curr.Return(); //trgt.Time = tim; //queue.Add(trgt); //return PlayUpdates(queue); //yield return context.CurTime + steptime; int[] bgnndx = Global.Instance.LitDict.Values.OfType <Lit>() .Where(v => v.Name.StartsWith(text)) .OrderByDescending(v => v.Row).ThenBy(v => v.Column) .Select(v => v.GlobalIndex).ToArray(); if (mode == 1) { int intr = (EndPoint.X - StartPoint.X) / 20; for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { context[bgnndx[row * 11 + col]] = array[row, col]; } yield return(StartPoint.X + intr * (row + 1)); } } else { int thrds = (EndPoint.X - StartPoint.X) / 3; int intr = thrds / 10; for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { context[bgnndx[row * 11 + col]] = array[row, col]; } yield return(context.CurTime + intr); } yield return(StartPoint.X + thrds); int pre = 0; int nxt = 11; int starttime = context.CurTime; int endtime = context.CurTime + thrds; while (context.CurTime < endtime) { float fraction = 2 * (context.CurTime - starttime) / (float)thrds; if (fraction > 1) { break; } for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { context[bgnndx[row * 11 + col]] = factor(array[row, col + pre], array[row, col + nxt], fraction); } } yield return(context.CurTime + 4); } yield return(endtime); pre = 11; nxt = 22; starttime = context.CurTime; endtime = EndPoint.X; while (context.CurTime < endtime) { float fraction = 2 * (context.CurTime - starttime) / (float)thrds; if (fraction > 1) { break; } for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { context[bgnndx[row * 11 + col]] = factor(array[row, col + pre], array[row, col + nxt], fraction); } } yield return(context.CurTime + 4); } } yield return(EndPoint.X); for (int row = 0; row < 9; row++) { for (int col = 0; col < 11; col++) { context[bgnndx[row * 11 + col]] = System.Drawing.Color.Black; } } }