Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Mar 23, 2019
1 parent 9727deb commit b325dca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ A given chord structure will locate snippets and transpose them to the correspon
- [x] Add sustain: use triggerAttack instead of triggerAttackRelease when enabled
- [ ] Add two midi channels to frontend (merge them in JSON)

## Inspiration

This project is inspired out what is possible with simple repetitive elements on the piano. I took a lot of inspriation from [Ólafur Arnalds](https://en.wikipedia.org/wiki/%C3%93lafur_Arnalds#re:member_(2018)), [Dan Tepfer](https://www.npr.org/2017/07/24/538677517/fascinating-algorithm-dan-tepfers-player-piano-is-his-composing-partner), and the minimal music style from [Philip Glass](https://en.wikipedia.org/wiki/Philip_Glass#1967%E2%80%931974:_Minimalism:_From_Strung_Out_to_Music_in_12_Parts).

## Credits

Piano sounds from [University of Iowa](http://theremin.music.uiowa.edu/MISpiano.html). The first part of the silence is removed with ffmpeg.
Expand All @@ -32,4 +36,4 @@ for i in *aiff; do ffmpeg -i "$i" -af silenceremove=1:0:-50dB "${i%.*}.mp3"; don

## License

MIT
MIT
12 changes: 10 additions & 2 deletions src/midi/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import (
)

type Phrase struct {
Filename string
Filename string
// TotalNotes has the total number of notes
TotalNotes int
IsMinor bool
// IsMinor indicates a C-minor key
IsMinor bool
// RH indicates whether it is a right-handed piece
RH bool
}

func Analyze(fnames []string) (phrases []Phrase, err error) {
Expand Down Expand Up @@ -46,6 +50,7 @@ func analyze(fname string) (p Phrase, err error) {
rd := smfreader.New(f)

var m midi.Message
noteSum := 0.0
for {
m, err = rd.Read()
if err != nil {
Expand All @@ -58,9 +63,12 @@ func analyze(fname string) (p Phrase, err error) {
if strings.Contains(utils.MidiToNote(v.Key()), "Eb") {
p.IsMinor = true
}
noteSum += float64(v.Key())
}
}

p.RH = noteSum/float64(p.TotalNotes) > 60

if err == smf.ErrFinished {
err = nil
}
Expand Down
28 changes: 10 additions & 18 deletions src/midi/combiner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@ func TestCombine(t *testing.T) {
assert.Nil(t, err)
fmt.Println(phrases)
phraseList := []string{
GetRandomPhrase(phrases, "D", true),
GetRandomPhrase(phrases, "D", true),
GetRandomPhrase(phrases, "F", false),
GetRandomPhrase(phrases, "F", false),
GetRandomPhrase(phrases, "A", true),
GetRandomPhrase(phrases, "A", true),
GetRandomPhrase(phrases, "C", false),
GetRandomPhrase(phrases, "C", false),
GetRandomPhrase(phrases, "D", true),
GetRandomPhrase(phrases, "D", true),
GetRandomPhrase(phrases, "F", false),
GetRandomPhrase(phrases, "F", false),
GetRandomPhrase(phrases, "A", true),
GetRandomPhrase(phrases, "A", true),
GetRandomPhrase(phrases, "C", false),
GetRandomPhrase(phrases, "C", false),
GetRandomPhrase(phrases, "D", true, true, 8, 40),
GetRandomPhrase(phrases, "D", true, true, 8, 40),
GetRandomPhrase(phrases, "F", false, true, 8, 40),
GetRandomPhrase(phrases, "F", false, true, 8, 40),
GetRandomPhrase(phrases, "D", true, true, 8, 44),
GetRandomPhrase(phrases, "D", true, true, 8, 44),
GetRandomPhrase(phrases, "A", true, true, 8, 40),
GetRandomPhrase(phrases, "A", true, true, 8, 40),
}
fmt.Println(phraseList)
err = Combine(phraseList, "song1.mid")
Expand All @@ -40,9 +32,9 @@ func TestCombine(t *testing.T) {

var r = rand.New(rand.NewSource(time.Now().Unix()))

func GetRandomPhrase(phrases []Phrase, note string, minor bool) string {
func GetRandomPhrase(phrases []Phrase, note string, minor bool, rh bool, minNotes, maxNotes int) string {
for _, i := range r.Perm(len(phrases)) {
if phrases[i].IsMinor != minor {
if phrases[i].IsMinor != minor || phrases[i].RH != rh || phrases[i].TotalNotes < minNotes || phrases[i].TotalNotes > maxNotes {
continue
}
return phrases[i].Filename + ".tr" + note + ".mid"
Expand Down

0 comments on commit b325dca

Please sign in to comment.