Skip to content

Commit

Permalink
[3851] - Send changes of adding block functionality (#3952)
Browse files Browse the repository at this point in the history
* fixes #3913

* fix:resolves grid position on hamburger opening(#3914) (#3924)

* fix:resolves hamburger opening(#3914)

* fix:fixes #3914(suggested changes done)

* adjust size of grid element repositioning when using aux toolbar

---------

Co-authored-by: Walter Bender <walter@sorcero.com>

* Fix input boxes (#3927)

* bump version

* enhancement: scale on hover (#3926)

Co-authored-by: anas2357 <141234155+anas2357@users.noreply.github.com>

* calculate frequencies from ratio

* Add close button to extended-menu pie menu (fixes #3933) (#3934)

* Bump braces and gulp (#3903)

Bumps [braces](https://github.com/micromatch/braces) to 3.0.3 and updates ancestor dependency [gulp](https://github.com/gulpjs/gulp). These dependencies need to be updated together.


Updates `braces` from 2.3.2 to 3.0.3
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/commits/3.0.3)

Updates `gulp` from 4.0.2 to 5.0.0
- [Release notes](https://github.com/gulpjs/gulp/releases)
- [Changelog](https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md)
- [Commits](gulpjs/gulp@v4.0.2...v5.0.0)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
- dependency-name: gulp
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* add support for solfege accidentals in phrasemaker

* Add support for cents (#3937)

* add support for cents through semi-tone transposition

* add 50 cents macro

* add cents example

* add output frequencies

* fix issue with ratio cents

* add a ratio-cents example

* Ratio transpose and Ratio interval (#3936)

* use processPitch for all pitch types

* Add support for cents (#3937)

* add support for cents through semi-tone transposition

* add 50 cents macro

* add cents example

* add output frequencies

* fix issue with ratio cents

* add a ratio-cents example

* use processPitch for all pitch types

* convert freq to note before scalar step

* fix note convert

* remove extra comma throwing off indexing

* Hyperscore link update (#3939) (#3947)

* Update Hyperscore example link in guide.html (#3944)

* Update README.md (#3943)

* left_and_back_images (#3950)

* Updated Dockerfile  (#3949)

* Update README.md

* Update dockerfile

* add temp collaborate button

* Write collaboration as a class

* bind collaboration with activity

* Add emitter on new block creation

* connect collaborare UI with functionality

* Set local update flag

* Render received data

* Initiate collaboration

* Make socket connection

* Listen for emit message

* Handle error

* remove yjs and socket.io dependecies

* Fixed #3956 Auto increasing and decreasing input block (#3957)

* fixes #3941

* fixes #3958

* minor fixes

* minor fixes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Walter Bender <walter@sorcero.com>
Co-authored-by: Nikhil <154296996+BeNikk@users.noreply.github.com>
Co-authored-by: Anas <141234155+Anas-2357@users.noreply.github.com>
Co-authored-by: anas2357 <141234155+anas2357@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Walter Bender <walter@sugarlabs.org>
Co-authored-by: Harshit Verma <therealharshit014@gmail.com>
Co-authored-by: Geeten Parab <147247925+GeetenParab@users.noreply.github.com>
Co-authored-by: akilesh1706 <126157319+akilesh1706@users.noreply.github.com>
Co-authored-by: Khadar vali <124120102+khadar1020@users.noreply.github.com>
  • Loading branch information
11 people committed Jul 27, 2024
1 parent e991999 commit 8c46937
Show file tree
Hide file tree
Showing 16 changed files with 1,192 additions and 2,839 deletions.
13 changes: 8 additions & 5 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

FROM python:latest

# First stage: Build stage
FROM python:latest AS build

WORKDIR /app

COPY . .

COPY . .
# Second stage: Final stage
FROM python:latest

WORKDIR /app

EXPOSE 3000
COPY --from=build /app /app

EXPOSE 3000

CMD ["python", "-m", "http.server", "3000", "--bind", "0.0.0.0"]
2 changes: 1 addition & 1 deletion documentation/back_block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion documentation/left_block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ While a bit fanciful, this example, which can be run by clicking on
the link below, takes musical paint in a novel direction.

[RUN
LIVE](https://walterbender.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True)
LIVE](https://sugarlabs.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True)

## <a name="ENSEMBLE">3.8 Ensemble</a>

Expand Down
3 changes: 2 additions & 1 deletion guide/guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ <h2 id="2-making-sounds"><a name="NOTES">2. Making Sounds</a></h2>
<a href="#3-programming-with-music">Next Section (3. Programming with Music)</a>
</p>
<p>

Music Blocks incorporates many common elements of music, such as
<a href="#22-pitch-blocks">pitch</a>, <a href="#21-note-value-blocks">rhythm</a>,
<a href="#341-set-volume-and-crescendo">volume</a>, and, to some degree,
Expand Down Expand Up @@ -2406,7 +2407,7 @@ <h3 id="37-interactions"><a name="INTERACTIONS">3.7 Interactions</a></h3>
</p>
<p>
<a
href="https://walterbender.github.io/musicblocks/index.html?id=1523896294964170&amp;run=True&amp;run=True"
href="https://sugarlabs.github.io/musicblocks/index.html?id=1523896294964170&run=True&run=True"
>RUN LIVE</a
>
</p>
Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,16 @@
>
<a style="color: transparent;">space&nbsp;&nbsp;&nbsp;</a>
</li>
<li>
<a
id="collaborateIcon"
class="tooltipped"
data-position="bottom"
><i class="material-icons md-48"
>groups</i
></a
>
</li>
<li>
<a
id="restoreIcon"
Expand Down
42 changes: 41 additions & 1 deletion js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,39 @@ class Activity {
})
}

// Initialize the collaboration
this._initiateCollaboration = () => {
this.collaboration.startCollaboration();
this.blocks.isLocalUpdate = true;
};

// Render the project from received data
this.renderProjectFromData = (update) => {
const data = JSON.parse(update);
document.body.style.cursor = "wait";
// this.doLoadAnimation();
this.blocks.isLocalUpdate = false;

// Render the blocks
for (const name in this.palettes.dict) {
this.palettes.dict[name].hideMenu(true);
}

this.stage.removeAllEventListeners("trashsignal");

// Wait for the old blocks to be removed.
// eslint-disable-next-line no-unused-vars
const __listener = (event) => {
this.blocks.loadNewBlocks(data);
this.stage.removeAllEventListeners("trashsignal");
};

this.stage.addEventListener("trashsignal", __listener, false);
this.sendAllToTrash(false, false);
this._allClear(false);
this.refreshCanvas();
};

/**
* Sets up plugin and palette boilerplate.
* This function initializes various properties related to the plugin objects,
Expand Down Expand Up @@ -3347,6 +3380,11 @@ class Activity {
this.refreshCanvas();
};

// Start the collaboration
const initiateCollaboration = (activity) => {
activity._initiateCollaboration();
}

this.handleKeyDown = (event) => {

if (event.ctrlKey && event.key === "z") {
Expand Down Expand Up @@ -5141,7 +5179,7 @@ class Activity {
})

document.addEventListener("mouseup", (event) => {
event.preventDefault();
// event.preventDefault();
this.isDragging = false;
this.selectionArea.style.display = "none";
this.startX = 0;
Expand Down Expand Up @@ -5377,6 +5415,7 @@ class Activity {

this.pasteBox = new PasteBox(this);
this.languageBox = new LanguageBox(this);
this.collaboration = new Collaboration(this);

// Show help on startup if first-time user.
if (this.firstTimeUser) {
Expand Down Expand Up @@ -5425,6 +5464,7 @@ class Activity {
if (_THIS_IS_MUSIC_BLOCKS_) {
this.toolbar.renderChooseKeyIcon(chooseKeyMenu);
}
this.toolbar.renderCollaborateIcon(initiateCollaboration);
this.toolbar.renderJavaScriptIcon(toggleJSWindow);
this.toolbar.renderLanguageSelectIcon(this.languageBox);
this.toolbar.renderWrapIcon();
Expand Down
5 changes: 4 additions & 1 deletion js/artwork.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions js/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,9 @@ class Block {
unhighlightSelectedBlocks(blk, selection) {
if (selection) {
this.blocks.unhighlight(blk, true);
this.disconnectedBitmap.visible = true;
if (!this.collapsed) {
this.disconnectedBitmap.visible = true;
}
this.container.updateCache();
};
}
Expand Down Expand Up @@ -3381,23 +3383,23 @@ class Block {

const labelElem = docById("labelDiv");

var safetext = function(text){
var safetext = function(text){
// Best to avoid using these special characters in text strings
// without first converting them to their "safe" form.
var table = {
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': 'apos',
'&': 'amp',
'\r': '#10',
'\n': '#13'
};
return text.toString().replace(/[<>"'\r\n&]/g, function(chr){
return '&' + table[chr] + ';';
});
};
var table = {
'<': 'lt',
'>': 'gt',
'"': 'quot',
'\'': 'apos',
'&': 'amp',
'\r': '#10',
'\n': '#13'
};
return text.toString().replace(/[<>"'\r\n&]/g, function(chr){
return '&' + table[chr] + ';';
});
};

if (this.name === "text") {
labelElem.innerHTML =
Expand Down
23 changes: 23 additions & 0 deletions js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class Blocks {

this.selectedBlocks = [];

this.isLocalUpdate = false;

/**
* We stage deletion of prototype action blocks on the palette so
* as to avoid palette refresh race conditions.
Expand Down Expand Up @@ -3066,6 +3068,14 @@ class Blocks {
this.visible = true;
};

// Emit a message when a new block is created
this.emitAddedBlock = () => {
if (this.activity.collaboration.hasCollaborationStarted) {
const update = this.activity.collaboration.convertBlockListToHtml();
this.activity.collaboration.socket.emit("new-block-added", update);
}
};

/**
* Make a new block with connections
* @param - name - new variable
Expand Down Expand Up @@ -3168,6 +3178,15 @@ class Blocks {

/** and we need to load the images into the container. */
myBlock.imageLoad();

/** Signal that a new block is created */
if (this.activity.collaboration.hasCollaborationStarted) {
if (this.isLocalUpdate) {
setTimeout(() => {
this.emitAddedBlock();
}, 200);
};
};
return myBlock;
};

Expand Down Expand Up @@ -6525,6 +6544,10 @@ class Blocks {
}
}
}

if (this.activity.collaboration.hasCollaborationStarted) {
this.isLocalUpdate = true;
}
};

/**
Expand Down
83 changes: 53 additions & 30 deletions js/collaboration/collaboration.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-vars */
// Copyright (c) 2024 Ajeet Pratap Singh
//
// This program is free software; you can redistribute it and/or
Expand All @@ -14,42 +15,64 @@

/* eslint-disable no-undef */

const RETRIES = 5;
const DELAY_DURATION = 2000;
let attempts = 0;

function stopConnection(socket) {
if(attempts >= RETRIES){
console.log("Maximum calls to make connection exceeded. Stopped making calls");
socket.disconnect();
class Collaboration {
constructor(activity) {
this.activity = activity;
this.RETRIES = 5;
this.DELAY_DURATION = 2000;
this.attempts = 0;
this.socket = null;
this.blockList = this.activity.blocks.blockList;
this.PORT = "http://localhost:8080/";
this.hasCollaborationStarted = false;
this.updatedProjectHtml = null;
}
}

function makeConnection(){
// Convert the blockList into html
convertBlockListToHtml = () => {
this.updatedProjectHtml = this.activity.prepareExport();
return this.updatedProjectHtml;
};

// connect to the local server
const socket = io("http://localhost:8080/");
socket.on("connect", () => {
try{
console.log("connected to the server");
} catch(error){
console.log("Connection failed", error);
// Stop making calls to the socket server
stopConnection = (socket) => {
if (this.attempts >= this.RETRIES) {
console.log("Maximum calls to make connection exceeded. Stopped making calls");
socket.disconnect();
}
});
};

socket.on("connect_error", (error) => {
attempts++;
console.log("Failed to connect to the socket server. Retrying in few seconds...");
setTimeout(stopConnection(socket), DELAY_DURATION);
});
}
// Make calls to the socket server
makeConnection = () => {
// connect to the local server
const socket = io(this.PORT);
socket.on("connect", () => {
this.socket = socket;
try {
console.log("connected to the server");
this.hasCollaborationStarted = true;
} catch (error) {
console.log("Connection failed", error);
}
});

function startCollaboration(){
document.addEventListener("DOMContentLoaded", () => {
makeConnection();
// initialiseDoc();
});
}
socket.on("connect_error", () => {
this.attempts++;
console.log("Failed to connect to the socket server. Retrying in few seconds...");
setTimeout(this.stopConnection(socket), this.DELAY_DURATION);
});

startCollaboration();
socket.on("new-block-added", (update) => {
this.activity.textMsg("New block added. rendering...");
setTimeout(this.activity.hideMsgs, 10000);
this.activity.renderProjectFromData(update);
});
};

// Start the collaboration
startCollaboration = () => {
this.makeConnection();
};
}

Loading

0 comments on commit 8c46937

Please sign in to comment.