Skip to content

Commit 08b31b7

Browse files
authored
AI-powered Debugger widget (#4739)
* feat: Add AI-powered debugging widget for Music Blocks projects Signed-off-by: Om Santosh Suneri <[email protected]> * importing the aidebugger widget Signed-off-by: Om Santosh Suneri <[email protected]> * Intialising the Class AIDebuggerWidget Signed-off-by: Om Santosh Suneri <[email protected]> * fix: AI Debugger Widget with cross-platform support and PR feedback fixes - fixed typos - made debugger available for both Music Blocks and Turtle Blocks - added environment-specific welcome messages - fixed all indentation and punctuation issues * fix: typo --------- Signed-off-by: Om Santosh Suneri <[email protected]>
1 parent bf59aae commit 08b31b7

File tree

3 files changed

+1183
-0
lines changed

3 files changed

+1183
-0
lines changed

js/activity.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ if (_THIS_IS_MUSIC_BLOCKS_) {
162162
"widgets/phrasemaker",
163163
"widgets/arpeggio",
164164
"widgets/aiwidget",
165+
"widgets/aidebugger",
165166
"widgets/pitchdrummatrix",
166167
"widgets/rhythmruler",
167168
"widgets/pitchstaircase",

js/blocks/WidgetBlocks.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
MusicKeyboard
6161
- js/widgets/pitchstaircase.js
6262
PitchStaircase
63+
- js/widgets/aidebugger.js
64+
AIDebuggerWidget
65+
6366
*/
6467

6568
/* exported setupWidgetBlocks */
@@ -1636,6 +1639,57 @@ function setupWidgetBlocks(activity) {
16361639
return [args[0], 1];
16371640
}
16381641
}
1642+
1643+
class AIDebugger extends StackClampBlock {
1644+
constructor() {
1645+
super("aidebugger");
1646+
this.setPalette("widgets", activity);
1647+
this.parameter = true;
1648+
this.beginnerBlock(true);
1649+
1650+
this.setHelpString([
1651+
_("Debug your music blocks project with new possibilities and more understanding."),
1652+
"documentation",
1653+
null,
1654+
"aidebugger"
1655+
]);
1656+
1657+
this.formBlock({ name: _("Debugger"), canCollapse: true });
1658+
this.makeMacro((x, y) => [
1659+
[0, "aidebugger", x, y, [null, 1]],
1660+
[1, "print", 0, 0, [0,2,null]],
1661+
[2, ["text",{"value":"Debugger Initiated"}], 0, 0, [1]]
1662+
]);
1663+
}
1664+
1665+
/**
1666+
* Handles the flow of data for the sampler block.
1667+
* @param {any[]} args - The arguments passed to the block.
1668+
* @param {object} logo - The logo object.
1669+
* @param {object} turtle - The turtle object.
1670+
* @param {object} blk - The block object.
1671+
* @returns {number[]} - The output values.
1672+
*/
1673+
flow(args, logo, turtle, blk) {
1674+
if (logo.sample === null) {
1675+
logo.sample = new AIDebuggerWidget();
1676+
}
1677+
logo.inSample = true;
1678+
logo.sample = new AIDebuggerWidget();
1679+
1680+
const listenerName = "_sampler_" + turtle;
1681+
logo.setDispatchBlock(blk, turtle, listenerName);
1682+
1683+
const __listener = event => {
1684+
logo.sample.init(activity);
1685+
};
1686+
1687+
logo.setTurtleListener(turtle, listenerName, __listener);
1688+
1689+
return [args[0], 1];
1690+
}
1691+
}
1692+
16391693
// Set up blocks if this is Music Blocks environment
16401694
if (_THIS_IS_MUSIC_BLOCKS_) {
16411695
new EnvelopeBlock().setup(activity);
@@ -1661,6 +1715,8 @@ function setupWidgetBlocks(activity) {
16611715
new MatrixCMajorBlock().setup(activity);
16621716
new MatrixBlock().setup(activity);
16631717
}
1718+
// Set up AIDebugger for both Music Blocks and Turtle Blocks
1719+
new AIDebugger().setup(activity);
16641720
// Instantiate and set up the StatusBlock
16651721
new StatusBlock().setup(activity);
16661722
}

0 commit comments

Comments
 (0)