 
 (defn make-set-patch-value [data]
   (fn [db [id param]]
-    (if (contains? param :offset)
+    (if (and (contains? param :offset) (not= 0 (:offset param)))
       (assoc-in db [::control id] (nth data (:offset param)))
       db)))
 
+(defn apply-patch [db data]
+  (reduce (make-set-patch-value data) db params/params))
+
 (rf/reg-event-db ::midi/sysex
   [rf/debug]
   (fn [db [_ data]]
     (if (patch-dump? data)
-      (reduce (make-set-patch-value data) db params/params))))
+      (-> db
+          (apply-patch data)
+          (assoc ::patch data)))))
+
+(rf/reg-sub ::patch
+  (fn [db]
+    (::patch db)))
+
+(defn tab [{:keys [id]}]
+  (let [current-tab @(rf/subscribe [::panel])]
+    [:a {:class (if (or (= current-tab id)) (nil? current-tab) "is-active")
+         :href (str "#" (name id))
+         :on-click #(rf/dispatch [::panel id])}
+      (first (r/children (r/current-component)))]))
 
 (defn tabs []
-  (let [tab @(rf/subscribe [::panel])]
-    [:ul.tabs
-      [:li {:class (if (or (= tab :osc)) (nil? tab) "is-active")
-            :on-click #(rf/dispatch [::panel :osc])}
-        "Osc"]
-      [:li {:class (if (= tab :filter) "is-active")
-            :on-click #(rf/dispatch [::panel :filter])}
-        "Filter"]
-      [:li {:class (if (= tab :env) "is-active")
-            :on-click #(rf/dispatch [::panel :env])}
-        "Env"]
-      [:li {:class (if (= tab :lfo) "is-active")
-            :on-click #(rf/dispatch [::panel :lfo])}
-        "LFO"]
-      [:li {:class (if (= tab :arp) "is-active")
-            :on-click #(rf/dispatch [::panel :arp])}
-        "ARP"]]))
+  [:ul.tabs
+    [:li [tab {:id :filter} "Filter"]]
+    [:li [tab {:id :env} "Env"]]
+    [:li [tab {:id :lfo} "LFO"]]
+    [:li [tab {:id :arp} "ARP"]]
+    (if patch-inspector-enabled?
+      [:li [tab {:id :patch-inspector} "Patch inspector"]])])
 
 (defn map-in-out [in out value]
   (+ (- value (first in)) (first out)))

      [:li [toggle {:id :arp-7/step :label "Step 7"}]]
      [:li [toggle {:id :arp-8/step :label "Step 8"}]]]])

(defn main-panel []
  (let [tab @(rf/subscribe [::panel])]
    [:main.main-panel

        :env [env-panel]
        :lfo [lfo-panel]
        :arp [arp-panel]
        :patch-inspector [patch-inspector-panel]
        [:h2 "Select a panel"])]))
