public void AddPianoRollItem(SongEvent e, float futureTick) { Vector3[] keyWidth = PianoDescriptor.getPianoDescriptor().getKeyWidth(e.KeyID, false); float girth = .5f * (keyWidth[0] - keyWidth[1]).magnitude; float duration = Note.GetDuration(e.NoteType); float length = PIXELPERBEAT * duration; float center = e.EndPoint - Timing.CurrentMeasure - (duration / 2f); float z_depth = center * PIXELPERBEAT; Vector3 midpoint = ((keyWidth[0] + keyWidth[1]) / 2f); float x_center = midpoint.x; float y_center = midpoint.y; GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.GetComponent <MeshRenderer>().sharedMaterial = PianoRollMatRef; cube.name = "rolling" + e.KeyID.ToString().PadLeft('0'); cube.tag = "PianoRoll"; PianoRoll r = cube.AddComponent <PianoRoll>(); r.e = e; r.endPoint = e.EndPoint; r.duration = duration; r.startPoint = e.StartPoint; cube.transform.parent = pianoRollContainer.transform; cube.transform.localPosition = new Vector3(x_center, y_center, z_depth); cube.transform.localScale = new Vector3(girth, 0.01f, length); cube.transform.rotation = GameObject.Find("MainApp").gameObject.transform.rotation; }
public void StopNote(Song song, float time, int voiceNumber) { var songEvent = new SongEvent(time, voiceNumber); var voice = song.Voices[voiceNumber]; voice .Events .Add(songEvent); }
void AddEvent(object sender, EventArgs e) { var cmd = (ICommand)Activator.CreateInstance(Engine.GetCommands()[commandsBox.SelectedIndex].GetType()); var ev = new SongEvent(0xFFFFFFFF, cmd); int index = listView.SelectedIndex + 1; SongPlayer.Song.InsertEvent(ev, currentTrack, index); SongPlayer.RefreshSong(); LoadTrack(currentTrack); SelectItem(index); }
public void AddNoteToSong(Song song, float time, int voiceNumber, float volume, MusicalNote note, NoteTimbre timbre, int octaveChange) { var songEvent = new SongEvent(time, voiceNumber, volume, note .Clone(timbre, octaveChange)); var voice = song.Voices[voiceNumber]; voice .Events .Add(songEvent); }
private void startDroplet(SongEvent e, float currentMeasure) { if (e.IsStart) { return; } if (e.KeyID == 0) { return; } keyHighlighter.AddPianoRollItem(e, currentMeasure); }
protected void SpawnKey(SongEvent songEvent) { var button = Instantiate(Prefab); button .transform .SetParent(ScrollingPanel); button.Image.rectTransform.anchoredPosition = new Vector2(SpawnX, 0); KeyboardKeys .Add(button); float moveOver = 100 + ((50 - LevelManager.LevelNumber) * 2); SpawnX += moveOver; int maxNumber = 2; if (LevelManager.LevelNumber >= 45) { maxNumber = 8; } else if (LevelManager.LevelNumber >= 35) { maxNumber = 7; } else if (LevelManager.LevelNumber >= 25) { maxNumber = 6; } else if (LevelManager.LevelNumber >= 15) { maxNumber = 5; } else if (LevelManager.LevelNumber >= 8) { maxNumber = 4; } else if (LevelManager.LevelNumber >= 4) { maxNumber = 3; } int i = Random.Range(0, maxNumber); int spriteIndex = i * 2; button.Image.sprite = KeyboardSprites[spriteIndex]; button.SpriteIndex = spriteIndex; button.HasBeenActivated = false; button.KeyCode = KeyCodes[i]; }
private void SetTicks() { MaxTicks = 0; bool u = false; for (int trackIndex = 0; trackIndex < 0x10; trackIndex++) { if (Events[trackIndex] != null) { Events[trackIndex] = Events[trackIndex].OrderBy(e => e.Offset).ToList(); List <SongEvent> evs = Events[trackIndex]; Track track = _tracks[trackIndex]; track.Init(); ElapsedTicks = 0; while (true) { SongEvent e = evs[track.CurEvent]; if (e.Ticks.Count > 0) { break; } else { e.Ticks.Add(ElapsedTicks); ExecuteNext(trackIndex, ref u); if (track.Stopped) { break; } else { ElapsedTicks += track.Rest; track.Rest = 0; } } } if (ElapsedTicks > MaxTicks) { _longestTrack = trackIndex; MaxTicks = ElapsedTicks; } track.NoteDuration = 0; } } }
private void SetTicks() { MaxTicks = 0; bool u = false; for (int trackIndex = 0; trackIndex < NumTracks; trackIndex++) { if (Events[trackIndex] == null) { continue; } Events[trackIndex] = Events[trackIndex].OrderBy(e => e.Offset).ToList(); List <SongEvent> evs = Events[trackIndex]; Track track = _tracks[trackIndex]; track.Init(); ElapsedTicks = 0; while (true) { SongEvent e = evs.Single(ev => ev.Offset == track.DataOffset); if (e.Ticks.Count > 0) { break; } e.Ticks.Add(ElapsedTicks); ExecuteNext(track, ref u); if (track.Stopped) { break; } ElapsedTicks += track.Rest; track.Rest = 0; } if (ElapsedTicks > MaxTicks) { _longestTrack = trackIndex; MaxTicks = ElapsedTicks; } track.NoteDuration = 0; } }
public void SongEventsValid(SngFile song) { SongEvent lastSongEvent = null; foreach (var songEvent in song.SongEvents) { if (lastSongEvent != null) { Assert.LessOrEqual(lastSongEvent.Time, songEvent.Time); } //Just make sure the time is sane Assert.Less(songEvent.Time, 2000); Assert.GreaterOrEqual(songEvent.Time, 0); ValidString(songEvent.Code); lastSongEvent = songEvent; } }
int IComparer.Compare(object a, object b) { SongEvent c1 = (SongEvent)a; SongEvent c2 = (SongEvent)b; if (c1.EndPoint > c2.EndPoint) { return(1); } if (c1.EndPoint < c2.EndPoint) { return(-1); } else { return(0); } }
private void SetTicks() { MaxTicks = 0; for (int trackIndex = 0; trackIndex < Events.Length; trackIndex++) { Events[trackIndex] = Events[trackIndex].OrderBy(e => e.Offset).ToList(); List <SongEvent> evs = Events[trackIndex]; Track track = _tracks[trackIndex]; track.Init(); ElapsedTicks = 0; while (true) { SongEvent e = evs.Single(ev => ev.Offset == track.CurOffset); if (e.Ticks.Count > 0) { break; } else { e.Ticks.Add(ElapsedTicks); ExecuteNext(track); if (track.Stopped) { break; } else { ElapsedTicks += track.Rest; track.Rest = 0; } } } if (ElapsedTicks > MaxTicks) { _longestTrack = trackIndex; MaxTicks = ElapsedTicks; } track.StopAllChannels(); } }
//append an event to the song private void Append(SongEvent songEvent) { events.Add(songEvent); }
private void Tick() { _time.Start(); while (true) { PlayerState state = State; bool playing = state == PlayerState.Playing; bool recording = state == PlayerState.Recording; if (!playing && !recording) { goto stop; } void MixerProcess() { _mixer.ChannelTick(); _mixer.Process(playing, recording); } while (_tempoStack >= 240) { _tempoStack -= 240; bool allDone = true; for (int trackIndex = 0; trackIndex < _tracks.Length; trackIndex++) { Track track = _tracks[trackIndex]; track.Tick(); while (track.Rest == 0 && !track.Stopped) { ExecuteNext(track); } if (trackIndex == _longestTrack) { if (ElapsedTicks == MaxTicks) { if (!track.Stopped) { List <SongEvent> evs = Events[trackIndex]; for (int i = 0; i < evs.Count; i++) { SongEvent ev = evs[i]; if (ev.Offset == track.CurOffset) { ElapsedTicks = ev.Ticks[0] - track.Rest; break; } } _elapsedLoops++; if (ShouldFadeOut && !_mixer.IsFading() && _elapsedLoops > NumLoops) { _mixer.BeginFadeOut(); } } } else { ElapsedTicks++; } } if (!track.Stopped || track.Channels.Count != 0) { allDone = false; } } if (_mixer.IsFadeDone()) { allDone = true; } if (allDone) { MixerProcess(); State = PlayerState.Stopped; SongEnded?.Invoke(); } } _tempoStack += _tempo; MixerProcess(); if (playing) { _time.Wait(); } } stop: _time.Stop(); }
public override void Reset() { songEvent = SongEvent.OnSongEnd; evt = null; }
protected override void OnPaint(PaintEventArgs e) { var bg = new SolidBrush(Theme.PlayerColor); e.Graphics.FillRectangle(bg, e.ClipRectangle); float ih = Height / 25.125f; // Info height float iy = ih - (e.Graphics.MeasureString("A", Font).Height * 1.125f); // Info y int co = (checkboxSize - 13) / 2; // Checkbox offset float px = checkboxSize * 2 + co * 2; // Position x int FWidth = Width - (int)px; // Fake width float dex = px + FWidth / 5.75f; // Del x float dx = dex - e.Graphics.MeasureString("Delay", Font).Width + e.Graphics.MeasureString("99", Font).Width; // "Delay" x float nx = px + FWidth / 4.4f; // Notes x float td = FWidth / 100f; // Voice type difference float ix = px + FWidth - td; float itx = ix - e.Graphics.MeasureString("Type", Font).Width; // "Type" x float vox = px + FWidth / 25f; // Voices x float r2d = FWidth / 15f; // Row 2's addition per element float ym = Height / 200f; // y margin float th = (Height - ym) / 16.5f; // Track height float r2o = th / 2.5f; int bh = (int)(Height / 30.3f); // Bar height int bx = (int)(px + FWidth / 2.35f); // Bar start x int bw = (int)(FWidth / 2.95f); // Bar width int bwd = bw % 2; // Add/Subtract by 1 if the bar width is odd int brx = bx + bw - bwd; // Bar right bound x int cx = bx + (bw / 2); // Bar center x string tempoStr = "Tempo - " + Info.Tempo.ToString(); float tx = cx - (e.Graphics.MeasureString(tempoStr, Font).Width / 2); // "Tempo - 120" x mutes[16].Location = new Point(co, (int)iy + co); pianos[16].Location = new Point(checkboxSize + co * 2, (int)iy + co); e.Graphics.DrawString("Position", Font, Brushes.Lime, px, iy); e.Graphics.DrawString("Delay", Font, Brushes.Crimson, dx, iy); e.Graphics.DrawString("Notes", Font, Brushes.Turquoise, nx, iy); e.Graphics.DrawString("L", Font, Brushes.GreenYellow, bx - 5, iy); e.Graphics.DrawString(tempoStr, Font, Brushes.Cyan, tx, iy); e.Graphics.DrawString("R", Font, Brushes.GreenYellow, brx - 5, iy); e.Graphics.DrawString("Type", Font, Brushes.DeepPink, itx, iy); e.Graphics.DrawLine(Pens.Gold, 0, ih, Width, ih); for (int i = 0; i < SongPlayer.NumTracks; i++) { float r1y = ih + ym + (i * th); // Row 1 y float r2y = r1y + r2o; // Row 2 y int by = (int)(r1y + ym); // Bar y int pax = (int)(bx + (bw / 2) + (bw / 2 * (Info.Pans[i] / (float)Engine.GetPanpotRange()))); // Pan line x Color color = Config.Colors[Info.Voices[i]]; Pen pen = new Pen(color); var brush = new SolidBrush(color); byte velocity = (byte)((Info.Lefts[i] + Info.Rights[i]) * 0xFF); var lBrush = new LinearGradientBrush(new Point(bx, by), new Point(bx + bw, by + bh), Color.FromArgb(velocity, color), Color.FromArgb(Math.Min(velocity * 4, 0xFF), color)); mutes[i].Location = new Point(co, (int)r1y + co); // Checkboxes pianos[i].Visible = mutes[i].Visible = true; pianos[i].Location = new Point(checkboxSize + co * 2, (int)r1y + co); e.Graphics.DrawString(string.Format("0x{0:X6}", Info.Positions[i]), Font, Brushes.Lime, px, r1y); e.Graphics.DrawString(Info.Delays[i].ToString(), Font, Brushes.Crimson, dex, r1y); e.Graphics.DrawString(Info.Voices[i].ToString(), Font, brush, vox, r2y); e.Graphics.DrawString(Info.Pans[i].ToString(), Font, Brushes.OrangeRed, vox + r2d, r2y); e.Graphics.DrawString(Info.Volumes[i].ToString(), Font, Brushes.LightSeaGreen, vox + (r2d * 2), r2y); e.Graphics.DrawString(Info.Mods[i].ToString(), Font, Brushes.SkyBlue, vox + (r2d * 3), r2y); e.Graphics.DrawString(Info.Pitches[i].ToString(), Font, Brushes.Purple, vox + (r2d * 4), r2y); e.Graphics.DrawLine(Pens.GreenYellow, bx, by, bx, by + bh); // Left bar bound line if (Config.CenterIndicators) { e.Graphics.DrawLine(pen, cx, by, cx, by + bh); // Center line } if (Config.PanpotIndicators) { e.Graphics.DrawLine(Pens.OrangeRed, pax, by, pax, by + bh); // Pan line } e.Graphics.DrawLine(Pens.GreenYellow, brx, by, brx, by + bh); // Right bar bound line var rect = new Rectangle((int)(bx + (bw / 2) - (Info.Lefts[i] * bw / 2)) + bwd, by, (int)((Info.Lefts[i] + Info.Rights[i]) * bw / 2), bh); e.Graphics.FillRectangle(lBrush, rect); e.Graphics.DrawRectangle(pen, rect); string theseNotes = string.Join(" ", Info.Notes[i].Select(n => SongEvent.NoteName(n))); bool empty = string.IsNullOrEmpty(theseNotes); theseNotes = empty ? noNotes : theseNotes; if (empty && previousNotes.Item1[i]++ < Config.RefreshRate * 10) { theseNotes = previousNotes.Item2[i]; } else if (!empty || previousNotes.Item2[i] != theseNotes) { previousNotes.Item1[i] = 0; previousNotes.Item2[i] = theseNotes; } e.Graphics.DrawString(theseNotes, Font, Brushes.Turquoise, nx, r1y); var strSize = e.Graphics.MeasureString(Info.Types[i], Font); e.Graphics.DrawString(Info.Types[i], Font, Brushes.DeepPink, ix - strSize.Width, by + (r2o / (Font.Size / 2.5f))); bg.Dispose(); pen.Dispose(); brush.Dispose(); lBrush.Dispose(); } base.OnPaint(e); }
private void Tick() { _time.Start(); while (true) { PlayerState state = State; bool playing = state == PlayerState.Playing; bool recording = state == PlayerState.Recording; if (!playing && !recording) { goto stop; } void MixerProcess() { _mixer.Process(_tracks, playing, recording); } while (_tempoStack >= 75) { _tempoStack -= 75; bool allDone = true; for (int trackIndex = 0; trackIndex < NumTracks; trackIndex++) { Track track = _tracks[trackIndex]; if (track.Enabled) { byte prevDuration = track.NoteDuration; track.Tick(); bool update = false; while (track.Rest == 0 && !track.Stopped) { ExecuteNext(track, ref update); } if (trackIndex == _longestTrack) { if (ElapsedTicks == MaxTicks) { if (!track.Stopped) { List <SongEvent> evs = Events[trackIndex]; for (int i = 0; i < evs.Count; i++) { SongEvent ev = evs[i]; if (ev.Offset == track.DataOffset) { ElapsedTicks = ev.Ticks[0] - track.Rest; break; } } _elapsedLoops++; if (ShouldFadeOut && !_mixer.IsFading() && _elapsedLoops > NumLoops) { _mixer.BeginFadeOut(); } } } else { ElapsedTicks++; } } if (prevDuration == 1 && track.NoteDuration == 0) // Note was not renewed { track.Channel.State = EnvelopeState.Release; } if (!track.Stopped) { allDone = false; } if (track.NoteDuration != 0) { allDone = false; if (update) { track.Channel.SetVolume(track.Volume, track.Panpot); track.Channel.SetPitch(track.GetPitch()); } } } } if (_mixer.IsFadeDone()) { allDone = true; } if (allDone) { MixerProcess(); State = PlayerState.Stopped; SongEnded?.Invoke(); } } _tempoStack += _tempo; MixerProcess(); if (playing) { _time.Wait(); } } stop: _time.Stop(); }
// Update is called once per frame void Update() { if (HasSongChanged()) { Timing.ClearSongUpdatedFlag(); // If the song has changed, #1 -- Get the new song and generate the pending roll key list. song = Song.GetCurrentSong(); events = SongAnalyzer.generateEventList(song); currentEvent = 0; pianoRollEvent = 0; // #2 - clear error keys, regardless of expiration. Not sure why, but without this step, // keys can be redrawn as error keys after they are destroyed. foreach (var key in ErrorKeys) { keyHighlighter.SetKeyHighlight(false, key.Key); ErrorKeys.Remove(key.Key); } // #3 - Destroy all piano roll keys, and prepare the first bar keyHighlighter.DestroyAllPianoRollItems(); NextBar(0); LastBar = 1; } else { CurrentBar = Timing.GetCurrentBar(); if (CurrentBar != LastBar) { NextBar(CurrentBar - 1); } LastBar = CurrentBar; } //figure out what events happened in the last frame and handle it! if (song != null) { /* * //key highlighting. * while (currentEvent < events.Count) * { * SongEvent e = (SongEvent)events[currentEvent]; * if (e.measureNumber <=Timing.CurrentMeasure) * { * //process e. * keyHighlighter.SetKeyHighlight(e.isStart, e.keyID); * currentEvent++; * } * else { break; } * }*/ //tolerance updating: /*while (toleranceRunner < tolerance.Count) * { * SongEvent e = (SongEvent)tolerance[toleranceRunner]; * if (e.MeasureNumber <= Timing.CurrentMeasure) * { * //process e. * if (e.IsStart) activeNotes.Add(e.KeyID); * else activeNotes.Remove(e.KeyID); * toleranceRunner++; * } * else { break; } * }*/ //piano roll float futureTick = Timing.CurrentMeasure + 2 * Timing.BeatsPerMeasure; while (pianoRollEvent < events.Count) { SongEvent e = (SongEvent)events[pianoRollEvent]; if (e.EndPoint <= futureTick) { //process e. startDroplet(e, futureTick); pianoRollEvent++; } else { break; } } // clear error keys, if they have expired foreach (var key in ErrorKeys) { if (key.Value < Timing.CurrentMeasure) { keyHighlighter.SetKeyHighlight(false, key.Key); ErrorKeys.Remove(key.Key); } } } Vector3 oldpos = playhead.transform.position; playhead.transform.position = new Vector3(GetPositionFromBeat(Timing.GetCurrentBeat(), 0), oldpos.y, oldpos.z); }