(in-package :om)
(in-package :mxml)

(defun groupnotation (self)
  (list "<notations>"
        (if (in-group? self)
            (let* ((lvl (get-grp-level self))
                   (ratio (getratiogroup (om::parent self)))
                   (act-note (second lvl))
                   (norm-note (third lvl))
                   (indx (car lvl))
                   (numdeno (getallgroups self))
                   (numdenom (remove nil 
                                     (loop for i in numdeno
                                           collect (if (not (= 1 (/ (car i) (second i)))) i) 
                                           )))
                   (simpli (/ act-note norm-note)))
              (cond 
               ((and (om::last-of-group? self) (om::first-of-group? self));singelton
                (list (tied-notation self)
                      (when (accent? self) (list (accent-notation self)))))
               ((om::first-of-group? self) 
                (progn 
                  (remove nil 
                          (append 
                           (let ((obj self)
                                 (indx (+ (length numdenom) 1)))
                                  
                             (remove nil (loop for i in (reverse numdenom)           
                                               append (progn 
                                                        (setf obj (om::parent obj))
                                                        (setf indx (- indx 1))
                                                        (firstofgroup (car i) (second i) (third i) indx)
                                                        ))))
                           (list (tied-notation self)
                                 (when (accent? self) (accent-notation self)))))
                  )
                )

               ((om::last-of-group? self);ici 
                (remove nil 
                        (append 
                         (let ((obj self)
                               (indx (+ (length numdenom) 1)))
                           (remove nil (loop for i in numdenom           
                                             append (progn 
                                                      (setf obj (om::parent obj))
                                                      (setf indx (- indx 1))
                                                      (lastofgroup indx)))))
                         (list (tied-notation self)
                               (when (accent? self) (accent-notation self)))))
                        )
                
               (t 
                (remove nil 
                    (list 
                     (when (tied? self) (tied-notation self))
                     (when (accent? self) (accent-notation self))));fix
                )))
             
           
          (when (or (tied? self) (accent? self))
            (remove nil 
                    (list 
                     (when (tied? self) (tied-notation self))
                     (when (accent? self) (accent-notation self)))))
          )
        
        ;;; VEL
        (velocity-as-xml self)
        "</notations>"
        ))