/* extAppStart: setup and start thread */ EXPORT void extAppStart(MMDAgent *mmdagent) { audio_manager.setupAndStart(mmdagent); enable = true; drop_motion = NULL; mmdagent->sendEventMessage(MMDAGENT_EVENT_PLUGINENABLE, PLUGINAUDIO_NAME); }
/* extProcCommand: process command message */ EXPORT void extProcCommand(MMDAgent *mmdagent, const char *type, const char *args) { if(enable == true) { if(MMDAgent_strequal(type, MMDAGENT_COMMAND_PLUGINDISABLE)) { if(MMDAgent_strequal(args, PLUGINAUDIO_NAME)) { enable = false; mmdagent->sendEventMessage(MMDAGENT_EVENT_PLUGINDISABLE, PLUGINAUDIO_NAME); } } else if (audio_manager.isRunning()) { if (MMDAgent_strequal(type, PLUGINAUDIO_STARTCOMMAND)) { audio_manager.play(args); } else if (MMDAgent_strequal(type, PLUGINAUDIO_STOPCOMMAND)) { audio_manager.stop(args); } } } else { if(MMDAgent_strequal(type, MMDAGENT_COMMAND_PLUGINENABLE)) { if(MMDAgent_strequal(args, PLUGINAUDIO_NAME)) { enable = true; mmdagent->sendEventMessage(MMDAGENT_EVENT_PLUGINENABLE, PLUGINAUDIO_NAME); } } } }
/* extAppEnd: stop and free thread */ EXPORT void extAppEnd(MMDAgent * mmdagent) { if(drop_motion != NULL) free(drop_motion); audio_manager.stopAndRelease(); }
/* extProcEvent: process event message */ EXPORT void extProcEvent(MMDAgent *mmdagent, const char *type, const char *args) { int i; FILE *fp; char *buf, *p, *q; PMDObject *objs; MotionPlayer *motionPlayer; if(enable == true) { if(MMDAgent_strequal(type, MMDAGENT_EVENT_DRAGANDDROP)) { buf = MMDAgent_strdup(args); p = MMDAgent_strtok(buf, "|", &q); if(MMDAgent_strtailmatch(p, ".mp3") || MMDAgent_strtailmatch(p, ".MP3")) { /* if there is a motion file which have the same name, store it */ if(drop_motion != NULL) free(drop_motion); drop_motion = MMDAgent_strdup(p); i = MMDAgent_strlen(drop_motion); drop_motion[i-4] = '.'; drop_motion[i-3] = 'v'; drop_motion[i-2] = 'm'; drop_motion[i-1] = 'd'; fp = MMDAgent_fopen(drop_motion, "rb"); if(fp != NULL) { fclose(fp); } else { free(drop_motion); drop_motion = NULL; } /* start mp3 */ audio_manager.stop(PLUGINAUDIO_DEFAULTALIAS); q = (char *) malloc(sizeof(char) * (strlen(PLUGINAUDIO_DEFAULTALIAS) + 1 + strlen(p) + 1)); sprintf(q, "%s|%s", PLUGINAUDIO_DEFAULTALIAS, p); audio_manager.play(q); free(q); } if(buf) free(buf); } else if(MMDAgent_strequal(type, AUDIOTHREAD_EVENTSTART)) { if(drop_motion != NULL) { if(MMDAgent_strequal(args, PLUGINAUDIO_DEFAULTALIAS) == true) { objs = mmdagent->getModelList(); for (i = 0; i < mmdagent->getNumModel(); i++) { if (objs[i].isEnable() == true && objs[i].allowMotionFileDrop() == true) { for (motionPlayer = objs[i].getMotionManager()->getMotionPlayerList(); motionPlayer; motionPlayer = motionPlayer->next) { if (motionPlayer->active == true && MMDAgent_strequal(motionPlayer->name, "base") == true) { mmdagent->sendCommandMessage(MMDAGENT_COMMAND_MOTIONCHANGE, "%s|%s|%s", objs[i].getAlias(), "base", drop_motion); break; } } if (!motionPlayer) mmdagent->sendCommandMessage(MMDAGENT_COMMAND_MOTIONADD, "%s|%s|%s|FULL|ONCE|ON|ON", objs[i].getAlias(), "base", drop_motion); } } mmdagent->resetAdjustmentTimer(); } free(drop_motion); drop_motion = NULL; } } } }