Exemplo n.º 1
0
 /**
  * 给已经添加的midi文件添加播放时长(duration字段)
  */
 public function getTrackCount()
 {
     $midis = range(199, 245);
     foreach ($midis as $v) {
         $file = public_path() . DIRECTORY_SEPARATOR . 'midis' . DIRECTORY_SEPARATOR . $v . '.mid';
         if (file_exists($file)) {
             $music = Music::find($v);
             if (!is_null($music)) {
                 $midi = new MidiDuration();
                 $midi->importMid($file);
                 $music->getNoteList[] = $midi->getNoteList();
                 echo $music->id . '-' . count($music->getNoteList);
                 // echo $music->id . '-' . $music->track;
                 echo "\n";
                 // $music->save();
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 上传单个midi文件和相关属性
  * @method store
  * @param  Request $request [description]
  * @return [json]           [是否成功]
  */
 public function store(Request $request)
 {
     // return $request->all();
     // return $request->file('midi_file')->getClientOriginalName();
     /**
      * 取得表单中各个项的值
      */
     $name = $request->get('name') or '';
     $composer = $request->get('composer') or '';
     $instrument_id = $request->get('instrument');
     $version = $request->get('version') or '';
     $press_id = $request->get('press');
     $operator = $request->user()->id;
     $organizer_id = $request->get('organizer') or 0;
     $note_content = $request->get('note_content') or '';
     $note_operator = $request->user()->id;
     // $category         = $request->get('category');
     $category = 2;
     $level = $request->get('level');
     $section_duration = $request->get('section_duration');
     $track = $request->get('track');
     // 如果文件存在且上传成功
     if (!($request->hasFile('midi_file') && $request->file('midi_file')->isValid())) {
         $data['status'] = false;
         // 文件上传失败
         $data['errCode'] = 10002;
         return $data;
     }
     if (!empty($name) && !empty($composer)) {
         /**
          * 插入数据
          */
         $music = new Music();
         $music->name = $name;
         $music->composer = $composer;
         $music->instrument_id = $instrument_id;
         $music->version = $version;
         $music->press_id = $press_id;
         $music->operator = $operator;
         $music->organizer_id = $organizer_id;
         $music->note_content = $note_content;
         $music->note_operator = $note_operator;
         $music->section_duration = $section_duration;
         $music->track = $track;
         $music->level = $level;
         $result = $music->save();
         /**
          * 插入乐曲分类标签
          */
         $music->tags()->attach($category);
         /**
          * 保存midi文件
          */
         $id = $music->id;
         // $source_name = $request->get('midi_file');
         // return $source_name;
         $path = public_path() . DIRECTORY_SEPARATOR . 'midis' . DIRECTORY_SEPARATOR;
         $name = $id . '.mid';
         $music->filename = $name;
         $request->file('midi_file')->move($path, $name);
         // 将文件名保存到DB
         $file = $path . $name;
         $midi = new MidiDuration();
         $midi->importMid($file);
         $music->duration = (int) ceil($midi->getDuration());
         $music->save();
         if ($result) {
             $data['status'] = true;
             return $data;
         }
     }
 }