0
Web IDE main
10 commitsoaky Update music-network
e0b76799 2026-09-25
main | 2026-09-25 |
| 2026-09-25 |
Overview
MITMusic Network
Quick Install on your ComputerCraft device
Type this command in the terminal:
hub get music-network
music_dj.lua main
--[[
=========================================================================
Musik-DJ - zentraler Computer, steuert alle Musik-Nodes per Funk.
=========================================================================
Sendet Play-/Stop-Befehle an alle music_node.lua-Computer in
Reichweite. Jeder Node laedt die gewuenschte Datei bei Bedarf SELBST
herunter (siehe music_node.lua) und raeumt bei Platzmangel automatisch
alte Tracks weg - dieser Computer braucht die Audiodateien selbst
nicht und schickt nur den (bloßen) Dateinamen.
Looping passiert direkt im Node (der weiss genau, wann die Datei zu
Ende ist) - kein geschaetzter Timer noetig.
TRACKS unten an deine tatsaechlich vorhandenen Dateien anpassen -
Dateiname muss exakt zu dem passen, was unter BASE_URL in
music_node.lua abrufbar ist.
Starten mit: music_dj
=========================================================================
]]
local PROTOCOL = "music_control"
local VOLUME_STEP = 0.1
-- Wie weit in der Zukunft der gemeinsame Startzeitpunkt liegt (ms).
-- Gibt allen Nodes Zeit, ihre HTTP-Verbindung aufzubauen und den ersten
-- Chunk zu laden, BEVOR wirklich Ton rauskommt - das gleicht
-- unterschiedlich schnelle Verbindungen aus und verhindert den
-- Sekunden-Versatz zwischen mehreren Speakern.
local START_DELAY_MS = 2000
-- Bekannte Tracks: Anzeige-Name -> blosser Dateiname (kein Pfad - der
-- Node haengt "sounds/" und die Download-URL selbst an).
local TRACKS = {
{ label = "Bounce", file = "bounce.dfpwm" },
{ label = "Lava Chicken", file = "lava_chicken.dfpwm" },
{ label = "Tears", file = "tears.dfpwm" },
{ label = "Precipice", file = "precipice.dfpwm" },
{ label = "Relic", file = "relic.dfpwm" },
{ label = "5", file = "5.dfpwm" },
{ label = "Creator (Music Box)", file = "creator_music_box.dfpwm" },
{ label = "Creator", file = "creator.dfpwm" },
{ label = "Otherside", file = "otherside.dfpwm" },
{ label = "Pigstep", file = "pigstep.dfpwm" },
}
------------------------------------------------------------------------
-- Reine Logik (ohne Peripheral-Zugriff - testbar)
------------------------------------------------------------------------
local function clampVolume(v)
if v < 0 then return 0 end
if v > 3 then return 3 end
return v
end
-- Welcher Button (aus 'rects') wurde bei (x,y) getroffen? nil wenn keiner.
local function hitTest(rects, x, y)
for _, r in ipairs(rects) do
if y == r.y and x >= r.x1 and x <= r.x2 then
return r.action
end
end
return nil
end
------------------------------------------------------------------------
-- Peripherals
------------------------------------------------------------------------
local modem = peripheral.find("modem", function(name, wrapped) return wrapped.isWireless() end)
if not modem then
error("Kein DRAHTLOSES Modem gefunden! Wireless- oder Ender-Modem an diesen Computer anschliessen.")
end
rednet.open(peripheral.getName(modem))
------------------------------------------------------------------------
-- Zustand
------------------------------------------------------------------------
local selectedIndex = 1
local volume = 0.5 -- leise als Standard
local looping = false
local function currentTrack()
return TRACKS[selectedIndex]
end
local function broadcastPlay()
local startAt = os.epoch("utc") + START_DELAY_MS
rednet.broadcast({ type = "play", file = currentTrack().file, volume = volume, loop = true, startAt = startAt }, PROTOCOL)
end
local function broadcastStop()
rednet.broadcast({ type = "stop" }, PROTOCOL)
end
------------------------------------------------------------------------
-- Anzeige
------------------------------------------------------------------------
local buttonRects = {}
local function render()
local w = select(1, term.getSize())
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
local title = "MUSIK-DJ"
term.setCursorPos(math.max(1, math.floor((w - #title) / 2) + 1), 1)
term.write(title)
term.setCursorPos(2, 3)
term.write(("Track: %s"):format(currentTrack().label))
term.setCursorPos(2, 4)
term.write(("Lautstaerke: %.1f"):format(volume))
term.setTextColor(looping and colors.lime or colors.gray)
term.setCursorPos(2, 5)
term.write(looping and "Status: LAEUFT (Loop)" or "Status: gestoppt")
term.setTextColor(colors.white)
buttonRects = {}
local y = 7
local function btn(label, action)
term.setBackgroundColor(colors.gray)
local text = " " .. label .. " "
term.setCursorPos(2, y)
term.write(text)
buttonRects[#buttonRects + 1] = { x1 = 2, x2 = 1 + #text, y = y, action = action }
y = y + 2
end
btn(looping and "STOP" or "PLAY (Loop)", "toggle")
btn("Lautstaerke -", "vol_down")
btn("Lautstaerke +", "vol_up")
if #TRACKS > 1 then
btn("Naechster Track", "next_track")
end
end
local function handleClick(x, y)
local action = hitTest(buttonRects, x, y)
if action == "toggle" then
if looping then
looping = false
broadcastStop()
else
looping = true
broadcastPlay()
end
elseif action == "vol_down" then
volume = clampVolume(volume - VOLUME_STEP)
if looping then broadcastPlay() end
elseif action == "vol_up" then
volume = clampVolume(volume + VOLUME_STEP)
if looping then broadcastPlay() end
elseif action == "next_track" then
selectedIndex = (selectedIndex % #TRACKS) + 1
if looping then broadcastPlay() end -- steigt sofort auf den neuen Track um
end
if action then render() end
end
------------------------------------------------------------------------
-- Hauptschleife
------------------------------------------------------------------------
render()
while true do
local _, _, x, y = os.pullEvent("mouse_click")
handleClick(x, y)
end Usage
Once installed with hub get music-network, run:
music-networkCareful what you run: This script was written by oaky, not by us.
It runs with full access to the computer you install it on — it can read and delete files there.
Read it before you run it.
About
No description provided.
MIT License
★ 0 stars
0 in-game downloads
Hardware Targets
computer