Need help in understanding music theory
Opened this issue · 0 comments
sabihoshi commented
Hello, I've been trying to port your project into one for Genshin Impact's Lyre.
I don't know much about music theory, so I would like some help on how I'd do it. I mostly just experimented, and I ended up changing just the part which key corresponded to which note, as well as remove vibrator and mostly keep the transposition code intact.
Unfortunately, there is no such thing as flat notes or sharps in the lyre so it sounds like this:
2021-03-30_19-19-47.mp4
The keyboard layout of the lyre is
QWERTYU
ASDFGHJ
ZXCVBNM
In turn, I asked someone with some music knowledge to help me and I ended up with this format, I don't know if it's exactly correct though, but here is an example of how it sounds like.
2021-03-30_17-30-56.mp4
private static readonly Dictionary<int, VirtualKeyCode> lyreNotes = new Dictionary<int, VirtualKeyCode>
{
{45, VirtualKeyCode.VK_Z}, // A2
{47, VirtualKeyCode.VK_X}, // B2
{49, VirtualKeyCode.VK_C}, // C2
{50, VirtualKeyCode.VK_V}, // D3
{52, VirtualKeyCode.VK_B}, // E3
{54, VirtualKeyCode.VK_N}, // F#3
{56, VirtualKeyCode.VK_M}, // G#3
{57, VirtualKeyCode.VK_A}, // A3
{59, VirtualKeyCode.VK_S}, // B3
{61, VirtualKeyCode.VK_D}, // C#3
{62, VirtualKeyCode.VK_F}, // D4
{64, VirtualKeyCode.VK_G}, // E4
{66, VirtualKeyCode.VK_H}, // F#4
{68, VirtualKeyCode.VK_J}, // G#4
{69, VirtualKeyCode.VK_Q}, // A4
{71, VirtualKeyCode.VK_W}, // B4
{73, VirtualKeyCode.VK_E}, // C#4
{74, VirtualKeyCode.VK_R}, // D5
{76, VirtualKeyCode.VK_T}, // E5
{78, VirtualKeyCode.VK_Y}, // F#5
{80, VirtualKeyCode.VK_U} // G#5
};
public static bool PlayNote(NoteOnEvent note, bool enableVibrato, bool transposeNotes)
{
if (!IsWindowFocused(_lpWindowName))
return false;
var noteId = (int) note.NoteNumber;
if (!lyreNotes.ContainsKey(noteId) && transposeNotes)
noteId = TransposeNote(noteId);
PlayNote(noteId);
return true;
}
private static int TransposeNote(int noteId)
{
while (true)
{
if (lyreNotes.ContainsKey(noteId)) return noteId;
if (noteId < lyreNotes.Keys.First())
noteId = lyreNotes.Keys.First() + noteId % 12;
else if (noteId > lyreNotes.Keys.Last())
noteId = lyreNotes.Keys.Last() - 15 + noteId % 12;
else
noteId++;
}
}