Change a NoteRest duration

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Change a NoteRest duration

Gideon Raveh

Hi all,

I want to cut a NoteRest duration by half. Manually, it’s very simple, by using the Keypad. However, the manual says that NoteRest.Duration is read only.

Is there a clever way to do the task? Deleting the NoteRest and re-insert it is not so clever way, forcing to save temporarily notes pitches.

Gideon.

 


_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Change a NoteRest duration

notenlektorat
Sorry, the proper way, if one wants to call it that, is to create a new noterest at the position. As long as we are talking a bout shortening a note: I am not completely sure what will happen if you create a new noterest at the position of the original noterest's half duration and then deleting that new noterest. It could end up overwriting the second half of the original noterest, but I wouldn't raise my hopes up too high.
 
Alex

_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Change a NoteRest duration

Bob Zawalich-3

Changing durations or pitches of notes is awful in ManuScript. It is one of the most error prone things you can do.

 

The *only* way to change the duration of a NoteRest is to gather up the properties of all the Note objects, then delete the NoteRest (or delete all its note objects), and then rewrite the notes.

 

If you try to use bar.AddNote at a location where there is a NoteRest, the added note will be incorporated into the existing NR at the same duration as that NR. So it will not overwrite the other part if smaller and will not extend if larger.

 

I don’t believe that you can save an NR into a Sparse Array and then delete the NR and still be able to access the properties of the NR. I have not tried it lately but I believe that once you delete the NR the stored NR is invalid. You could add a bar to the end of the score, copy the NR you want to change and paste it there, then find the pasted NR so you can access the properties. Later you will have to delete the added bar.

 

I mostly do not do that. I create a string containing all the properties of  each of the notes separated by semicolons and store them in an array. I then delete the NR, write the first Note with bar.AddNote, getting the properties from my string, then add the rest of the notes with nr.AddNote.

 

Of course it is even messier if you want to increase the duration. You will pretty much have to either add new bars and create notes there or create a temp score. See for example Double Note Values.

 

I will look around and see if I can find a decent example of what I have done in the past.

 

Good luck!

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of notenlektorat
Sent: Saturday, September 17, 2016 3:43 AM
To: A mailing list for Sibelius plug-in developers <[hidden email]>
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Sorry, the proper way, if one wants to call it that, is to create a new noterest at the position. As long as we are talking a bout shortening a note: I am not completely sure what will happen if you create a new noterest at the position of the original noterest's half duration and then deleting that new noterest. It could end up overwriting the second half of the original noterest, but I wouldn't raise my hopes up too high.

 

Alex


_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Change a NoteRest duration

Gideon Raveh
In reply to this post by Gideon Raveh

I was thinking of the same idea. Here is my solution:

 

bar = noteRest.ParentBar;

position = noteRest.Position;

for i = 0 to 4

{

name = "diatonic" & i;

@name = noteRest[i].DiatonicPitch;

name = "chromatic" & i;

@name = noteRest[i].Pitch;

}

noteRest.Delete();

bar.AddNote(position,chromatic1,Quarter,False,1,diatonic1);

bar.AddNote(position,chromatic0,Quarter,False,1,diatonic0);

position = position + Quarter;   //Oom-pah rhythm

bar.AddNote(position,chromatic2,Quarter,False,1,diatonic2);

bar.AddNote(position,chromatic3,Quarter,False,1,diatonic3);

 

 

From: Bob Zawalich [[hidden email]]
Sent: 17 September 2016 17:47
To: 'A mailing list for Sibelius plug-in developers'
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Changing durations or pitches of notes is awful in ManuScript. It is one of the most error prone things you can do.

 

The *only* way to change the duration of a NoteRest is to gather up the properties of all the Note objects, then delete the NoteRest (or delete all its note objects), and then rewrite the notes.

 

If you try to use bar.AddNote at a location where there is a NoteRest, the added note will be incorporated into the existing NR at the same duration as that NR. So it will not overwrite the other part if smaller and will not extend if larger.

 

I don’t believe that you can save an NR into a Sparse Array and then delete the NR and still be able to access the properties of the NR. I have not tried it lately but I believe that once you delete the NR the stored NR is invalid. You could add a bar to the end of the score, copy the NR you want to change and paste it there, then find the pasted NR so you can access the properties. Later you will have to delete the added bar.

 

I mostly do not do that. I create a string containing all the properties of  each of the notes separated by semicolons and store them in an array. I then delete the NR, write the first Note with bar.AddNote, getting the properties from my string, then add the rest of the notes with nr.AddNote.

 

Of course it is even messier if you want to increase the duration. You will pretty much have to either add new bars and create notes there or create a temp score. See for example Double Note Values.

 

I will look around and see if I can find a decent example of what I have done in the past.

 

Good luck!

 

 

 

From: [hidden email] [[hidden email]] On Behalf Of notenlektorat
Sent: Saturday, September 17, 2016 3:43 AM
To: A mailing list for Sibelius plug-in developers <[hidden email]>
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Sorry, the proper way, if one wants to call it that, is to create a new noterest at the position. As long as we are talking a bout shortening a note: I am not completely sure what will happen if you create a new noterest at the position of the original noterest's half duration and then deleting that new noterest. It could end up overwriting the second half of the original noterest, but I wouldn't raise my hopes up too high.

 

Alex


_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Change a NoteRest duration

Bob Zawalich-3

If you are doing this for yourself and you know that you will always have normal noteheads and no live playback data that should be fine. In the general case you could lose a lot of data.

 

You could look at, for example the code in the Divide Durations plugin which divides up a note in various ways.

 

I build up a string of properties for each note like this:

 

GetNotePropertyString(n)

 

// save the properties of a note in a string with fields separated so they can easily be decomposed.

// note that quartertones will be lost!

 

chSeparator = ";";

 

str = n.Pitch & chSeparator & // 0

n.DiatonicPitch & chSeparator & // 1

TrueFalseAsNumber(n.Tied) & chSeparator & // 2

n.NoteStyle & chSeparator & // 3

TrueFalseAsNumber(n.UseOriginalVelocityForPlayback) & chSeparator & // 4

n.OriginalVelocity & chSeparator & // 5

TrueFalseAsNumber(n.UseOriginalDeltaSrForPlayback) & chSeparator & // 6

n.OriginalDeltaSr & chSeparator & // 7

TrueFalseAsNumber(n.UseOriginalDurationForPlayback) & chSeparator & // 8

n.OriginalDuration & chSeparator & // 9

TrueFalseAsNumber(n.Bracketed) & chSeparator & // 10

TrueFalseAsNumber(n.Slide) & chSeparator & // 11

n.StringNum; // 12

 

// append these fields to use as "remaining amounts for distribution - data is note by note

str = str & chSeparator & n.OriginalDeltaSr & // 13

chSeparator & n.OriginalDuration & // 14

chSeparator & n.Color; // 15 color will be note level in Sib 8.3

 

//trace("GetNotePropertyString str = " & str);

return str;

 

 

and when I need them to recreate a note I use SplitString.

 

Also: I typically only use indirection when I need to store an object. Since you are storing integers (Pitch and DiatonicPitch), you could just store them in an array, which I find to be somewhat less confusing.

 

In Sib 6 and later if I have to store an object I use a Sparse Array rather than indirection. This is again less obscure and also you can pass a sparse array to another routine or use a global sparse array while a “pseudo array” built with indirection  can only be used in the method in which it is created.

 

In Divide Duration, the code in ReplaceNR is what I use to rewrite the note as smaller pieces of itself. It probably looks more elaborate that it might need to be, but I reuse the code in other plugins and I try to have it handle all the cases I can think of. So I try to come up with something I can just plugin whenever I need to split up a NoteRest.

 

Note that even with all I am doing quartertones will be lost, since there is no way to create a quartertone in ManuScript. In some plugins I check for quartertones before processing such NoteRests (you can detect a QT using the note.Name field, but you cannot create one).

 

Your code should work fine as long as you are ok having default values for the fields you are not specifying.

 

 

Cheers

 

bob

 

 

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Gideon Raveh
Sent: Sunday, September 18, 2016 9:44 AM
To: [hidden email]
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

I was thinking of the same idea. Here is my solution:

 

bar = noteRest.ParentBar;

position = noteRest.Position;

for i = 0 to 4

{

name = "diatonic" & i;

@name = noteRest[i].DiatonicPitch;

name = "chromatic" & i;

@name = noteRest[i].Pitch;

}

noteRest.Delete();

bar.AddNote(position,chromatic1,Quarter,False,1,diatonic1);

bar.AddNote(position,chromatic0,Quarter,False,1,diatonic0);

position = position + Quarter;   //Oom-pah rhythm

bar.AddNote(position,chromatic2,Quarter,False,1,diatonic2);

bar.AddNote(position,chromatic3,Quarter,False,1,diatonic3);

 

 

From: Bob Zawalich [[hidden email]]
Sent: 17 September 2016 17:47
To: 'A mailing list for Sibelius plug-in developers'
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Changing durations or pitches of notes is awful in ManuScript. It is one of the most error prone things you can do.

 

The *only* way to change the duration of a NoteRest is to gather up the properties of all the Note objects, then delete the NoteRest (or delete all its note objects), and then rewrite the notes.

 

If you try to use bar.AddNote at a location where there is a NoteRest, the added note will be incorporated into the existing NR at the same duration as that NR. So it will not overwrite the other part if smaller and will not extend if larger.

 

I don’t believe that you can save an NR into a Sparse Array and then delete the NR and still be able to access the properties of the NR. I have not tried it lately but I believe that once you delete the NR the stored NR is invalid. You could add a bar to the end of the score, copy the NR you want to change and paste it there, then find the pasted NR so you can access the properties. Later you will have to delete the added bar.

 

I mostly do not do that. I create a string containing all the properties of  each of the notes separated by semicolons and store them in an array. I then delete the NR, write the first Note with bar.AddNote, getting the properties from my string, then add the rest of the notes with nr.AddNote.

 

Of course it is even messier if you want to increase the duration. You will pretty much have to either add new bars and create notes there or create a temp score. See for example Double Note Values.

 

I will look around and see if I can find a decent example of what I have done in the past.

 

Good luck!

 

 

 

From: [hidden email] [[hidden email]] On Behalf Of notenlektorat
Sent: Saturday, September 17, 2016 3:43 AM
To: A mailing list for Sibelius plug-in developers <[hidden email]>
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Sorry, the proper way, if one wants to call it that, is to create a new noterest at the position. As long as we are talking a bout shortening a note: I am not completely sure what will happen if you create a new noterest at the position of the original noterest's half duration and then deleting that new noterest. It could end up overwriting the second half of the original noterest, but I wouldn't raise my hopes up too high.

 

Alex


_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Change a NoteRest duration

Gideon Raveh

Wow!!!

I’m speechless,

Gideon.

 

From: Bob Zawalich [mailto:[hidden email]]
Sent: 19 September 2016 08:13
To: 'A mailing list for Sibelius plug-in developers'
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

If you are doing this for yourself and you know that you will always have normal noteheads and no live playback data that should be fine. In the general case you could lose a lot of data.

 

You could look at, for example the code in the Divide Durations plugin which divides up a note in various ways.

 

I build up a string of properties for each note like this:

 

GetNotePropertyString(n)

 

// save the properties of a note in a string with fields separated so they can easily be decomposed.

// note that quartertones will be lost!

 

chSeparator = ";";

 

str = n.Pitch & chSeparator & // 0

n.DiatonicPitch & chSeparator & // 1

TrueFalseAsNumber(n.Tied) & chSeparator & // 2

n.NoteStyle & chSeparator & // 3

TrueFalseAsNumber(n.UseOriginalVelocityForPlayback) & chSeparator & // 4

n.OriginalVelocity & chSeparator & // 5

TrueFalseAsNumber(n.UseOriginalDeltaSrForPlayback) & chSeparator & // 6

n.OriginalDeltaSr & chSeparator & // 7

TrueFalseAsNumber(n.UseOriginalDurationForPlayback) & chSeparator & // 8

n.OriginalDuration & chSeparator & // 9

TrueFalseAsNumber(n.Bracketed) & chSeparator & // 10

TrueFalseAsNumber(n.Slide) & chSeparator & // 11

n.StringNum; // 12

 

// append these fields to use as "remaining amounts for distribution - data is note by note

str = str & chSeparator & n.OriginalDeltaSr & // 13

chSeparator & n.OriginalDuration & // 14

chSeparator & n.Color; // 15 color will be note level in Sib 8.3

 

//trace("GetNotePropertyString str = " & str);

return str;

 

 

and when I need them to recreate a note I use SplitString.

 

Also: I typically only use indirection when I need to store an object. Since you are storing integers (Pitch and DiatonicPitch), you could just store them in an array, which I find to be somewhat less confusing.

 

In Sib 6 and later if I have to store an object I use a Sparse Array rather than indirection. This is again less obscure and also you can pass a sparse array to another routine or use a global sparse array while a “pseudo array” built with indirection  can only be used in the method in which it is created.

 

In Divide Duration, the code in ReplaceNR is what I use to rewrite the note as smaller pieces of itself. It probably looks more elaborate that it might need to be, but I reuse the code in other plugins and I try to have it handle all the cases I can think of. So I try to come up with something I can just plugin whenever I need to split up a NoteRest.

 

Note that even with all I am doing quartertones will be lost, since there is no way to create a quartertone in ManuScript. In some plugins I check for quartertones before processing such NoteRests (you can detect a QT using the note.Name field, but you cannot create one).

 

Your code should work fine as long as you are ok having default values for the fields you are not specifying.

 

 

Cheers

 

bob

 

 

 

 

From: [hidden email] [[hidden email]] On Behalf Of Gideon Raveh
Sent: Sunday, September 18, 2016 9:44 AM
To: [hidden email]
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

I was thinking of the same idea. Here is my solution:

 

bar = noteRest.ParentBar;

position = noteRest.Position;

for i = 0 to 4

{

name = "diatonic" & i;

@name = noteRest[i].DiatonicPitch;

name = "chromatic" & i;

@name = noteRest[i].Pitch;

}

noteRest.Delete();

bar.AddNote(position,chromatic1,Quarter,False,1,diatonic1);

bar.AddNote(position,chromatic0,Quarter,False,1,diatonic0);

position = position + Quarter;   //Oom-pah rhythm

bar.AddNote(position,chromatic2,Quarter,False,1,diatonic2);

bar.AddNote(position,chromatic3,Quarter,False,1,diatonic3);

 

 

From: Bob Zawalich [[hidden email]]
Sent: 17 September 2016 17:47
To: 'A mailing list for Sibelius plug-in developers'
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Changing durations or pitches of notes is awful in ManuScript. It is one of the most error prone things you can do.

 

The *only* way to change the duration of a NoteRest is to gather up the properties of all the Note objects, then delete the NoteRest (or delete all its note objects), and then rewrite the notes.

 

If you try to use bar.AddNote at a location where there is a NoteRest, the added note will be incorporated into the existing NR at the same duration as that NR. So it will not overwrite the other part if smaller and will not extend if larger.

 

I don’t believe that you can save an NR into a Sparse Array and then delete the NR and still be able to access the properties of the NR. I have not tried it lately but I believe that once you delete the NR the stored NR is invalid. You could add a bar to the end of the score, copy the NR you want to change and paste it there, then find the pasted NR so you can access the properties. Later you will have to delete the added bar.

 

I mostly do not do that. I create a string containing all the properties of  each of the notes separated by semicolons and store them in an array. I then delete the NR, write the first Note with bar.AddNote, getting the properties from my string, then add the rest of the notes with nr.AddNote.

 

Of course it is even messier if you want to increase the duration. You will pretty much have to either add new bars and create notes there or create a temp score. See for example Double Note Values.

 

I will look around and see if I can find a decent example of what I have done in the past.

 

Good luck!

 

 

 

From: [hidden email] [[hidden email]] On Behalf Of notenlektorat
Sent: Saturday, September 17, 2016 3:43 AM
To: A mailing list for Sibelius plug-in developers <[hidden email]>
Subject: Re: [Plugin-dev] Change a NoteRest duration

 

Sorry, the proper way, if one wants to call it that, is to create a new noterest at the position. As long as we are talking a bout shortening a note: I am not completely sure what will happen if you create a new noterest at the position of the original noterest's half duration and then deleting that new noterest. It could end up overwriting the second half of the original noterest, but I wouldn't raise my hopes up too high.

 

Alex


_______________________________________________
Plugin-dev mailing list
[hidden email]
https://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev