-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Greensleeves" song #5
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Greensleeves.swift | ||
// ForceTouchPlayer | ||
// | ||
// Created by Arthur Ginzburg on 29.01.2023. | ||
// Copyright © 2023 Danilo Campana Fuchs. All rights reserved. | ||
// | ||
// Adapted from https://github.com/robsoncouto/arduino-songs/blob/master/greensleeves/greensleeves.ino | ||
// | ||
|
||
import Foundation | ||
|
||
// matched from different songs that existed in both this repo and the arduino-songs repo. | ||
//let DURATION_OVERRIDE_MINUS_16 = 0.375; // from Doom | ||
let DURATION_OVERRIDE_MINUS_8 = 0.5; // out of thin air, did not find references. | ||
//let DURATION_OVERRIDE_MINUS_4 = 1; | ||
let DURATION_OVERRIDE_MINUS_2 = 2.0; | ||
let DURATION_OVERRIDE_2 = 0.9; // out of thin air, did not find references. | ||
let DURATION_OVERRIDE_4 = 0.75; | ||
let DURATION_OVERRIDE_8 = 0.25; | ||
let DURATION_OVERRIDE_16 = 0.1; // out of thin air, did not find references. | ||
|
||
// TODO: prevent these constants from being global. They should only be relevant for this song (but I did not check this approach with other songs). | ||
|
||
// just replaced every 5 with 2, and every 4 with 1 for now, nothing complicated. But it worked. | ||
let OVERRIDE_NOTE_G4 = NOTE_G1; | ||
let OVERRIDE_NOTE_AS4 = NOTE_AS1; | ||
let OVERRIDE_NOTE_C5 = NOTE_C2; | ||
let OVERRIDE_NOTE_D5 = NOTE_D2; | ||
let OVERRIDE_NOTE_DS5 = NOTE_DS2; | ||
let OVERRIDE_NOTE_A4 = NOTE_A1; | ||
let OVERRIDE_NOTE_F4 = NOTE_F1; | ||
let OVERRIDE_NOTE_FS4 = NOTE_FS1; | ||
let OVERRIDE_NOTE_D4 = NOTE_D1; | ||
let OVERRIDE_NOTE_E4 = NOTE_E1; | ||
let OVERRIDE_NOTE_F5 = NOTE_F2; // highest note | ||
let OVERRIDE_NOTE_E5 = NOTE_E2; | ||
|
||
let greensleeves = Song( | ||
name: "Greensleeves", | ||
defaultTempo: 82.0, // searched the Web for "greensleeves bpm" | ||
padding: Note(frequency: REST, value: 0.28), // out of thin air. Chose a value that made the song slow enough but still melodical. | ||
rawNotes: [ | ||
// Translated these notes from arduino to Swift this way: | ||
// Opened https://chat.openai.com | ||
// Texted: `Group this C array by each 2 values and translate into Swift:`, added a newline, and pasted the arduino array. And sent the message to the AI. | ||
(OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_C5,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_DS5,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_C5,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_F4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_A4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_D4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), | ||
|
||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_C5,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_DS5,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_C5,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_F4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_E4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_G4,DURATION_OVERRIDE_MINUS_2), | ||
(OVERRIDE_NOTE_F5,DURATION_OVERRIDE_2), (OVERRIDE_NOTE_E5,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_8), | ||
|
||
(OVERRIDE_NOTE_C5,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_F4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_A4,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_D4,DURATION_OVERRIDE_4), | ||
(OVERRIDE_NOTE_F5,DURATION_OVERRIDE_2), (OVERRIDE_NOTE_E5,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_D5,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_C5,DURATION_OVERRIDE_4), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_F4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_8), | ||
|
||
(OVERRIDE_NOTE_AS4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_A4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_G4,DURATION_OVERRIDE_8), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_MINUS_8), (OVERRIDE_NOTE_E4,DURATION_OVERRIDE_16), (OVERRIDE_NOTE_FS4,DURATION_OVERRIDE_8), | ||
(OVERRIDE_NOTE_G4,DURATION_OVERRIDE_MINUS_2) | ||
// then it just repeats once more in the arduino code. Decided to DRY it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add a Like this: https://github.com/danilofuchs/ForceTouchPlayer/blob/main/ForceTouchPlayer/Songs/Tetris.swift There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but as a user I feel more comfortable pressing the |
||
] | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍