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

[3851] - Implement functionality of collaboration mouse along with custom and random names. #3984

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
72097b8
fixes #3913
walterbender Jun 23, 2024
200dddb
fix:resolves grid position on hamburger opening(#3914) (#3924)
BeNikk Jun 28, 2024
71fe874
Merge branch 'master' into collaboration
apsinghdev Jul 1, 2024
423b467
Fix input boxes (#3927)
apsinghdev Jul 2, 2024
0d082eb
bump version
walterbender Jul 2, 2024
eb7c23a
enhancement: scale on hover (#3926)
Anas-2357 Jul 2, 2024
6354fa8
calculate frequencies from ratio
walterbender Jul 2, 2024
474f811
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 2, 2024
ad292d9
Merge branch 'master' into collaboration
apsinghdev Jul 3, 2024
5848e62
Add close button to extended-menu pie menu (fixes #3933) (#3934)
BeNikk Jul 3, 2024
10ab05e
Bump braces and gulp (#3903)
dependabot[bot] Jul 3, 2024
5e27904
add support for solfege accidentals in phrasemaker
walterbender Jul 4, 2024
3c57c4b
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 4, 2024
530f330
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 4, 2024
f73597e
Merge branch 'master' into collaboration
apsinghdev Jul 4, 2024
5022721
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 7, 2024
55570e8
Add support for cents (#3937)
walterbender Jul 7, 2024
f88955e
Ratio transpose and Ratio interval (#3936)
walterbender Jul 7, 2024
97e811a
fix note convert
walterbender Jul 7, 2024
cba02d3
remove extra comma throwing off indexing
walterbender Jul 7, 2024
306888e
Merge branch 'master' into collaboration
apsinghdev Jul 9, 2024
2d99514
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 10, 2024
944bc2e
Hyperscore link update (#3939) (#3947)
therealharshit Jul 12, 2024
aaf0f6e
Update Hyperscore example link in guide.html (#3944)
GeetenParab Jul 12, 2024
c41d9f5
Update README.md (#3943)
akilesh1706 Jul 12, 2024
69f8ee8
left_and_back_images (#3950)
khadar1020 Jul 15, 2024
472ec5c
Updated Dockerfile (#3949)
akilesh1706 Jul 15, 2024
cc0b986
Merge branch 'master' into collaboration
apsinghdev Jul 16, 2024
08787e1
remove yjs and socket.io dependecies
apsinghdev Jul 16, 2024
8776750
Fixed #3956 Auto increasing and decreasing input block (#3957)
therealharshit Jul 25, 2024
6436c2f
fixes #3941
walterbender Jul 26, 2024
3b63768
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Jul 26, 2024
c415d53
fixes #3958
walterbender Jul 26, 2024
cc4bcef
Merge branch 'master' into collaboration
apsinghdev Jul 27, 2024
3acc0b5
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 27, 2024
07f9707
Fixes collapsed state of note block (#3961)
therealharshit Jul 28, 2024
fd39015
Merge branch 'master' into collaboration
apsinghdev Jul 28, 2024
de9bd23
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Jul 29, 2024
72dcdea
fixes issue with extra line number in JavaScript Editor (#3962)
haroon10725 Jul 30, 2024
fdbd3ff
Merge branch 'master' into collaboration
apsinghdev Aug 1, 2024
8105355
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Aug 3, 2024
25a54b0
fixes sample block duplication issue (#3965)
haroon10725 Aug 5, 2024
5c94784
Merge branch 'master' into collaboration
apsinghdev Aug 6, 2024
0e59d72
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Aug 7, 2024
569efca
Merge branch 'collaboration' of https://github.com/sugarlabs/musicblo…
apsinghdev Aug 11, 2024
e0a3e3e
updated planet image on documentation (#3971)
haroon10725 Aug 14, 2024
4acea66
fix 1MB file size limit on audio sample imports (#3976)
haroon10725 Aug 18, 2024
a995ff9
update wheelnav.js (#3977)
haroon10725 Aug 20, 2024
87bcbba
Fixes #3972 Highlight should not activate when code is being run (#3975)
therealharshit Aug 20, 2024
4ff5b98
removed extra code (#3980)
haroon10725 Aug 22, 2024
f5f616f
Fixes #3973 Right click menu only opens in the advanced mode (#3978)
AnupamGaur Aug 22, 2024
38ed1f2
FIXES ISSUE #3895 Add alphabet "G" as a block found in easy mode (#3…
omsuneri Aug 22, 2024
6f620f0
AI BLOCK and Documentation on How to add widget in MB (#3964)
abhijeetsingh0401 Aug 25, 2024
411cd87
Added midi support to MB (#3904)
Mubashirshariq Aug 26, 2024
205ad71
modifications for clarity
walterbender Aug 26, 2024
5af39d2
Merge branch 'master' into collaboration
apsinghdev Aug 27, 2024
9e82eaf
create a new class for collaboration cursor
apsinghdev Aug 28, 2024
49d70ce
Import collabcursor file
apsinghdev Aug 28, 2024
ffc51ed
Add logic to take name from the user
apsinghdev Aug 28, 2024
23dff5d
Implement collaboration mouse functionality
apsinghdev Aug 28, 2024
de9b416
Implement random name functionality
apsinghdev Aug 28, 2024
c26a2d2
add abacus example
walterbender Aug 28, 2024
9f82b1f
Rhythm block doesn't repeat issue update (#3982)
therealharshit Aug 28, 2024
c807bc3
add more steps to new palette instructions
walterbender Aug 28, 2024
1f3e27f
Merge branch 'master' of github.com:sugarlabs/musicblocks
walterbender Aug 28, 2024
ed2d7dd
Merge branch 'master' into collaboration
apsinghdev Aug 29, 2024
c5a248d
Merge branch 'collaboration' into Feat/add-collab-cursor
apsinghdev Aug 29, 2024
0ddd1a5
Fix scrolling issue
apsinghdev Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added ,
Empty file.
Binary file modified documentation/planet-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified documentation/planet-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ Music Blocks has handy widgets for various musical concepts to create musical co
| stocks.html | Generated from a Python script, this project is a musical representation of the price of a stock over time |
| Morse-code-rhythms.html | Generate Morse code rhythms by typing in letters that generate rhythmic patterns |
| typing-game.html | Catch the falling alphabets/letters before they reach ground by inputting them correctly |
| abacus-prototype.html | Working abacus example... remix to enrich this example. |


# Utilities

Expand Down
1 change: 1 addition & 0 deletions examples/abacus-prototype.html

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

<script src="lib/Tone.js" defer></script>

<script src="lib/midi.js" defer></script>

<script src="lib/jquery.ruler.js" defer></script>

<script src="lib/modernizr-2.6.2.min.js" defer></script>
Expand All @@ -48,6 +50,8 @@

<script src="lib/wheelnav.js" defer></script>

<script src="lib/abc.min.js" defer></script>

<script src="lib/codejar/codejar.min.js" defer></script>

<script src="lib/codejar/highlight.pack.js" defer></script>
Expand All @@ -56,6 +60,8 @@

<script src="./js/collaboration/collaboration.js"></script>

<script src="./js/collaboration/collabcursor.js"></script>

<link rel="prefetch" type="application/l10n" href="./localization.ini"/>

<script data-main="js/loader" src="lib/require.js" defer></script>
Expand Down Expand Up @@ -411,7 +417,7 @@
class="file"
type="file"
id="myOpenFile"
accept=".ta, .tb, .html"
accept=".ta, .tb, .html,.mid,.midi"
tabindex="-1"
/>
<input
Expand Down
6 changes: 6 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ meaningful name, e.g. `setupGraphicsBlocks()`.
4. Call that setup function in `js/basicblocks.js` from the
`initBasicProtoBlocks()` function.

5. Add artwork for the palette icon in `js/artwork.js`. There are
several dictionaries that need to be updated as well: `PALETTECOLORS`
and `PALETTEICONS`.

6. Assign colors in `js/utils/platformstyle.js`.

After the above steps are complete, move to [defining a new
block](#how-to-define-a-new-block)

Expand Down
1,128 changes: 1,110 additions & 18 deletions js/activity.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions js/blocks/PitchBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ function setupPitchBlocks(activity) {
"note2"
]);
this.formBlock({ outType: "noteout" });
this.beginnerBlock(true);
}
}

Expand All @@ -889,6 +890,7 @@ function setupPitchBlocks(activity) {
"note1"
]);
this.formBlock({ outType: "solfegeout" });
this.beginnerBlock(true);
}
}

Expand Down Expand Up @@ -1841,6 +1843,7 @@ function setupPitchBlocks(activity) {
[1, ["notename", { value: "G" }], 0, 0, [0]],
[2, ["number", { value: 4 }], 0, 0, [0]]
]);
this.beginnerBlock(true);
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/blocks/RhythmBlockPaletteBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ function setupRhythmBlockPaletteBlocks(activity) {
const bpmFactor =
TONEBPM / tur.singer.bpm.length > 0 ? last(tur.singer.bpm) : Singer.masterBPM;

const beatValue = bpmFactor / noteBeatValue;
const beatValue =
bpmFactor == null ? 1 : bpmFactor / noteBeatValue;

/**
* Plays a note in the rhythm.
Expand Down
61 changes: 60 additions & 1 deletion js/blocks/WidgetBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,65 @@ function setupWidgetBlocks(activity) {
if (args.length === 1) return [args[0], 1];
}
}

/**
* Represents a block for inspecting the status of Music Blocks during execution.
* @extends StackClampBlock
*/
class AIMusicBlocks extends StackClampBlock {
/**
* Creates a SamplerBlock instance.
*/
constructor() {
super("aimusic");
this.setPalette("widgets", activity);
this.parameter = true;
this.beginnerBlock(false);

this.setHelpString([
_("Upload a sample and adjust its pitch center."),
"documentation",
null,
"aimusic"
]);

//.TRANS: the speed at music is should be played.
this.formBlock({ name: _("aimusic"), canCollapse: true });
this.makeMacro((x, y) => [
[0, "aimusic", x, y, [null, 1]],

[1, "print", 0, 0, [0,2,null]],
[2, ["text",{"value":"Music Generated By AI"}], 0, 0, [1]]
]);
}

/**
* Handles the flow of data for the sampler block.
* @param {any[]} args - The arguments passed to the block.
* @param {object} logo - The logo object.
* @param {object} turtle - The turtle object.
* @param {object} blk - The block object.
* @returns {number[]} - The output values.
*/
flow(args, logo, turtle, blk) {
if (logo.sample === null) {
logo.sample = new AIWidget();
}
logo.inSample = true;
logo.sample = new AIWidget();

const listenerName = "_sampler_" + turtle;
logo.setDispatchBlock(blk, turtle, listenerName);

// eslint-disable-next-line no-unused-vars
const __listener = event => {
logo.sample.init(activity);
};

logo.setTurtleListener(turtle, listenerName, __listener);

return [args[0], 1];
}
}
// Set up blocks if this is Music Blocks environment
if (_THIS_IS_MUSIC_BLOCKS_) {
new EnvelopeBlock().setup(activity);
Expand All @@ -1579,6 +1637,7 @@ function setupWidgetBlocks(activity) {
new MatrixGMajorBlock().setup(activity);
new MatrixCMajorBlock().setup(activity);
new MatrixBlock().setup(activity);
new AIMusicBlocks().setup(activity);
}
// Instantiate and set up the StatusBlock
new StatusBlock().setup(activity);
Expand Down
100 changes: 100 additions & 0 deletions js/collaboration/collabcursor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable no-unused-vars */
// Copyright (c) 2024 Ajeet Pratap Singh
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA

class Cursor {
constructor(activity) {
this.activity = activity;
this.cursorContainer = new Map();
this.nameContainer = new Map();
}

createCursor(id) {
const cursorDiv = document.createElement("div");
const nameDiv = document.createElement("div");
const name = document.createElement("h6");
const collaboratorName = this.nameContainer.get(id);
const arrowHtml = `<i class="material-icons" style="font-size: 25px; color: rgb(178, 190, 181); opacity: 0.8; margin-top: 1px;">navigation</i>`;

cursorDiv.style.cssText = `
display: flex;
justify-content: center;
left: 60vh;
bottom: 60vh;
position: absolute;
background-color: rgba(0,0,0,0);
padding: 5px;
width: 80px;
z-index: 1;
height: 60px
`;
// eslint-disable-next-line quotes
nameDiv.style.cssText = `
position: absolute;
background-color: rgb(178, 190, 181);
opacity: 0.8;
padding: 5px;
border: 1px solid #ccc;
border-radius: 50px;
width: 70px;
z-index: 1;
height: 15px;
display: flex;
justify-content: center;
top: 35px;
`;

name.textContent = collaboratorName;
name.style.cssText = `
position: absolute;
font-size: 12px;
color: black;
z-index: 2;
top: -22px;
`;

const arrowSign = document.createRange().createContextualFragment(arrowHtml);
nameDiv.appendChild(name);
cursorDiv.appendChild(arrowSign);
cursorDiv.appendChild(nameDiv);
document.body.appendChild(cursorDiv);
this.cursorContainer.set(id, cursorDiv);
}

removeCursor(id) {
const cursor = this.cursorContainer.get(id);
if (cursor) {
document.body.removeChild(cursor);
this.nameContainer.delete(id);
this.cursorContainer.delete(id);
}
}

trackCursor() {
if (this.activity.collaboration.hasCollaborationStarted) {
let counter = 0
const EMIT_THRESHOLD = 5;
const emitMouseMove = (e) => {
counter++;
if (counter >= EMIT_THRESHOLD) {
const roomID = this.activity.room_id;
const xScroll = this.activity.blocksContainer.x;
const yScroll = this.activity.blocksContainer.y;
const data = { room_id: roomID, x: e.pageX, y: e.pageY, scrollx: xScroll, scrolly: yScroll };
this.activity.collaboration.socket.emit("mouse-move", data);
counter = 0;
};
};
document.addEventListener("mousemove", emitMouseMove);
}
}

}
82 changes: 78 additions & 4 deletions js/collaboration/collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ class Collaboration {
this.PORT = "http://localhost:8080/";
this.hasCollaborationStarted = false;
this.updatedProjectHtml = null;
this.randomNames = [
'Macrotis',
'Setonix',
'Petaurus',
'Marmosa',
'Macropus',
'Dasyurus',
'Caluromys',
'Acrobates',
'Didelphis',
'Philander',
'Lutreolina',
'Notoryctes',
'Metachirus',
'Dromiciops',
'Chaeropus'
];
}

// Convert the blockList into html
Expand All @@ -44,20 +61,65 @@ class Collaboration {
};

// Make calls to the socket server
makeConnection = (ID) => {
makeConnection = (room_id, name) => {
// 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;
socket.emit("joinRoom", ID);
socket.emit("joinRoom", {room_id, name});
this.activity.collabCursor.trackCursor();
} catch (error) {
console.log("Connection failed", error);
}
});

socket.on("existing-cursor", (cursorArray) => {
if (cursorArray.length > 1) {
cursorArray.forEach(({id}) => {
const ID = id[0];
if (ID !== this.socket.id){
this.activity.collabCursor.createCursor(ID);
}
});
}
});

socket.on("new-cursor", ({id}) => {
this.activity.collabCursor.createCursor(id);
});

socket.on("remove-cursor", (id) => {
this.activity.collabCursor.removeCursor(id);
})

socket.on("mouse-move", (data) => {
const { socket_id, x, y, scrollx, scrolly } = data;
const cursor = this.activity.collabCursor.cursorContainer.get(socket_id);
if (cursor) {
const currentScrollX = this.activity.blocksContainer.x;
const currentScrollY = this.activity.blocksContainer.y;
const adjustedX = x - (scrollx - currentScrollX);
const adjustedY = y - (scrolly - currentScrollY);
cursor.style.left = `${adjustedX}px`;
cursor.style.top = `${adjustedY}px`;
}
});

socket.on("add-new-name", ({id, name}) => {
this.activity.collabCursor.nameContainer.set(id, name);
})

socket.on("add-existing-names", ((namesArray) => {
if (namesArray.length > 1) {
namesArray.forEach(({id, name}) => {
this.activity.collabCursor.nameContainer.set(id, name);
});
}
}));

socket.on("connect_error", () => {
this.attempts++;
console.log("Failed to connect to the socket server. Retrying in few seconds...");
Expand All @@ -81,9 +143,21 @@ class Collaboration {
});
};

// Generate a random name for the user
generateRandomName = () => {
const randomNum = Math.floor(Math.random() * 14);
const prefix = this.randomNames[randomNum];
const suffix = Math.floor(Math.random() * 50);
const name = prefix + suffix;
return name;
}

// Start the collaboration
startCollaboration = (ID) => {
this.makeConnection(ID);
startCollaboration = (ID, name) => {
if (!name) {
name = this.generateRandomName();
}
this.makeConnection(ID, name);
};
}

Loading