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

Save pitch name in Note struct. #165

Closed
NeroBlackstone opened this issue May 27, 2023 · 9 comments
Closed

Save pitch name in Note struct. #165

NeroBlackstone opened this issue May 27, 2023 · 9 comments

Comments

@NeroBlackstone
Copy link
Member

Is your feature request related to a problem? Please describe.
If we initialize a Note with pitch name with flat:

n = Note("Bb4")
#@show n : Note A♯4 | vel = 100 | pos = 0, dur = 960

But in some cases, we want to save exact pitch name Bb4/

Describe the solution you'd like
Add field pitch name in Note struct and change implementation in some constructors.
If you like this idea I will open a PR.

@Datseris
Copy link
Member

I don't think this helps. There is a simple function for obtaining the pitch name out of the pitch field. The note structure should remain as is to directly parallelize the actual MIDI information which are these UInt8 numbers.

@NeroBlackstone
Copy link
Member Author

It is important to associate note pitch and note name.
For example, initialize notes from string, which contain a G flat scale melody:

Notes(" G♭ A♭ B♭ C♭ D♭ E♭ F")

But if we want to print this melody pitch, it will print F sharp scale "F♯ G♯ A♯ B C♯ D♯ E♯". This makes music analysis very difficult.
Is it possible to implement this feature in MusicManipulate.jl? Wrap Note struct in NamedNote struct and add a field for pitch name? I don't know.

@Datseris
Copy link
Member

Okay, I see your point. Yes, I agree with the suggestion of a new struct NamedNote that includes the name as a string. You can add this in MusicManipulations.jl. This struct should have all the fields Note has but with additional field name that is a string. You would have to implement tests for this struct, and conversions to and from Note as well though. You would also have to make a constructor NamedNotes(" G♭ A♭ B♭ C♭ D♭ E♭ F")

@NeroBlackstone
Copy link
Member Author

My question is: Now we have written so many useful functions for Note, how to extend Note to NamedNote, and make the existing functions receive NamedNote, without change Note struct.

@Datseris
Copy link
Member

well all functions that have been written for Note should be written for AbstractNote instead.

@NeroBlackstone
Copy link
Member Author

NeroBlackstone commented May 29, 2023

Sometimes converting between Note and NamedNote is inconvenient, because if we convert NamedNote to Note then manipulate, will lose "name".

@NeroBlackstone
Copy link
Member Author

well all functions that have been written for Note should be written for AbstractNote instead.

Yes, I think so... I will think carefully.

@NeroBlackstone
Copy link
Member Author

abstract type AbstractNote end
abstract type AbstractExtendNote <: AbstractNote end

struct Note <: AbstractNote 
    # note fields
    nf::nf_type
end
struct NamedNote <: AbstractExtendNote
    n::Note
    name:: String
end
struct WhatEverNote <: AbstractExtendNote
   n::Note
   p::p_type
end

#existed functions 
f!(x::AbstractNote) = ...
f!(x::AbstractExtendNote) = f!(x.n)
   
julia> Cflat4 = Note("Cb4")
#B3 print

julia> namedCflat4 = NamedNote(Note("Cb4"), "Cb4")
#Cflat4 print 

What do you think?

@Datseris
Copy link
Member

AbstractNote already exists in the library and the Notes struct is parameterized on the note type, Notes{N<:AbstractNote}... There is no need for a new type hieararchy. Just write the code for NamedNote, similarly with MoreVelNote as we do here: https://github.com/JuliaMusic/MusicManipulations.jl/blob/master/src/midifiles.jl

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