Skip to content

Instantly share code, notes, and snippets.

@HoShiMin
Created June 14, 2015 18:59
Show Gist options
  • Save HoShiMin/9b4fd6117402f90104b7 to your computer and use it in GitHub Desktop.
Save HoShiMin/9b4fd6117402f90104b7 to your computer and use it in GitHub Desktop.
Хэшмап с нотами для быстрого получения частоты ноты по её названию
unit NotesSerializer;
interface
uses
NotesInfo, Generics.Collections;
type
TNotesSerializer = class
private
FNotesDictionary: TDictionary<string, Single>;
public
constructor Create;
destructor Destroy; override;
function GetFrequency(NoteName: string): Single;
end;
var
NotesList: TNotesSerializer;
implementation
{ TNotesSerializer }
constructor TNotesSerializer.Create;
var
I: Integer;
begin
FNotesDictionary := TDictionary<string, Single>.Create;
for I := 0 to Length(Notes) - 1 do
FNotesDictionary.Add(Notes[I], ChromaticGamma[I]);
end;
destructor TNotesSerializer.Destroy;
begin
FNotesDictionary.Destroy;
end;
function TNotesSerializer.GetFrequency(NoteName: string): Single;
begin
if not FNotesDictionary.TryGetValue(NoteName, Result) then Result := 0;
end;
initialization
NotesList := TNotesSerializer.Create;
finalization
NotesList.Destroy;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment