Skip to content
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

Different-colored keys? #2

Open
lassik opened this issue Sep 22, 2017 · 2 comments
Open

Different-colored keys? #2

lassik opened this issue Sep 22, 2017 · 2 comments

Comments

@lassik
Copy link

lassik commented Sep 22, 2017

Would you accept a feature to assign different colors to depressed keys? E.g. some of the depressed keys would be green, some red, and the remaining non-depressed keys would be black/white. Something like:

type alias Color = String
notes : Set.Set Note
noteColor : Note -> Color

Or:

notes : Dict.Dict Note Color
@cript0nauta
Copy link
Owner

Hi @lassik! It seems to be a really nice feature to have. Now the color of the keys is hardcoded inside the CSS, but it would be great to control both pressed and unpressed keys colors from the model instead.

I think having a colorOverrides : Dict.Dict Note Color dict in the model would be a better approach than having a function, since it would be more extensible and because having a function in a model is not so common as having a dict.

If you wanted to use it with a function, you could do this when updating the model:

colors =
    List.range 0 127 -- MIDI note numbers
    |> List.map (\note -> (note, noteColor note) )
    |> Dict.fromList

newPianoModel = { pianoModel | colorOverrides = colors }

To check if each key is pressed or unpressed you could check if the note number is member of the pianoModel.notes.

I'm a bit busy this days to code it, but I'll probably have some free time in a couple of weeks to give a look to this. Pull Request are also welcome :P

@cript0nauta
Copy link
Owner

Hi again! Sorry for the delay. I have been working on this feature, it seems to be finished now but I would like some feedback before publishing.

I changed the approach a bit, but it is basically the same idea: having a dict allowing the users of the library to override the colors of some notes. I used the native Color type to specify the color.

If you still interested, you could review this changes. The files examples/Basic.elm and examples/PlayMIDI.elm (this last one should be used with the examples/playmidi.html file) show a simple and a more complex way of using custom colors.

To correctly run the PlayMIDI example you have to clone the repo https://github.com/mudcube/MIDI.js into the directory examples/bower_components/midi and to run elm-make examples/PlayMIDI.elm --output examples/PlayMIDI.js. (I know I should improve this process :P).

Let me know if you have any problems or suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants