]> _ Git - songbook.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jan 2023 17:56:24 +0000 (18:56 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 10 Jan 2023 17:56:24 +0000 (18:56 +0100)
app/Http/Controllers/FrontController.php
app/Notion/Song.php
resources/js/player.js
resources/views/notion_menu.blade.php
resources/views/notion_song.blade.php

index 291f0f108f61062b3aba4ed1d6cd9de618394595..e2de20db11387333338128b6f104855f2eba9152 100644 (file)
@@ -18,6 +18,14 @@ use Notion\Pages\Properties\Title;
 
 
 class FrontController extends Controller {
+    public static $notionFileFields = [
+        'demos' => ['notion' => 'Démos Voix', 'cat' => '🎤 Démos'],
+        'instru' => ['notion' => 'Instru', 'cat' => '🎸 Instru'],
+        'record' => ['notion' => 'Enregistrement', 'cat' => '💿️ Enregistrement'],
+        'tabs' => ['notion' => 'Partition', 'cat' => '🎼 Partition'],
+        'archives' => ['notion' => 'Archives et autres fichiers', 'cat' => '🗃️ Archives']
+    ];
+
     public static function defaultCollection() {
         return redirect('/' . Collection::withoutGlobalScope('ownerclause')->find(1)->slug);
     }
@@ -186,6 +194,12 @@ class FrontController extends Controller {
 
             }
 
+            /** @var Checkbox $hideProperty */
+            $hideProperty = $song->getProprety('Cacher dans l\'app');
+            if ($hideProperty->checked) {
+                continue;
+            }
+
             $s = [];
 
             /** @var Title $titleProperty */
@@ -194,12 +208,31 @@ class FrontController extends Controller {
             $orderProperty = $song->getProprety('Ordre');
             /** @var RichTextProperty $notesProperty */
             $notesProperty = $song->getProprety('Notes générales');
-            /** @var \Notion\Pages\Properties\Files $filesProperty */
-            $filesProperty = $song->getProprety('Files & media');
-            /** @var Checkbox $hideProperty */
-            $hideProperty = $song->getProprety('Cacher dans l\'app');
-            if ($hideProperty->checked) {
-                continue;
+
+            $audioId = 0;
+            foreach (self::$notionFileFields as $key => $f) {
+                /** @var \Notion\Pages\Properties\Files $filesProperty */
+                $filesProperty = $song->getProprety($f['notion']);
+                if (!isset($s[$key])) {
+                    $s[$key] = [];
+                }
+                foreach ($filesProperty->files as $file) {
+                    $ext = self::parseExtensionFromAmazonURL($file->url);
+                    $isAudio = in_array($ext, $audios);
+                    if ($isAudio) {
+                        $audioId++;
+                        $aid = $audioId;
+                    } else {
+                        $aid = 0;
+                    }
+                    $e = explode('.', $file->name);
+                    if (count($e) > 1) {
+                        array_pop($e);
+                        $name = implode('.', $e);
+                    }
+                    $name = $name ?: self::parseFileNameFromAmazonURL($file->url);
+                    $s[$key][] = ['name' => $name, 'opturl' => $file->url, 'url' => $file->url, 'ext' => $ext, 'audio' => $aid];
+                }
             }
 
             $s['id'] = $song->id;
@@ -208,18 +241,6 @@ class FrontController extends Controller {
             $s['lyrics'] = $pageContents;
             $s['notes'] = self::_blockToHtml($notesProperty);
             $s['notion_url'] = $song->url;
-
-            $s['files'] = [];
-            $s['audios'] = [];
-            foreach ($filesProperty->files as $file) {
-                $ext = self::parseExtensionFromAmazonURL($file->url);
-                if (in_array($ext, $audios)) {
-                    $s['audios'][] = ['name' => self::parseFileNameFromAmazonURL($file->url), 'url' => $file->url, 'ext' => $ext];
-                } else {
-                    $s['files'][] = ['name' => self::parseFileNameFromAmazonURL($file->url), 'url' => $file->url, 'ext' => $ext];
-                }
-            }
-
             $res[$s['order']] = new \App\Notion\Song($s, $collection->notion_database);
         }
         ksort($res);
index 101fefc6782aa16c07cdb6c5045bd44c94ed0f62..ff358780b668c0ab89b52875ee084f682794fe14 100644 (file)
@@ -2,10 +2,11 @@
 
 namespace App\Notion;
 
+use App\Http\Controllers\FrontController;
 use Cubist\Util\Data;
 use Cubist\Util\Str;
 
-class Song extends Data{
+class Song extends Data {
 
     public function getUrl() {
         return Str::slug($this->getTitle()) . '.html';
@@ -31,25 +32,24 @@ class Song extends Data{
         return $this->get('order');
     }
 
-    public function getNotionURL(){
+    public function getNotionURL() {
         return $this->get('notion_url');
     }
 
-    public function hasSimpleChords(){
+    public function hasSimpleChords() {
         return false;
     }
 
     public function getAudioTracks() {
-        $res = $this->get('audios');
-        foreach ($res as $k=>$v) {
-            $res[$k]['i']=$k;
-            $res[$k]['opturl']=$v['url'];
+        $res = [];
+        foreach (FrontController::$notionFileFields as $key => $field) {
+            foreach ($this->get($key, []) as $file) {
+                if (!$file['audio']) {
+                    continue;
+                }
+                $res[] = $file;
+            }
         }
         return $res;
     }
-
-    public function getFiles(){
-        return $this->get('files');
-    }
-
 }
index 0046519bc534c8665d2e9ee3aea5776d750cf42d..797603766150f923ddda312abbd9a08d25304fad 100644 (file)
@@ -14,6 +14,7 @@
         $('select[data-name="audio"]').val(e[1]);
         updateSelect($('select[data-name="audio"]'));
         resetPlayers();
+
         playAudio();
         return false;
     });
@@ -48,6 +49,7 @@
         $('[data-action="play"]').hide();
 
         var audio = window.getOption('audio').toString();
+
         var t = window.getOption('audio_' + audio + '_tone');
         if (t === undefined) {
             t = 0;
index ea05a2459fb50b41616f23d9a9adf18b45846650..f76230d1bb411517e38a711ef11a56c9201aaefc 100644 (file)
                     <li><a href="#" class="clickselect">💿 {{__('Audio track')}} <select data-name="audio"
                                                                                         name="audio_{{$song->id}}">
                                 @foreach($song->getAudioTracks() as $i=>$track)
-                                    <option value="{{$i}}" data-url="{{$track['url']}}">{{$track['name']}}</option>
+                                    <option value="{{$track['audio']}}" data-url="{{$track['url']}}">{{$track['name']}}</option>
                                 @endforeach
                             </select><span></span></a></li>
-                    @foreach($song->getAudioTracks() as $i=>$track)
-                        @if($collection->transpose && isset($track['tone']) && is_numeric($track['tone']))
-                            <li data-audio="{{$i}}"><a href="#" class="clickselect">↕️{{__('Audio key')}} <select
-                                        class="audiotone"
-                                        data-name="audio_{{$i}}_tone"
-                                        name="audio_{{$i}}_tone_{{$song->id}}">
-                                        @for($i=-5;$i<=6;$i++)
-                                            <option value="{{($i+12)%12}}"
-                                                    @if($i===0) selected @endif>{{$tones[(12+$track['tone']+$i)%12].$song->mode}} @if($i>0)
-                                                    (+{{$i}}
-                                                    )
-                                                @elseif($i<0)
-                                                    ({{$i}})
-                                                @endif </option>
-                                        @endfor
-                                    </select><span></span></a></li>
-                        @endif
-                    @endforeach
                 @endif
 {{--                @if($partition)--}}
 {{--                    <li><a target="_blank" href="{{$partition}}">🎼 {{__('Partition')}}</a></li>--}}
index c3c01174781951cc60d95dce72e97df367848e84..a2d34ec55d88672d76a2500d4be611fe41a1c1fb 100644 (file)
@@ -1,5 +1,4 @@
 @php
-    $audioTracks=$song->getAudioTracks();
     $simple=$song->hasSimpleChords();
 @endphp
 
             <section class="fromnotion notes">{!! $song->notes !!}</section>
         @endif
         <div class="credits">{{$song->credits}}</div>
-        @if(count($audioTracks))
-            <h2>💿 {{__('Audios')}}</h2>
-            <ul class="files">
-                @foreach($audioTracks as $audio)
-                    <li><a class="select_audio" data-id="player_{{$audio['i']}}_0">{{$audio['name']}}</a></li>
-                @endforeach
-            </ul>
-        @endif
-        @if(count($song->getFiles()))
-            <h2>📄 {{__('Fichiers')}}</h2>
-            <ul class="files">
-                @foreach($song->getFiles() as $file)
-                    <li><a target="_blank" href="{{$file['url']}}">{{$file['name']}}.{{$file['ext']}}</a></li>
-                @endforeach
-            </ul>
-        @endif
-    </article>
-    @if(count($audioTracks))
+
+        @foreach(\App\Http\Controllers\FrontController::$notionFileFields as $key=>$field)
+            @if($song->get($key,null))
+                <h2>{{$field['cat']}}</h2>
+                <ul class="files">
+                    @foreach($song->get($key) as $file)
+                        <li>
+                            @if($file['audio'])
+                                <a class="select_audio" data-id="player_{{$file['audio']}}_0">🎵 {{$file['name']}}</a>
+                            @else
+                                <a target="_blank" href="{{$file['url']}}">🗒️ {{$file['name']}}</a>
+                            @endif
+                        </li>
+
+                    @endforeach
+                </ul>
+            @endif
+        @endforeach
+
         <div id="audioplayers">
-            @foreach($audioTracks as $audio)
-                <audio id="player_{{$audio['i']}}_0" controls loop>
-                    <source src="{{$audio['opturl']}}" type="audio/mp3"/>
-                </audio>
+            @foreach(\App\Http\Controllers\FrontController::$notionFileFields as $key => $field)
+                @foreach($song->get($key, []) as $file)
+                    @if($file['audio'])
+                        @php
+                        $hasAudio=true;
+                        @endphp
+                        <audio id="player_{{$file['audio']}}_0" controls loop>
+                            <source src="{{$file['opturl']}}"/>
+                        </audio>
+                    @endif
+                @endforeach
             @endforeach
         </div>
-    @endif
-@endsection
-@section('floating')
-    @if(count($audioTracks))
-        <a href="#" data-action="play">
-            <svg x="0" y="0" width="124.512" height="124.512" aria-hidden="true">
-                <use xlink:href="#play"/>
-            </svg>
-        </a>
-    @endif
+        @endsection
+        @section('floating')
+            @if(isset($hasAudio) && $hasAudio)
+                <a href="#" data-action="play">
+                    <svg x="0" y="0" width="124.512" height="124.512" aria-hidden="true">
+                        <use xlink:href="#play"/>
+                    </svg>
+                </a>
+            @endif
+    </article>
 @endsection