#include "Application.h" #include "Pad.h" #include "Socket.h" #include "Command.h" Command::CommandReturn _help(Application& app, Pad& pad, std::vector& args, CommandLog& io) { app.help(io); return Command::CONTINUE; } Command::CommandReturn _(Application& app, Pad& pad, std::vector& args, CommandLog& io) { return Command::CONTINUE; } Command::CommandReturn _exit(Application& app, Pad& pad, std::vector& args, CommandLog& io) { return Command::EXIT; } Command::CommandReturn _load(Application& app, Pad& pad, std::vector& args, CommandLog& io) { if(!pad){ THROW(NoPadSelectedError, ""); } if(args.size()<2 || !args[0].isString() || !args[1].isString()){ THROW(ArgumentCommandError, "Pad not loaded"); } if(args[0].asString()=="conf" || args[0].asString()=="configuration"){ if(app.load_pad_configuration(args[1].asString())){ io << "Configuration '"<< args[0].asString() << "' chargée\n"; } } else if(args[0].asString()=="def" || args[0].asString()=="definition"){ if(app.load_pad_definition(args[1].asString())){ io << "Pad '"<< args[0].asString() << "' chargé\n"; } }else{ THROW(ArgumentCommandError, "Pad not loaded"); } return Command::CONTINUE; } Command::CommandReturn _close(Application& app, Pad& _pad, std::vector& args, CommandLog& io) { return Command::CLOSE; } Command::CommandReturn _pad(Application& app, Pad& _pad, std::vector& args, CommandLog& io) { int l = args.size(); if(!l) THROW(ArgumentCommandError, ""); unsigned int i=0; Json::Value v = args[0]; std::string cmd; Pad* pad = &_pad; if(v.isInt()){ pad=&app.get_pad(v.asInt()); i++; } cmd=args[i].asString(); i++; if(cmd=="new" && args.size()>=i+1 && args[i].isString()){ if(app.load_pad_definition(args[i].asString())){ io << "Pad '"<< args[i].asString() << "' chargé\n"; }else{ io << "Impossible de charger le pad '"<< args[i].asString() <<"'\n"; } }else if(cmd=="load" && args.size()>=i+1 && args[i].isString()){ if(app.load_pad_configuration(args[i].asString())){ io << "Configuration '"<< args[i].asString() << "' chargée\n"; }else{ io << "Impossible de charger la configuration '"<< args[i].asString() <<"'\n"; } }else if(cmd=="input" && args.size()>=i+1 && args[i].isString() ){ if(!pad)THROW(NoPadSelectedError, ""); pad->input(args[i].asString()); }else if(cmd=="remove" && args.size()>=i+1 && args[i].isInt()){ if(!pad)THROW(NoPadSelectedError, ""); app.remove_pad(args[i].asInt()); }else if(cmd=="list"){ int len = app.pad_count(); io << len << " pads:\n"; for(int i=0; i"):(" ")) << app.get_id(p.get_name()) << " : " << p.get_name() <<"\n" ; } } }else if(cmd=="select" && args.size()>=i+1 && (args[i].isInt() || args[i].isString())){ if(args[i].isInt()) app.set_pad(args[i].asInt()); else app.set_pad(args[i].asString()); }else if(cmd=="clear"){ pad->clear(); }else{ THROW(ArgumentCommandError, "Erreur: argmunents non reconnus...") } return Command::CONTINUE; } void add_commands(Application& app) { app.add_command("help", _help, "Affiche cette aide"); app.add_command("close", _close, "Ferme la connexion avec la socket"); app.add_command("load", _load, "Charge une définition ou une configuration\n\ \tUsage: load (conf[figuration] | def[finition] \"FILE_OR_NAME\"\n\ \t\tFILE_OR_NAME: fichier de configuration (chemin) ou nom du pad"); app.add_command("pad", _pad, "Commande de pad.\n" "\tUsage: pad [ID] (new \"NAME\"|load \"FILE\"|input \"ARGS\"|list|remmove|select ID)\n" "\t\tID: Préciser l'id du pad pour le sélectionner, la commande suivante s'appliquera sur ce pad\n" "\t\tnew \"NAME\": Charge et selectionne en pad actif le pad NAME. Si le pad est déja chargé, il ser simplement sélectionné\n" "\t\tload \"FILE\": Charger la configuration du pad FILE. Si le pad de la configuration n'est pas chargé, il le sera automatiquement " "sinon il écrasera la configuration précédente.\n" "\t\tinput \"ARGS\": Simule une entrée du pad. ARGS doit être un Json de MidiMessage ou MidiMEssageList (exemple:" "[\"noteon\", 1, 54,127] ou [[\"noteon\", 1, 54,127][\"noteon\", 1, 56,127]])\n" "\t\tremove: supprime le pad actif (ou celui explicitement cité)\n" "\t\select ID: Change le pad actif par ID\n" "\t\tlist: Liste les différents pad\n"); app.add_command("exit", _exit, "Ferme l'application"); }