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

extVarious-midiname: Array, or would SequenceableCollection be better? #23

Open
jamshark70 opened this issue Jul 26, 2022 · 2 comments
Open

Comments

@jamshark70
Copy link

Array.fillNoteNames
-> [ C3, C#3, D3, Eb3, E3, F3, F#3, G3, G#3, A3, Bb3, B3 ]

List.fillNoteNames
^^ ERROR: Message 'fillNoteNames' not understood.

It seems to me that this might not be an intentional limitation.

Shouldn't these methods be defined on SequenceableCollection?

One peculiar side effect is that Array.fillNoteNames clobbers Array.fill in SC-IDE's auto-completion menu. *fill is defined on Collection, so it ends up lower in the list than the less-frequently-used *fillNoteNames. I believe this would be avoided by defining it higher in the class tree.

@woutersnoei
Copy link
Contributor

Hi James, sorry for the delay, just checking issues now. Yes, makes sense. It would require a bit of rework though, if I just change Array into SequenceableCollection the code "List.fillNoteNames" will render an Array of notenames instead of a list (don't know if that's necessarily a problem but it would seem a bit unclear). Also, I just tried, but it seems that for the completion menu it doesn't make a difference if fillNoteNames is in Array or SequenceableCollection; it still shows up first..

@jamshark70
Copy link
Author

Probably like this:

+ SequenceableCollection {
	*fillNoteNames { arg startNote = "C3", endNote = "B3", step=1;
		// equal to Array.makeScale(type:'chromatic') but probably faster..
		var startNoteMidi = startNote.namemidi;
		^this.series(
			(endNote.namemidi - startNoteMidi + 1) div: step,
			startNoteMidi,
			step
		).collectAs(_.midiname, this)
	}
}

In a class method, using this to invoke the specific subclass is a common pattern. (collectAs is needed because aList.collect produces an array, grrrr.)

Similar could be applied to other methods in the same file.

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