private void ChangeTempo(double newTempo) { if (Math.Abs(Tempo - newTempo) < double.Epsilon) { return; } var oldTempo = Tempo; TempoChanged?.Invoke(this, new TempoChangedEventArgs(oldTempo, newTempo)); Tempo = newTempo; RecalcTickTime(); }
public void OnTempoChanged(int tempo) { TempoChanged?.Invoke(this, new TempoChangedEventArgs { TempoBPM = tempo }); }
/// <summary> /// performs a single song-position-advance /// </summary> void TrackStepExecute() { trackstepWait = 0; if (trackstepPosition > tfx.SongEndPositions[songNo] || trackstepPosition >= tfx.Tracksteps.Length) { Paula.Reset(); if (trackstepPosition < tfx.Tracksteps.Length) { TrackstepPositionChanged?.Invoke(this, EventArgs.Empty); } SongEnded?.Invoke(this, EventArgs.Empty); trackstepWait = 1; stopped = true; return; } if (tfx.Tracksteps[trackstepPosition][0] == 0xEFFE) { var line = tfx.Tracksteps[trackstepPosition]; switch (line[1]) { case 0: // stop the player stopped = true; break; case 1: // Play a section starting at position and ending here times // times. If times is 0000 then section will repeat forever. // line+4=position, line+6=times int position = line[2]; int times = line[3]; trackstepPosition = position; // TD: error-check, count loops break; case 2: // set the tempo // TD break; case 3: // start a master volume slide (?) if (line[3] == 0xEE) { --tempoNumber; //Frequency = 14; TempoChanged?.Invoke(this, EventArgs.Empty); } else if (line[3] == 0x10) { //Frequency = 30; TempoChanged?.Invoke(this, EventArgs.Empty); } break; case 4: break; default: break; } } else { for (int i = 0; i < 8; ++i) { var track = tracks[i]; var d = tfx.Tracksteps[trackstepPosition][i]; int stepPattern = d >> 8; int stepTranspose = (sbyte)(d & 0xFF); // init pattern track.PatternPC = 0; track.NumWait = 0; track.NumPatternLoop = 0; // TD: handle 0xFE correctly! if (stepPattern >= 0x80) { if (stepPattern != 0x80) { track.PatternNo = -1; } } else { Log("starting pattern " + track.PatternNo + " in tick " + tickCounter); track.PatternNo = stepPattern; track.Transpose = stepTranspose; } } trackstepWait = 1; } TrackstepPositionChanged?.Invoke(this, EventArgs.Empty); ++trackstepPosition; }
public void SelectFile(string fileName) { InvalidFile = false; InvalidFileChanged?.Invoke(this, EventArgs.Empty); if (Playing) { Stop(); } _source = null; string extension = Path.GetExtension(fileName).ToLower(); try { if (extension == ".mp3") { _source = new Mp3FileReader(fileName); } else if (extension == ".wav") { _source = new WaveFileReader(fileName); } else if ((extension == ".fla") || (extension == ".flac")) { _source = new FlacReader(fileName); } } catch { InvalidFile = true; InvalidFileChanged?.Invoke(this, EventArgs.Empty); _source = null; } TotalTimeChanged?.Invoke(this, EventArgs.Empty); if (_source == null) { return; } _stretcher = new RubberBandWaveStream(_source); _stretcher.SourceRead += (sender, e) => { CurrentTimeChanged?.Invoke(this, e); }; _stretcher.EndOfStream += (sender, e) => { ReachedEnd?.Invoke(this, e); Stop(); }; TempoChanged?.Invoke(this, EventArgs.Empty); CurrentTimeChanged?.Invoke(this, EventArgs.Empty); _waveOut.Init(_stretcher); }