Skip to content

Coderbot Music Features #148

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

Merged
merged 38 commits into from Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fd8be44
Create new class music
mikeleikele Apr 7, 2020
249726b
CoderBot audio env + Library for music class
mikeleikele Apr 7, 2020
f1aa221
dev. pause and init. notes
mikeleikele Apr 8, 2020
794b695
add packages structure and manager
mikeleikele Apr 8, 2020
f28841d
add check availability of selected instrument
Apr 9, 2020
0af1605
Add references to cls Music of packages class.
Apr 12, 2020
cc9177e
Music Package default
Apr 12, 2020
37efde2
add interface for front-end sys for Music-Ext
Apr 14, 2020
2c9eff4
rename params music class
Apr 14, 2020
df0883f
add audio volume to init. configFile coderbot
Apr 14, 2020
e28761c
Show audio volume and save it
Apr 14, 2020
50fb0c4
Set volume at save and init.
Apr 14, 2020
eeb7e6c
add HW-backend link
Apr 14, 2020
d6c9ac6
fix music pause - float duration
Apr 14, 2020
b712797
Fix audioCRTL parse
Apr 14, 2020
d6870c8
Merge branch 'volumeLevelCtrl' into music_ext_sprint_1
Apr 14, 2020
ef3ee79
added sound library
Apr 15, 2020
896acd1
updated dog verse
Apr 21, 2020
2e04f67
fixed typing error
Apr 21, 2020
887fa11
updated tests
Apr 21, 2020
ba4bd65
added control for note and verse in play_animal
Apr 21, 2020
e012793
Merge branch 'music_ext_sprint_1' of https://github.com/MicheleCarbon…
Apr 22, 2020
043ada5
Add files via upload
Apr 22, 2020
6d29679
aggiunto file per il caricamento dei pacchetti nella vue app
May 18, 2020
c5c98f7
Merge branch 'music_ext_sprint_1' of https://github.com/MicheleCarbon…
May 18, 2020
870e142
aggiunta routine per rimozione di un pacchetto musicale
Jun 1, 2020
637d8a8
modificato: musicPackages.py
Jun 1, 2020
7c412e8
added version verifier
Jun 2, 2020
e8da5b9
added addPackage function
Jun 2, 2020
84d0ab3
added updatePackage function
Jun 2, 2020
24448d5
added version control to install
Jun 5, 2020
b0b6403
fixed routine for deleting a package
Jun 9, 2020
6b3f191
fixed routine for deleting a package
Jun 9, 2020
75b8fc3
added routine for deleting a package
Jun 9, 2020
1c62800
added new sounds
Jun 9, 2020
a96b5ac
updated available sounds
Jun 9, 2020
80317c6
Merge branch 'develop' into music_ext_sprint_2
previ Nov 1, 2021
ae3af9a
Update start.sh
previ Nov 1, 2021
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
Binary file added Architectural_Spike.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from config import Config
from coderbotTestUnit import run_test as runCoderbotTestUnit
import pigpio
from musicPackages import MusicPackageManager

BUTTON_PIN = 16

Expand Down Expand Up @@ -179,6 +180,25 @@ def updateFromPackage():
os.system('sudo reboot')
return 200

def updatePackages():
"""
Add a musical package an save the list of available packages on disk
also add sounds and directory
"""
"""zipName = request.args.get("zipname")
"""
file_to_upload = connexion.request.files['file_to_upload']
print("adding " +str(file_to_upload))
print("adding " + file_to_upload.filename)
file_to_upload.save(os.path.join('./updatePackages/', file_to_upload.filename))
musicPkg = MusicPackageManager.get_instance()
response = musicPkg.addPackage(file_to_upload.filename)
if response == 1:
return 200
elif response == 2:
return 2
elif response == 3:
return 3


## Programs
Expand Down Expand Up @@ -252,4 +272,4 @@ def reset():
def testCoderbot(data):
# taking first JSON key value (varargin)
tests_state = runCoderbotTestUnit(data[list(data.keys())[0]])
return tests_state
return tests_state
54 changes: 54 additions & 0 deletions audioControls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CoderBot, a didactical programmable robot.
# Copyright (C) 2014, 2015 Roberto Previtera <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
############################################################################
# CoderBot, a didactical programmable robot.
# Copyright (C) 2014, 2015 Roberto Previtera <[email protected]>
#
# MUSICAL EXTENTION for CoderBot
# This extention is develop by:
# Michele Carbonera - [email protected] - [email protected] - [email protected]
# Antonino Tramontana - [email protected]
# Copyright (C) 2020
############################################################################

import os
import alsaaudio

class AudioCtrl:
mixer = None
_instance = None

@classmethod
def get_instance(cls):
if cls._instance is None:
cls._instance = AudioCtrl()
return cls._instance

def __init__(self):
self.mixer = alsaaudio.Mixer('PCM', cardindex=1)
#self.mixer = alsaaudio.PCM(device='numid=1', cardindex=1)

def getVolume(self):
print(self.mixer.getvolume())

def setVolume(self,valueVolume):
self.mixer.setvolume(valueVolume)
'''
if __name__ == "__main__":
a = AudioCtrl()
a.setVolume(20)
#a.setVolume(100)'''
41 changes: 40 additions & 1 deletion coderbot.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
{"move_power_angle_3": "60", "cnn_default_model": "generic_fast_low", "prog_maxblocks": "-1", "camera_jpeg_quality": "5", "show_page_control": "true", "camera_framerate": "30", "prog_scrollbars": "true", "move_fw_speed": "100", "prog_level": "adv", "move_motor_trim": "1", "move_motor_mode": "dc", "cv_image_factor": "2", "move_power_angle_1": "45", "camera_path_object_size_min": "4000", "button_func": "none", "camera_color_object_size_min": "4000", "camera_jpeg_bitrate": "1000000", "move_fw_elapse": "1", "show_control_move_commands": "true", "camera_color_object_size_max": "160000", "show_page_prefs": "true", "camera_exposure_mode": "auto", "ctrl_tr_elapse": "-1", "show_page_program": "true", "move_tr_elapse": "0.5", "camera_path_object_size_max": "160000", "sound_shutter": "$shutter.mp3", "ctrl_fw_elapse": "-1", "sound_stop": "$shutdown.mp3", "ctrl_tr_speed": "80", "ctrl_fw_speed": "100", "move_tr_speed": "85", "move_power_angle_2": "60", "ctrl_hud_image": "", "load_at_start": "", "sound_start": "$startup.mp3", "encoder": "True"}
{
"move_power_angle_3":"60",
"cnn_default_model":"generic_fast_low",
"prog_maxblocks":"-1",
"camera_jpeg_quality":"5",
"show_page_control":"true",
"camera_framerate":"30",
"prog_scrollbars":"true",
"move_fw_speed":"100",
"prog_level":"adv",
"move_motor_trim":"1",
"move_motor_mode":"dc",
"cv_image_factor":"2",
"move_power_angle_1":"45",
"camera_path_object_size_min":"4000",
"button_func":"none",
"camera_color_object_size_min":"4000",
"camera_jpeg_bitrate":"1000000",
"move_fw_elapse":"1",
"show_control_move_commands":"true",
"camera_color_object_size_max":"160000",
"show_page_prefs":"true",
"camera_exposure_mode":"auto",
"ctrl_tr_elapse":"-1",
"show_page_program":"true",
"move_tr_elapse":"0.5",
"camera_path_object_size_max":"160000",
"sound_shutter":"$shutter.mp3",
"ctrl_fw_elapse":"-1",
"sound_stop":"$shutdown.mp3",
"ctrl_tr_speed":"80",
"ctrl_fw_speed":"100",
"move_tr_speed":"85",
"move_power_angle_2":"60",
"ctrl_hud_image":"",
"load_at_start":"",
"sound_start":"$startup.mp3",
"encoder":"True",
"audio_volume_level":"100"
}
172 changes: 172 additions & 0 deletions dist/static/music_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"packages": {
"cat": {
"category": "animal",
"name_IT": "gatto",
"name_EN": "cat",
"version": "0.1",
"date": "2020-04-08",
"interface": {
"base": {
"available": "TRUE",
"icon": "cat.png"
},
"intermediate": {
"available": "TRUE",
"icon": "cat.png"
},
"advanced": {
"available": "TRUE",
"icon": "cat.png"
}
}
},
"dog": {
"category": "animal",
"name_IT": "cane",
"name_EN": "dog",
"version": "0.1",
"date": "2020-04-08",
"interface": {
"base": {
"available": "TRUE",
"icon": "dog.png"
},
"intermediate": {
"available": "TRUE",
"icon": "dog.png"
},
"advanced": {
"available": "TRUE",
"icon": "dog.png"
}
}
},
"piano": {
"category": "instrument",
"name_IT": "pianoforte",
"name_EN": "piano",
"version": "0.1",
"date": "2020-04-08",
"interface": {
"base": {
"available": "TRUE",
"icon": "piano.png"
},
"intermediate": {
"available": "TRUE",
"icon": "piano.png"
},
"advanced": {
"available": "TRUE",
"icon": "piano.png"
}
}
},
"guitar": {
"category": "instrument",
"name_IT": "chitarra",
"name_EN": "guitar",
"version": "0.1",
"date": "2020-04-08",
"interface": {
"base": {
"available": "TRUE",
"icon": "guitar.png"
},
"intermediate": {
"available": "TRUE",
"icon": "guitar.png"
},
"advanced": {
"available": "TRUE",
"icon": "guitar.png"
}
}
},
"flute": {
"category": "instrument",
"name_IT": "flauto",
"name_EN": "flute",
"version": "0.1",
"date": "2020-04-08",
"interface": {
"base": {
"available": "TRUE",
"icon": "flute.png"
},
"intermediate": {
"available": "TRUE",
"icon": "flute.png"
},
"advanced": {
"available": "TRUE",
"icon": "flute.png"
}
}
},
"pig": {
"category": "animal",
"name_IT": "maiale",
"name_EN": "pig",
"version": "0.1",
"date": "2020-06-01",
"interface": {
"base": {
"available": "TRUE",
"icon": "pig.png"
},
"intermediate": {
"available": "TRUE",
"icon": "pig.png"
},
"advanced": {
"available": "TRUE",
"icon": "pig.png"
}
}
},
"elephant": {
"category": "animal",
"name_IT": "elefante",
"name_EN": "elephant",
"version": "0.1",
"date": "2020-06-01",
"interface": {
"base": {
"available": "TRUE",
"icon": "elephant.png"
},
"intermediate": {
"available": "TRUE",
"icon": "elephant.png"
},
"advanced": {
"available": "TRUE",
"icon": "elephant.png"
}
}
},
"snake": {
"category": "animal",
"name_IT": "serpente",
"name_EN": "snake",
"version": "0.1",
"date": "2020-06-01",
"interface": {
"base": {
"available": "TRUE",
"icon": "snake.png"
},
"intermediate": {
"available": "TRUE",
"icon": "snake.png"
},
"advanced": {
"available": "TRUE",
"icon": "snake.png"
}
}
}
}
}
22 changes: 21 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from config import Config
from cnn_manager import CNNManager
from event import EventManager

from audioControls import AudioCtrl
from musicPackages import MusicPackageManager
# Logging configuration
logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -59,6 +60,8 @@
app.prog = None
app.shutdown_requested = False



## New API and web application

# API v2 is defined in v2.yml and its methods are in api.py
Expand Down Expand Up @@ -153,10 +156,23 @@ def handle_config():
"""
Overwrite configuration file on disk and reload it
"""
audioCtrl = AudioCtrl.get_instance()
audioCtrl.setVolume(int(request.form['audio_volume_level']))
Config.write(updateDict(app.bot_config, request.form))
app.bot_config = Config.get()
return "ok"

@app.route("/deletepkg", methods=["POST"])
def handle_packages():
"""
Delete a musical package an save the list of available packages on disk
also delete package sounds and directory
"""
packageName = request.form.get("nameID")
musicPkg = MusicPackageManager.get_instance()
musicPkg.deletePackage(packageName)
return "package deleted"

@app.route("/config", methods=["GET"])
def returnConfig():
"""
Expand Down Expand Up @@ -468,6 +484,10 @@ def run_server():
encoder=bool(app.bot_config.get('encoder')))
audio = Audio.get_instance()
audio.say(app.bot_config.get("sound_start"))

audioCtrl = AudioCtrl.get_instance()
audioCtrl.setVolume(int(app.bot_config.get['audio_volume_level']))

try:
cam = Camera.get_instance()
Motion.get_instance()
Expand Down
Loading