public static PianoSettings Instance() { if (settings == null) { settings = new PianoSettings(); settings.Load(); } return(settings); }
private void ParseVariablePause(string line, Variable variable) { ++currentIndex; var pauseElement = new PauseElement(); if (line[currentIndex] == '_') { ++currentIndex; string numStr; currentIndex = ParserHelper.ReadNumber(line, currentIndex, true, out numStr); if (string.IsNullOrEmpty(numStr)) { throw new CompilationException($"'{line[currentIndex]}' isn't a number at {currentLine}:{currentIndex}"); } pauseElement.Duration = PianoSettings.Instance().GetNoteDuration(GetDuration(numStr)); } else if (line[currentIndex] == '@') { ++currentIndex; string varName; currentIndex = ParserHelper.ReadWord(line, currentIndex, out varName); if (string.IsNullOrEmpty(varName)) { throw new CompilationException($"Invalid variable name at {currentLine}:{currentIndex}"); } pauseElement.WaitForVariable = varName; } else { string numStr; currentIndex = ParserHelper.ReadNumber(line, currentIndex, false, out numStr); if (string.IsNullOrEmpty(numStr)) { throw new CompilationException($"'{line[currentIndex]}' isn't a number at {currentLine}:{currentIndex}"); } bool ok = double.TryParse(numStr, out pauseElement.Duration); if (!ok) { throw new CompilationException($"'{numStr}' isn't a number at {currentLine}:{currentIndex}"); } } variable.Elements.Add(pauseElement); }
public static WavInfo GetNote(string note, int pressLevel, double duration) { var settings = PianoSettings.Instance(); return(WavEditor.Modify( WavIO.Load($"D:\\Projects\\PianoGenerator\\PianoGenerator\\bin\\Debug\\Resources\\Notes\\{settings.GetNoteName(note, pressLevel)}") ) .FreezeRegion(0, duration) .MultiplyWith((double x, double i) => Math.Max(0, 1 - settings.GetReleaseKeyK() * i), true) .GetWav()); }
public static WavInfo GetNote(string note, int pressLevel, PianoSettings.NoteDuration duration) { return(GetNote(note, pressLevel, PianoSettings.Instance().GetNoteDuration(duration))); }
private void ParseVariableNote(string line, Variable variable) { var noteElement = new NoteElement(); if (line[currentIndex] == '~') { noteElement.Note = ParseRelativeVariable(line, variable); } else { StringBuilder note = new StringBuilder(line.Substring(currentIndex, 2), 3); if (line[currentIndex] < 'A' || line[currentIndex] > 'G') { throw new CompilationException($"Expected a value between 'A' and 'G' not '{line[currentIndex]}' at {currentLine}:{currentIndex}"); } if (line[currentIndex + 1] < '1' || line[currentIndex + 1] > '6') { throw new CompilationException($"Expected a value between '1' and '6' not '{line[currentIndex + 1]}' at {currentLine}:{currentIndex}"); } currentIndex += 2; if (line[currentIndex] == '#' || line[currentIndex] == 'b') { if (line[currentIndex] == '#') { HigherNote(note); } if (!HasBemolle(note)) { throw new CompilationException($"'{note}' note hasn't a bemolle! (at {currentLine}:{currentIndex})"); } note.Append(note[1]);//move a number to the 3rd position note[1] = 'b'; ++currentIndex; } noteElement.Note = note.ToString(); } if (line[currentIndex] != '!') { throw new CompilationException($"Expected '!' at {currentLine}:{currentIndex}"); } ++currentIndex; if (!char.IsDigit(line[currentIndex])) { throw new CompilationException($"Expected digit at {currentLine}:{currentIndex}"); } noteElement.PressLevel = line[currentIndex] - '0'; if (noteElement.PressLevel > 3 || noteElement.PressLevel < 1) { throw new CompilationException($"Invalid press value '{noteElement.PressLevel}' at {currentLine}:{currentIndex}"); } ++currentIndex; if (line[currentIndex] == '_') { ++currentIndex; if (!char.IsDigit(line[currentIndex])) { throw new CompilationException($"Expected a digit at {currentLine}:{currentIndex}"); } string numberStr; currentIndex = ParserHelper.ReadNumber(line, currentIndex, true, out numberStr); if (string.IsNullOrEmpty(numberStr)) { throw new CompilationException($"Expected a number at {currentLine}:{currentIndex}"); } noteElement.Duration = PianoSettings.Instance().GetNoteDuration(GetDuration(numberStr)); } else if (line[currentIndex] == '=') { ++currentIndex; string numberStr; currentIndex = ParserHelper.ReadNumber(line, currentIndex, false, out numberStr); if (string.IsNullOrEmpty(numberStr)) { throw new CompilationException($"Expected a number at {currentLine}:{currentIndex}"); } double duration; bool ok = double.TryParse(numberStr, out duration); if (!ok) { throw new CompilationException($"Expected a number at {currentLine}:{currentIndex}"); } noteElement.Duration = duration; } else { throw new CompilationException($"Expected '_' or '=' at {currentLine}:{currentIndex}"); } variable.Elements.Add(noteElement); }