ComputerCraft Archive

Starship - CC 1.8 Audio Editor

command operating-system unknown forum

Description

StarshipStarship is a powerful audio editor for ComputerCraft 1.8.It is based on the latest peripheral API which includes the speaker (but it's not needed to just create the sound).And of course it is...

Installation

Copy one of these commands into your ComputerCraft terminal:

Pastebin:pastebin get jGynJX5n starship_-_cc_1.8_audio_editor
wget:wget https://pastebin.com/raw/jGynJX5n starship_-_cc_1.8_audio_editor
Archive:wget https://cc.shobie.xyz/cc/get/pb-jGynJX5n starship_-_cc_1.8_audio_editor
Quick Install: wget https://cc.shobie.xyz/cc/get/pb-jGynJX5n Starship - CC 1.8 Audio Editor

Usage

Run the program after downloading

Tags

forumprograms

Source

View Original Source

Code Preview

--[[
    this is just a quick installer that fetches all that you need to run Starship outside of VedroidOS.
    it doesn't modify anything from Starship or VedroidOS, it just picks out all you need to run it
    and makes a wrapper that tells it where to save your projects.
    
    it tries to grab the latest Starship version from Store@; if this fails, just pass "backup"
    as the first argument. i tried my best to make this future-proof, but that may not be the case.

    note that an installation of starship installed via this program will register and
    run correctly within VedroidOS, although the compatibility layer will not be preserved.

    version history:
        0.2.1
            starship is now downloaded directly from Store@ (https://pastebin.com/raw/42ujyRYf) rather than the VedroidOS ROM
        0.2.0
            added compatibility layers for CC 1.7 and command computers.
        0.1.0
            initial release.
    
    license: if you really want to use this for anything, just put "Atenfyr" somewhere and i'll be happy.
]]

local args = {...}

if not http then
    printError('HTTP API not found.')
    return
end

local function grabPaste(source, path)
    local h = http.get('https://pastebin.com/raw/' .. source)
    local f = fs.open(path, 'w')
    f.write(h.readAll())
    f.close()
    h.close()
end

local function flashVedroid(path, whitelist) -- only grabs needed files from the vedroid ROM
    local f = fs.open(path, "r")
    local data = textutils.unserialise(f.readAll())
    f.close()

    for i = 1, #data do
        if not whitelist or whitelist[data[i]["path"]:gsub('//+', '/')] then
            local f = fs.open(data[i]["path"], "w")
            f.write(data[i]["text"])
            f.close()
        end
    end
end

local flashWhitelist = {
    ['/System/API/windows']=true,
    ['/System/API/sysbar']=true,
    ['/System/API/vedroid']=true,
    ['/System/API/contexts']=true
}

local storeWhitelist = {
    ['/.ds/sys/[email protected]/Resources/repo/Starship.inf']=true,
    ['/.ds/sys/[email protected]/Resources/repo/Starship.png']=true
}

print('Starship and VedroidOS were written by -DECE-, and this installer was written by Atenfyr.\n')
print('Downloading the VedroidOS beta rom..')
grabPaste('Ld2SfQNW', '/vedroidrom')
print('Flashing the necessary files..')
flashVedroid('/vedroidrom', flashWhitelist)
fs.delete('/vedroidrom')

local starshipStoreData = {['code'] = 'yG6N66BP'} -- this may not always be accurate
if args[1] ~= 'backup' then
    print('Fetching the Store@ data..')
    grabPaste('42ujyRYf', '.storedata')
    flashVedroid('.storedata', storeWhitelist)
    fs.delete('.storedata')

    local f = fs.open('/.ds/sys/[email protected]/Resources/repo/Starship.inf', 'r')
    starshipStoreData = textutils.unserialize(f.readAll())
    f.close()

    fs.move('/.ds/sys/[email protected]/Resources/repo/Starship.png', '/.ds/sys/Starship.apk/Resources/icon.png')
    fs.delete('.ds/sys/[email protected]')
end

print('Downloading Starship..')
grabPaste(starshipStoreData['code'], '/.ds/sys/Starship.apk/main')

local f = fs.open('/starship', 'w')
f.write([[local oldWindow = window.create
local oldBG, oldFG
local paletteBG = {[8]=1,[16]=1,[64]=1}
local paletteFG = {[8]=128,[16]=128,[64]=1}
local paletteBGW = {[8]=256,[16]=128,[64]=1}

-- display compatibility layer for computercraft 1.7. i didn't modify the british english variants because Starship only uses american english
if not term.getPaletteColor then
    oldBG = term.setBackgroundColor
    oldFG = term.setTextColor
    
    term.getPaletteColor = function() return 0,0,0 end
    term.setBackgroundColor = function(c)
        if paletteBG[c] then
            return oldBG(paletteBG[c])
        end
        return oldBG(c)
    end
    term.setTextColor = function(c)
        if paletteFG[c] then
            return oldFG(paletteFG[c])
        end
        return oldFG(c)
    end

    window.create = function(...)
        local newWindow = oldWindow(...)
        local oldBGW = newWindow.setBackgroundColor
        local oldFGW = newWindow.setTextColor    
        newWindow.setBackgroundColor = function(c)
            if paletteBGW[c] then
                return oldBGW(paletteBGW[c])
            end
            return oldBGW(c)
        end
        newWindow.setTextColor = function(c)
            if paletteFG[c] then
                return oldFGW(paletteFG[c])
            end
            return oldFGW(c)
        end
        newWindow.setPaletteColor = function() end
        return newWindow
    end
end

local oldPeripheralFind

-- sound compatibility layer for command computers w/o a speaker
if not peripheral.find('speaker') and commands then
    oldPeripheralFind = peripheral.find
    peripheral.find = function(...)
        local args = {...}
        if args[1] == 'speaker' then
            return {['playNote'] = function(instrument, volume, pitch)
                return commands.execAsync('playsound block.note.' .. instrument .. ' record @a ~ ~ ~ ' .. volume .. ' ' .. string.format("%.5f", (2^((pitch-12)/12))) .. ' 0') -- both wikis say that the higher volume is the farther it goes for both speakers and /playsound, so i'm leaving volume alone
            end}
        end
        return oldPeripheralFind(...)
    end
end

_G['l_login'] = 'sys' -- this is the username that Starship will use to save files 
shell.run('/.ds/sys/Starship.apk/main')
_G['l_login'] = nil

if oldBG then
    term.getPaletteColor = nil
    window.create = oldWindow
    term.setBackgroundColor = oldBG
    term.setTextColor = oldFG
end
if oldPeripheralFind then
    peripheral.find = oldPeripheralFind
end

term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)]])
f.close()

print('Finished.\n\nA compatibility wrapper has been saved at /starship, and projects will be saved at /.ds/sys/Starship.apk/Resources.')