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

Bug Fix, Temperament Widget: Play and Stop not working properly #2845

Merged
merged 13 commits into from
Mar 2, 2021

Conversation

daksh4469
Copy link
Member

Issue Reference: #2767
There were some bugs in this widget, all connected to the Play and Stop functionality.

  • Firstly, if the STOP button was clicked on a certain note (let's say 3), it would not reflect that as the same in the UI. Instead, it would appear to be stopping on the next note (i.e., in this case, 4):
screen-capture5.mp4
  • Secondly, if the widget was closed while it was still playing, the sound of the same note would still be heard (once again), even after closing:
screen-capture6.mp4
  • Lastly, if the process was Stopped in the counter-clockwise cycle, i.e., when this.playbackForward = false, the stopping functionality would not be reflected in the UI and thus would result in a regression:
screen-capture7.mp4

This PR solves these bugs as shown below (all solved bugs are shown in the sequence as they are mentioned above) :

screen-capture8.mp4

@daksh4469
Copy link
Member Author

Please review @meganindya @walterbender.
Thanks.

@@ -2005,7 +2005,10 @@ class TemperamentWidget {
let p = 0;
this.playbackForward = true;
this._playing = !this._playing;

if (!this._playing) {
logo.synth.setMasterVolume(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we want to mess with the Master volume. It may have broader impacts. Why not just exit the loop? (See the mode widget, that does something similar.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just returning out of the loop would work perfectly.
Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this commit. Please review again.
Thanks.

@@ -2199,6 +2199,20 @@ class TemperamentWidget {
this.notesCircle.navItems[i - 1].slicePathAttr.fill = "#c8C8C8";
this.notesCircle.navItems[i - 1].sliceSelectedAttr.fill =
"#c8C8C8";
if(i==11){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add spaces around operators

this.notesCircle.navItems[0].slicePathAttr.fill = "#c8C8C8";
this.notesCircle.navItems[0].sliceSelectedAttr.fill = "#c8C8C8";
}
else if(i<11){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces...

Copy link
Member

@meganindya meganindya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temperament.js:1767 Uncaught TypeError: Assignment to constant variable.
    at TemperamentWidget._save (temperament.js:1767)
    at HTMLDivElement.widgetWindow.addButton.onclick (temperament.js:130)

Also, stop button doesn't reset after playing all the notes up and down is over.

@daksh4469
Copy link
Member Author

temperament.js:1767 Uncaught TypeError: Assignment to constant variable.
    at TemperamentWidget._save (temperament.js:1767)
    at HTMLDivElement.widgetWindow.addButton.onclick (temperament.js:130)

Also, stop button doesn't reset after playing all the notes up and down is over.

I fixed this. Please check and review @meganindya

Copy link
Member

@meganindya meganindya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't fixed

temperament.js:1767 Uncaught TypeError: Assignment to constant variable.
    at TemperamentWidget._save (temperament.js:1767)
    at HTMLDivElement.widgetWindow.addButton.onclick (temperament.js:130)
temperament.js:1471 Uncaught TypeError: Cannot read property 'addEventListener' of null
    at temperament.js:1471

@daksh4469
Copy link
Member Author

daksh4469 commented Feb 17, 2021

this isn't fixed

The error Uncaught TypeError: Assignment to constant variable. is occurring due to a global variable OCTAVERATIO which is defined in musicutils.js file. I tried changing its definition from const to let but did not work.
I am trying to figure this out.

Also,can you specify when does this second error occur, because this event listener seems to work fine and it also generates the arbitraryEditSlider on mouseover.

@daksh4469
Copy link
Member Author

daksh4469 commented Feb 17, 2021

Hi @meganindya,
I fixed the first error, i.e., Uncaught TypeError: Assignment to constant variable by declaring the OctaveRatio in the temperament.js file itself, as there was no need to use the global OCTAVERATIO from musicutils.js . Now, the save functionality works fine.
Now, it is generating the same error for the same variable OCTAVERATIO in blocks.js file. And on solving this similarly, it is generating another 2 errors in temperament.js files,which are, Uncaught TypeError: t is undefined temperament.js:140:9 and Uncaught TypeError: this.notesCircle is undefined temperament.js:84:17.

Can you verify if this is happening in your environment setup too or is it just in mine?

@@ -1760,8 +1763,7 @@ class TemperamentWidget {
}
}

// Global value
OCTAVERATIO = this.powerBase;
const OctaveRatio = this.powerBase;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global constant ? simple rename?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it worked here perfectly.
Actually, making the variable OCTAVERATIO as let in the musicutils.js file didn't work. Thus, this step.

if (i !== -1) {
if (this.circleIsVisible == false && docById("wheelDiv4") == null) {
this.notesCircle.navItems[i - 1].fillAttr = "#c8C8C8";
this.notesCircle.navItems[i - 1].sliceHoverAttr.fill = "#c8C8C8";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c8C8C8 should be a constant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, how will it be beneficial?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One advantage of using a constant symbol instead of a magic number/string is that you can express the semantics of the value more precisely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

this.circleIsVisible == true &&
docById("wheelDiv4") == null
) {
j = i - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variable can be omitted, it's a bad practice to declare temp variables if they are used only once.
i,j => naming should be meaningful for other people who read your code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 2185 to 2189
//on completion of a full circle and on hitting '0' note in clockwise direction
this.notesCircle.navItems[0].fillAttr = "#c8C8C8";
this.notesCircle.navItems[0].sliceHoverAttr.fill = "#c8C8C8";
this.notesCircle.navItems[0].slicePathAttr.fill = "#c8C8C8";
this.notesCircle.navItems[0].sliceSelectedAttr.fill = "#c8C8C8";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at a particular position(i) you are setting value of nav items to a particular colour.
You can use a function. which changes this.notesCircle.navItems[pos].fillAttr = COLOUR and call it in the code.
It will be a lot cleaner and maintainable in future.

setNotesCircleColour(pos,colour)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will work on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@vaibhavdaren vaibhavdaren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can improve on code quality

@daksh4469
Copy link
Member Author

Can you please review it again? @vaibhavdaren

Comment on lines +2178 to +2184
this.wheel1.navItems[i - 1].fillAttr = TemperamentWidget.LIGHTGREY;
this.wheel1.navItems[i - 1].sliceHoverAttr.fill =
TemperamentWidget.LIGHTGREY;
this.wheel1.navItems[i - 1].slicePathAttr.fill =
TemperamentWidget.LIGHTGREY;
this.wheel1.navItems[i - 1].sliceSelectedAttr.fill =
TemperamentWidget.LIGHTGREY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed function call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, actually the function updateNotesCircle works on notesCircle, whereas these lines use wheel1 and this only happens once in the whole code. Thus, a different function would have to be made for wheel1 which would not be that useful given that this function would have to be called just once.

@daksh4469
Copy link
Member Author

I did a rebase of this branch after the above-mentioned error by @meganindya was resolved by @ricknjacky in #2862. Now, everything works as expected in the Temperament Widget. Play and stop functionality also works as expected. Also, these commits also cover the changes mentioned in reviews by @vaibhavdaren. I also reverted one commit which involved changes in variable OCTAVERATIO to avoid any inconsistency.
Please have a look at this @walterbender and share your thoughts.

@walterbender walterbender merged commit c6bb32d into sugarlabs:master Mar 2, 2021
@daksh4469 daksh4469 deleted the daksh4469-main2 branch March 2, 2021 15:17
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

Successfully merging this pull request may close these issues.

4 participants