[med-svn] [edfbrowser] 01/06: New upstream version 1.59

Andreas Tille tille at debian.org
Sat Sep 9 20:57:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository edfbrowser.

commit 82babf134abea7b1aa8a80bb8baaf2f2380395a5
Author: Andreas Tille <tille at debian.org>
Date:   Sat Sep 9 22:38:24 2017 +0200

    New upstream version 1.59
---
 README.txt                               |  29 ++
 about_dialog.cpp                         |   4 +-
 about_dialog.h                           |   2 +-
 active_file_chooser.cpp                  |   2 +-
 active_file_chooser.h                    |   2 +-
 adjustfiltersettings.cpp                 |   2 +-
 adjustfiltersettings.h                   |   2 +-
 annotations_dock.cpp                     | 417 +++++++++--------
 annotations_dock.h                       |   4 +-
 ascii2edf.cpp                            |   2 +-
 ascii2edf.h                              |   2 +-
 ascii_export.cpp                         |   2 +-
 ascii_export.h                           |   2 +-
 averager_curve_wnd.cpp                   |   2 +-
 averager_curve_wnd.h                     |   2 +-
 averager_dialog.cpp                      |  43 +-
 averager_dialog.h                        |   2 +-
 bdf2edf.cpp                              |   2 +-
 bdf2edf.h                                |   2 +-
 bdf_triggers.cpp                         |  44 +-
 bdf_triggers.h                           |   9 +-
 bi9800.cpp                               |   2 +-
 bi9800.h                                 |   2 +-
 biosemi2bdfplus.cpp                      |  80 ++--
 biosemi2bdfplus.h                        |   2 +-
 biox2edf.cpp                             |   2 +-
 biox2edf.h                               |   2 +-
 check_edf_file.cpp                       |   2 +-
 check_edf_file.h                         |   2 +-
 check_for_updates.cpp                    |   2 +-
 check_for_updates.h                      |   2 +-
 colordialog.cpp                          |   2 +-
 colordialog.h                            |   2 +-
 date_time_stamp_parser.c                 |   2 +-
 date_time_stamp_parser.h                 |   2 +-
 doc/manual.html                          |  15 +-
 ecg_export.cpp                           |  53 ++-
 ecg_export.h                             |   8 +-
 ecg_filter.cpp                           |   2 +-
 ecg_filter.h                             |   2 +-
 edf_annot_list.c                         | 442 ++++++++----------
 edf_annot_list.h                         |  53 ++-
 edf_annotations.cpp                      | 108 ++---
 edf_annotations.h                        |   6 +-
 edf_annotations_new.cpp                  | 769 -------------------------------
 edf_compat.cpp                           |   2 +-
 edf_compat.h                             |   2 +-
 edf_helper.c                             | 113 +++++
 date_time_stamp_parser.h => edf_helper.h |  16 +-
 edfbrowser.pro                           |   2 +
 edflib.c                                 |   2 +-
 edflib.h                                 |   2 +-
 edfplusd_cnv.cpp                         | 234 +++++-----
 edfplusd_cnv.h                           |   4 +-
 edit_annotation_dock.cpp                 | 150 +++---
 edit_annotation_dock.h                   |   8 +-
 edit_predefined_mtg.cpp                  |   2 +-
 edit_predefined_mtg.h                    |   2 +-
 emsa2edf.cpp                             |   2 +-
 emsa2edf.h                               |   2 +-
 export_annotations.cpp                   |  54 ++-
 export_annotations.h                     |   2 +-
 filter.cpp                               |   2 +-
 filter.h                                 |   2 +-
 filter_dialog.cpp                        |   2 +-
 filter_dialog.h                          |   2 +-
 filtercurve.cpp                          |   2 +-
 filtercurve.h                            |   2 +-
 filteredblockread.cpp                    |   2 +-
 filteredblockread.h                      |   2 +-
 fino2edf.cpp                             |   2 +-
 fino2edf.h                               |   2 +-
 flywheel.cpp                             |   2 +-
 flywheel.h                               |   2 +-
 fma_ecg2edf.cpp                          |  30 +-
 fma_ecg2edf.h                            |  14 +-
 global.h                                 |  23 +-
 header_editor.cpp                        |  69 ++-
 header_editor.h                          |   7 +-
 images/splash.png                        | Bin 9307 -> 9305 bytes
 import_annotations.cpp                   | 239 +++++-----
 import_annotations.h                     |   4 +-
 jump_dialog.cpp                          |  34 +-
 jump_dialog.h                            |   5 +-
 load_montage_dialog.cpp                  | 306 ++++++++----
 load_montage_dialog.h                    |   2 +-
 main.cpp                                 |   2 +-
 mainwindow.cpp                           | 149 +++---
 mainwindow.h                             |   8 +-
 mainwindow_constr.cpp                    |   9 +-
 manscan2edf.cpp                          |   2 +-
 manscan2edf.h                            |   2 +-
 mit2edf.cpp                              | 291 ++++++------
 mit2edf.h                                |   2 +-
 nexfin2edf.cpp                           |   2 +-
 nexfin2edf.h                             |   2 +-
 nk2edf.cpp                               |   2 +-
 nk2edf.h                                 |   2 +-
 options_dialog.cpp                       |   4 +-
 options_dialog.h                         |   4 +-
 pagetime_dialog.cpp                      |   2 +-
 pagetime_dialog.h                        |   2 +-
 popup_save_cancelwindow.cpp              |   2 +-
 popup_save_cancelwindow.h                |   2 +-
 print_to_bdf.cpp                         |  67 +--
 print_to_bdf.h                           |   4 +-
 print_to_edf.cpp                         |  69 ++-
 print_to_edf.h                           |   4 +-
 ravg_filter.cpp                          |   2 +-
 ravg_filter.h                            |   2 +-
 raw2edf.cpp                              |   2 +-
 raw2edf.h                                |   2 +-
 read_write_settings.cpp                  |  34 +-
 reduce_signals.cpp                       | 100 ++--
 reduce_signals.h                         |   3 +-
 save_annots.cpp                          |  57 ++-
 save_annots.h                            |   5 +-
 save_montage_dialog.cpp                  |   6 +-
 save_montage_dialog.h                    |   2 +-
 scp_ecg2edf.cpp                          |   2 +-
 scp_ecg2edf.h                            |   2 +-
 show_actual_montage_dialog.cpp           |   2 +-
 show_actual_montage_dialog.h             |   2 +-
 show_edf_hdr.cpp                         |   2 +-
 show_edf_hdr.h                           |   2 +-
 signal_chooser.cpp                       |   2 +-
 signal_chooser.h                         |   2 +-
 signalcurve.cpp                          |   4 +-
 signalcurve.h                            |   2 +-
 signals_dialog.cpp                       |   2 +-
 signals_dialog.h                         |   2 +-
 special_button.cpp                       |   2 +-
 special_button.h                         |   2 +-
 spectrum_dock.cpp                        |   2 +-
 spectrum_dock.h                          |   2 +-
 spectrumanalyzer.cpp                     |   2 +-
 spectrumanalyzer.h                       |   2 +-
 spike_filter.cpp                         |   2 +-
 spike_filter.h                           |   2 +-
 spike_filter_dialog.cpp                  |   2 +-
 spike_filter_dialog.h                    |   2 +-
 statistics_dialog.cpp                    |   2 +-
 statistics_dialog.h                      |   2 +-
 unisens2edf.cpp                          |  20 +-
 unisens2edf.h                            |   2 +-
 utc_date_time.c                          |   2 +-
 utc_date_time.h                          |   2 +-
 utils.c                                  |   2 +-
 utils.h                                  |   2 +-
 version.txt                              |  25 +
 videoplayer.cpp                          |   2 +-
 view_montage_dialog.cpp                  |   2 +-
 view_montage_dialog.h                    |   2 +-
 viewbuf.cpp                              |   2 +-
 viewcurve.cpp                            |  31 +-
 viewcurve.h                              |   2 +-
 wav2edf.cpp                              |   2 +-
 wav2edf.h                                |   2 +-
 xml.cpp                                  |   7 +-
 xml.h                                    |   2 +-
 z_ratio_filter.cpp                       |   2 +-
 z_ratio_filter.h                         |   2 +-
 z_score_dialog.cpp                       |  26 +-
 z_score_dialog.h                         |   2 +-
 164 files changed, 2028 insertions(+), 2509 deletions(-)

diff --git a/README.txt b/README.txt
index b08d10d..f1ecc56 100644
--- a/README.txt
+++ b/README.txt
@@ -45,3 +45,32 @@ Installing
 sudo make install
 
 
+
+How to compile (step by step)
+=============================
+
+- Install Git, the GCC compiler and the Qt4 development package:
+  Linux Mint 18: sudo apt-get install git-core libqt4-dev libqt4-core g++
+  openSuse Leap 42.2: sudo zypper in git-core libqt4-devel
+  Fedora 25: sudo dnf install git-core qt-devel gcc-c++
+
+- Download the source code:
+  mkdir EDFbrowser_git
+  cd EDFbrowser_git
+  git init
+  git pull https://github.com/Teuniz/EDFbrowser
+
+- Create the makefile:
+  Linux Mint 18: qmake
+  openSuse Leap 42.2: qmake
+  Fedora 25: qmake-qt4
+
+- Compile the source code and install it:
+  make -j16
+  sudo make install
+
+Now you can run the program by typing: edfbrowser
+
+
+
+
diff --git a/about_dialog.cpp b/about_dialog.cpp
index fe2e5cb..ab45821 100644
--- a/about_dialog.cpp
+++ b/about_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -67,7 +67,7 @@ UI_Aboutwindow::UI_Aboutwindow(UI_Mainwindow *mainwindow)
   textedit1->setPlainText(
         "\n " PROGRAM_NAME " " PROGRAM_VERSION "\n"
         "\n This program is made by Teunis van Beelen.\n"
-        "\n Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen.\n"
+        "\n Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen.\n"
         "\n Email: teuniz at gmail.com\n"
         "\n Disclaimer:\n"
         " Despite this software is intend to be useful, there is no warranty, use this software at your own risk!\n"
diff --git a/about_dialog.h b/about_dialog.h
index d291c52..0926a1f 100644
--- a/about_dialog.h
+++ b/about_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/active_file_chooser.cpp b/active_file_chooser.cpp
index cbd91c7..8f9a78e 100644
--- a/active_file_chooser.cpp
+++ b/active_file_chooser.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/active_file_chooser.h b/active_file_chooser.h
index ec52213..fb23c6f 100644
--- a/active_file_chooser.h
+++ b/active_file_chooser.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/adjustfiltersettings.cpp b/adjustfiltersettings.cpp
index f908cd7..ea63153 100644
--- a/adjustfiltersettings.cpp
+++ b/adjustfiltersettings.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/adjustfiltersettings.h b/adjustfiltersettings.h
index c4b7e3e..73e326c 100644
--- a/adjustfiltersettings.h
+++ b/adjustfiltersettings.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/annotations_dock.cpp b/annotations_dock.cpp
index 952d7f7..2439f3e 100644
--- a/annotations_dock.cpp
+++ b/annotations_dock.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -31,6 +31,12 @@
 
 
 
+static void process_events(void)
+{
+  qApp->processEvents();
+}
+
+
 UI_Annotationswindow::UI_Annotationswindow(int file_number, QWidget *w_parent)
 {
   QPalette palette;
@@ -81,6 +87,7 @@ UI_Annotationswindow::UI_Annotationswindow(int file_number, QWidget *w_parent)
   list->setFont(*mainwindow->monofont);
   list->setAutoFillBackground(true);
   list->setPalette(palette);
+  list->setUniformItemSizes(true);
 
   show_between_act = new QAction("Set timescale from here to next annotation", list);
   hide_annot_act = new QAction("Hide", list);
@@ -143,22 +150,26 @@ UI_Annotationswindow::UI_Annotationswindow(int file_number, QWidget *w_parent)
 
 void UI_Annotationswindow::hide_all_NK_triggers(bool)
 {
-  struct annotationblock *annot;
+  int i, sz;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot;
 
   hide_nk_triggers = 1;
 
-  while(annot != NULL)
+  sz = edfplus_annotation_size(annot_list);
+
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     if(annot->ident & (1 << ANNOT_ID_NK_TRIGGER))
     {
-      annot->hided = 1;
-
       annot->hided_in_list = 1;
-    }
 
-    annot = annot->next_annotation;
+      annot->hided = 1;
+    }
   }
 
   updateList();
@@ -169,22 +180,26 @@ void UI_Annotationswindow::hide_all_NK_triggers(bool)
 
 void UI_Annotationswindow::hide_all_BS_triggers(bool)
 {
-  struct annotationblock *annot;
+  int i, sz;
+
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotationblock *annot;
 
   hide_bs_triggers = 1;
 
-  while(annot != NULL)
+  sz = edfplus_annotation_size(annot_list);
+
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     if(annot->ident & (1 << ANNOT_ID_BS_TRIGGER))
     {
-      annot->hided = 1;
-
       annot->hided_in_list = 1;
-    }
 
-    annot = annot->next_annotation;
+      annot->hided = 1;
+    }
   }
 
   updateList();
@@ -195,22 +210,26 @@ void UI_Annotationswindow::hide_all_BS_triggers(bool)
 
 void UI_Annotationswindow::unhide_all_NK_triggers(bool)
 {
-  struct annotationblock *annot;
+  int i, sz;
+
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotationblock *annot;
 
   hide_nk_triggers = 0;
 
-  while(annot != NULL)
+  sz = edfplus_annotation_size(annot_list);
+
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     if(annot->ident & (1 << ANNOT_ID_NK_TRIGGER))
     {
-      annot->hided = 0;
-
       annot->hided_in_list = 0;
-    }
 
-    annot = annot->next_annotation;
+      annot->hided = 0;
+    }
   }
 
   updateList();
@@ -221,22 +240,26 @@ void UI_Annotationswindow::unhide_all_NK_triggers(bool)
 
 void UI_Annotationswindow::unhide_all_BS_triggers(bool)
 {
-  struct annotationblock *annot;
+  int i, sz;
+
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotationblock *annot;
 
   hide_bs_triggers = 0;
 
-  while(annot != NULL)
+  sz = edfplus_annotation_size(annot_list);
+
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     if(annot->ident & (1 << ANNOT_ID_BS_TRIGGER))
     {
-      annot->hided = 0;
-
       annot->hided_in_list = 0;
-    }
 
-    annot = annot->next_annotation;
+      annot->hided = 0;
+    }
   }
 
   updateList();
@@ -247,34 +270,31 @@ void UI_Annotationswindow::unhide_all_BS_triggers(bool)
 
 void UI_Annotationswindow::filter_edited(const QString text)
 {
-  int i, cnt, n, len;
+  int i, n, len, sz;
 
   char filter_str[32];
 
-  struct annotationblock *annot;
-
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotationblock *annot;
 
-  cnt = edfplus_annotation_count(&annot);
+  sz = edfplus_annotation_size(annot_list);
 
-  if(cnt < 1)
-  {
-    return;
-  }
+  if(sz < 1)  return;
 
   if(text.length() < 1)
   {
-    while(annot != NULL)
+    for(i=0; i<sz; i++)
     {
-      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) || ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
+      annot = edfplus_annotation_get_item(annot_list, i);
+
+      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) ||
+           ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
       {
         annot->hided_in_list = 0;
 
         annot->hided = 0;
       }
-
-      annot = annot->next_annotation;
     }
 
     updateList();
@@ -288,11 +308,14 @@ void UI_Annotationswindow::filter_edited(const QString text)
 
   len = strlen(filter_str);
 
-  if(invert_filter == 0)
+   if(invert_filter == 0)
   {
-    while(annot != NULL)
+    for(i=0; i<sz; i++)
     {
-      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) || ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
+      annot = edfplus_annotation_get_item(annot_list, i);
+
+      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) ||
+           ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
       {
         annot->hided_in_list = 1;
 
@@ -310,15 +333,16 @@ void UI_Annotationswindow::filter_edited(const QString text)
           }
         }
       }
-
-      annot = annot->next_annotation;
     }
   }
   else
   {
-    while(annot != NULL)
+    for(i=0; i<sz; i++)
     {
-      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) || ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
+      annot = edfplus_annotation_get_item(annot_list, i);
+
+      if(!(((annot->ident & (1 << ANNOT_ID_NK_TRIGGER)) && hide_nk_triggers) ||
+           ((annot->ident & (1 << ANNOT_ID_BS_TRIGGER)) && hide_bs_triggers)))
       {
         annot->hided_in_list = 0;
 
@@ -336,8 +360,6 @@ void UI_Annotationswindow::filter_edited(const QString text)
           }
         }
       }
-
-      annot = annot->next_annotation;
     }
   }
 
@@ -349,19 +371,13 @@ void UI_Annotationswindow::filter_edited(const QString text)
 
 void UI_Annotationswindow::checkbox2_clicked(int state)
 {
-  int cnt, changed=0;
+  int changed=0, sz;
 
-  struct annotationblock *annot;
-
-
-  annot = mainwindow->annotationlist[file_num];
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  cnt = edfplus_annotation_count(&annot);
+  sz = edfplus_annotation_size(annot_list);
 
-  if(cnt < 1)
-  {
-    return;
-  }
+  if(sz < 1)  return;
 
   if(state==Qt::Checked)
   {
@@ -385,20 +401,15 @@ void UI_Annotationswindow::checkbox2_clicked(int state)
 
 void UI_Annotationswindow::show_between(bool)
 {
-  int n;
+  int n, sz;
 
   long long displaytime;
 
-  struct annotationblock *annot;
-
-
   if(list->count() < 2)
   {
     return;
   }
 
-  annot = mainwindow->annotationlist[file_num];
-
   n = list->currentRow();
 
   if(n >= (list->count() - 1))
@@ -406,14 +417,19 @@ void UI_Annotationswindow::show_between(bool)
     return;
   }
 
-  while(n--)
-  {
-    annot = annot->next_annotation;
-  }
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot;
+
+  sz = edfplus_annotation_size(annot_list);
+
+  if(n >= (sz - 1))  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
 
   displaytime = annot->onset;
 
-  annot = annot->next_annotation;
+  annot = edfplus_annotation_get_item(annot_list, n + 1);
 
   displaytime -= annot->onset;
 
@@ -435,24 +451,24 @@ void UI_Annotationswindow::show_between(bool)
 
 void UI_Annotationswindow::hide_annot(bool)
 {
-  int n;
-
-  struct annotationblock *annot;
-
+  int n, sz;
 
   if(list->count() < 1)
   {
     return;
   }
 
-  annot = mainwindow->annotationlist[file_num];
-
   n = list->currentRow();
 
-  while(n--)
-  {
-    annot = annot->next_annotation;
-  }
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot;
+
+  sz = edfplus_annotation_size(annot_list);
+
+  if(n >= sz)  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
 
   annot->hided_in_list = 1;
 
@@ -464,24 +480,24 @@ void UI_Annotationswindow::hide_annot(bool)
 
 void UI_Annotationswindow::unhide_annot(bool)
 {
-  int n;
-
-  struct annotationblock *annot;
-
+  int n, sz;
 
   if(list->count() < 1)
   {
     return;
   }
 
-  annot = mainwindow->annotationlist[file_num];
-
   n = list->currentRow();
 
-  while(n--)
-  {
-    annot = annot->next_annotation;
-  }
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot;
+
+  sz = edfplus_annotation_size(annot_list);
+
+  if(n >= sz)  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
 
   annot->hided_in_list = 0;
 
@@ -493,27 +509,28 @@ void UI_Annotationswindow::unhide_annot(bool)
 
 void UI_Annotationswindow::hide_same_annots(bool)
 {
-  int n;
+  int i, n, sz;
 
   char str1[MAX_ANNOTATION_LEN],
        str2[MAX_ANNOTATION_LEN];
 
-  struct annotationblock *annot;
-
 
   if(list->count() < 1)
   {
     return;
   }
 
-  annot = mainwindow->annotationlist[file_num];
-
   n = list->currentRow();
 
-  while(n--)
-  {
-    annot = annot->next_annotation;
-  }
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot;
+
+  sz = edfplus_annotation_size(annot_list);
+
+  if(n >= sz)  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
 
   strcpy(str1, annot->annotation);
 
@@ -521,10 +538,10 @@ void UI_Annotationswindow::hide_same_annots(bool)
 
   remove_trailing_spaces(str1);
 
-  annot = mainwindow->annotationlist[file_num];
-
-  while(annot != NULL)
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     strcpy(str2, annot->annotation);
 
     remove_leading_spaces(str2);
@@ -537,8 +554,6 @@ void UI_Annotationswindow::hide_same_annots(bool)
 
       annot->hided = 1;
     }
-
-    annot = annot->next_annotation;
   }
 
   mainwindow->maincurve->update();
@@ -547,27 +562,24 @@ void UI_Annotationswindow::hide_same_annots(bool)
 
 void UI_Annotationswindow::unhide_same_annots(bool)
 {
-  int n;
+  int i, n, sz;
 
   char str1[MAX_ANNOTATION_LEN],
        str2[MAX_ANNOTATION_LEN];
 
-  struct annotationblock *annot;
+  if(list->count() < 1)  return;
 
+  n = list->currentRow();
 
-  if(list->count() < 1)
-  {
-    return;
-  }
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annot = mainwindow->annotationlist[file_num];
+  struct annotationblock *annot;
 
-  n = list->currentRow();
+  sz = edfplus_annotation_size(annot_list);
 
-  while(n--)
-  {
-    annot = annot->next_annotation;
-  }
+  if(n >= sz)  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
 
   strcpy(str1, annot->annotation);
 
@@ -575,10 +587,10 @@ void UI_Annotationswindow::unhide_same_annots(bool)
 
   remove_trailing_spaces(str1);
 
-  annot = mainwindow->annotationlist[file_num];
-
-  while(annot != NULL)
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     strcpy(str2, annot->annotation);
 
     remove_leading_spaces(str2);
@@ -591,8 +603,6 @@ void UI_Annotationswindow::unhide_same_annots(bool)
 
       annot->hided = 0;
     }
-
-    annot = annot->next_annotation;
   }
 
   mainwindow->maincurve->update();
@@ -601,17 +611,21 @@ void UI_Annotationswindow::unhide_same_annots(bool)
 
 void UI_Annotationswindow::unhide_all_annots(bool)
 {
+  int i, sz;
+
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
   struct annotationblock *annot;
 
-  annot = mainwindow->annotationlist[file_num];
+  sz = edfplus_annotation_size(annot_list);
 
-  while(annot != NULL)
+  for(i=0; i<sz; i++)
   {
+    annot = edfplus_annotation_get_item(annot_list, i);
+
     annot->hided = 0;
 
     annot->hided_in_list = 0;
-
-    annot = annot->next_annotation;
   }
 
   mainwindow->maincurve->update();
@@ -687,9 +701,9 @@ void UI_Annotationswindow::updateList(void)
   char str[MAX_ANNOTATION_LEN + 32],
        *str_tmp;
 
-  int i,
+  int i, j,
       len,
-      sequence_nr=0,
+      sz,
       jump=0,
       modified=0;
 
@@ -699,6 +713,9 @@ void UI_Annotationswindow::updateList(void)
 
   QByteArray ba;
 
+  struct annotationblock *annot;
+
+  struct annotation_list *annot_list;
 
   selected = -1;
 
@@ -710,24 +727,40 @@ void UI_Annotationswindow::updateList(void)
 
   specialfont.setPixelSize(12);
 
+  QApplication::setOverrideCursor(Qt::WaitCursor);
+
   list->clear();
 
-  edfplus_annotation_sort(&mainwindow->annotationlist[file_num]);
+  annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  sz = edfplus_annotation_size(annot_list);
+
+  QMessageBox messagewindow(QMessageBox::NoIcon, "Busy", "Sorting annotations...");
+  messagewindow.setStandardButtons(QMessageBox::NoButton);
+  if(sz > 2000)
+  {
+    messagewindow.show();
+  }
+
+  edfplus_annotation_sort(annot_list, &process_events);
 
-  annotation = mainwindow->annotationlist[file_num];
+  messagewindow.setText("Populating list...");
 
-  while(annotation != NULL)
+  for(j=0; j<sz; j++)
   {
-    if(annotation->hided_in_list)
+    if(!(j % 1000))
     {
-      annotation = annotation->next_annotation;
+      qApp->processEvents();
+    }
 
-      sequence_nr++;
+    annot = edfplus_annotation_get_item(annot_list, j);
 
+    if(annot->hided_in_list)
+    {
       continue;
     }
 
-    string = QString::fromUtf8(annotation->annotation);
+    string = QString::fromUtf8(annot->annotation);
 
     ba = string.toUtf8();
     str_tmp = ba.data();
@@ -744,30 +777,30 @@ void UI_Annotationswindow::updateList(void)
 
     if(relative)
     {
-      if((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) < 0LL)
+      if((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) < 0LL)
       {
         snprintf(str, (MAX_ANNOTATION_LEN + 32) / 2, "  -%2i:%02i:%02i.%04i",
-                (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
-                (int)(((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
-                (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
-                (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
+                (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
+                (int)(((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
+                (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
+                (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
       }
       else
       {
         snprintf(str, (MAX_ANNOTATION_LEN + 32) / 2, "  %3i:%02i:%02i.%04i",
-                (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
-                (int)((((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
-                (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
-                (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
+                (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
+                (int)((((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
+                (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
+                (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
       }
     }
     else
     {
       snprintf(str, MAX_ANNOTATION_LEN + 32, "  %3i:%02i:%02i.%04i",
-              (int)((((annotation->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION)/ 3600) % 24),
-              (int)((((annotation->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION) % 3600) / 60),
-              (int)(((annotation->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION) % 60),
-              (int)(((annotation->onset + mainwindow->edfheaderlist[file_num]->l_starttime) % TIME_DIMENSION) / 1000LL));
+              (int)((((annot->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION)/ 3600) % 24),
+              (int)((((annot->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION) % 3600) / 60),
+              (int)(((annot->onset + mainwindow->edfheaderlist[file_num]->l_starttime) / TIME_DIMENSION) % 60),
+              (int)(((annot->onset + mainwindow->edfheaderlist[file_num]->l_starttime) % TIME_DIMENSION) / 1000LL));
     }
 
     str[MAX_ANNOTATION_LEN + 31] = 0;
@@ -783,9 +816,9 @@ void UI_Annotationswindow::updateList(void)
 
     listitem = new QListWidgetItem(string, list);
 
-    listitem->setData(Qt::UserRole, QVariant(sequence_nr));
+    listitem->setData(Qt::UserRole, QVariant(j));
 
-    if(annotation->modified==1)
+    if(annot->modified==1)
     {
       listitem->setFont(specialfont);
 
@@ -794,26 +827,26 @@ void UI_Annotationswindow::updateList(void)
       modified = 1;
     }
 
-    if((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) < 0LL)
+    if((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) < 0LL)
     {
       snprintf(str, (MAX_ANNOTATION_LEN + 32) / 2, "onset: -%i:%02i:%02i.%04i",
-              (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
-              (int)(((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
-              (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
-              (int)((-(annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
+              (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
+              (int)(((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
+              (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
+              (int)((-(annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
     }
     else
     {
       snprintf(str, (MAX_ANNOTATION_LEN + 32) / 2, "onset: %2i:%02i:%02i.%04i",
-              (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
-              (int)((((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
-              (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
-              (int)(((annotation->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
+              (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION)/ 3600),
+              (int)((((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 3600) / 60),
+              (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION) % 60),
+              (int)(((annot->onset - mainwindow->edfheaderlist[file_num]->starttime_offset) % TIME_DIMENSION) / 1000LL));
     }
 
-    if(annotation->duration[0]!=0)
+    if(annot->duration[0]!=0)
     {
-      snprintf(str + strlen(str), (MAX_ANNOTATION_LEN + 32) / 2, "\nduration: %s",annotation->duration);
+      snprintf(str + strlen(str), (MAX_ANNOTATION_LEN + 32) / 2, "\nduration: %s",annot->duration);
     }
 
     str[MAX_ANNOTATION_LEN + 31] = 0;
@@ -824,27 +857,23 @@ void UI_Annotationswindow::updateList(void)
 
     string = QString::fromLatin1(str);
 
-    string.append(QString::fromUtf8(annotation->annotation));
+    string.append(QString::fromUtf8(annot->annotation));
 
     listitem->setToolTip(string);
 
-    if(annotation->selected)
+    if(annot->selected)
     {
-      selected = sequence_nr;
+      selected = j;
 
-      annotation->selected = 0;
+      annot->selected = 0;
 
-      if(annotation->jump)
+      if(annot->jump)
       {
         jump = 1;
 
-        annotation->jump = 0;
+        annot->jump = 0;
       }
     }
-
-    annotation = annotation->next_annotation;
-
-    sequence_nr++;
   }
 
   if(mainwindow->annot_editor_active)
@@ -872,48 +901,54 @@ void UI_Annotationswindow::updateList(void)
       mainwindow->save_act->setEnabled(true);
     }
   }
+
+  messagewindow.hide();
+
+  QApplication::restoreOverrideCursor();
 }
 
 
 
 void UI_Annotationswindow::annotation_selected(QListWidgetItem * item, int centered)
 {
-  int i=0, n;
+  int i=0, n, sz;
 
   long long temp;
 
+  struct annotationblock *annot;
 
-  annotation = mainwindow->annotationlist[file_num];
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
   n = item->data(Qt::UserRole).toInt();
 
+  sz = edfplus_annotation_size(annot_list);
+
+  if(n >= sz)  return;
+
+  annot = edfplus_annotation_get_item(annot_list, n);
+
   if(mainwindow->annot_editor_active)
   {
     mainwindow->annotationEditDock->set_selected_annotation(file_num, n);
   }
 
-  while(n--)
-  {
-    annotation = annotation->next_annotation;
-  }
-
   if(mainwindow->video_player->status == VIDEO_STATUS_PLAYING)
   {
-    mainwindow->video_player_seek((int)((annotation->onset - (mainwindow->pagetime / 2) - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION));
+    mainwindow->video_player_seek((int)((annot->onset - (mainwindow->pagetime / 2) - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION));
 
     return;
   }
 
   if(mainwindow->video_player->status == VIDEO_STATUS_PAUSED)
   {
-    mainwindow->video_player_seek((int)((annotation->onset - (mainwindow->pagetime / 2) - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION));
+    mainwindow->video_player_seek((int)((annot->onset - (mainwindow->pagetime / 2) - mainwindow->edfheaderlist[file_num]->starttime_offset) / TIME_DIMENSION));
   }
 
   if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_OFFSET)
   {
     for(i=0; i<mainwindow->files_open; i++)
     {
-      mainwindow->edfheaderlist[i]->viewtime = annotation->onset;
+      mainwindow->edfheaderlist[i]->viewtime = annot->onset;
 
       if(centered)
       {
@@ -926,7 +961,7 @@ void UI_Annotationswindow::annotation_selected(QListWidgetItem * item, int cente
 
   if(mainwindow->viewtime_sync==VIEWTIME_UNSYNCED)
   {
-    mainwindow->edfheaderlist[file_num]->viewtime = annotation->onset;
+    mainwindow->edfheaderlist[file_num]->viewtime = annot->onset;
 
     if(centered)
     {
@@ -938,7 +973,7 @@ void UI_Annotationswindow::annotation_selected(QListWidgetItem * item, int cente
 
   if((mainwindow->viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)||(mainwindow->viewtime_sync==VIEWTIME_USER_DEF_SYNCED))
   {
-    temp = annotation->onset - mainwindow->edfheaderlist[file_num]->viewtime;
+    temp = annot->onset - mainwindow->edfheaderlist[file_num]->viewtime;
 
     temp -= mainwindow->edfheaderlist[file_num]->starttime_offset;
 
@@ -969,3 +1004,17 @@ void UI_Annotationswindow::annotation_selected(QListWidgetItem * item, int cente
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/annotations_dock.h b/annotations_dock.h
index 20c8d17..3954332 100644
--- a/annotations_dock.h
+++ b/annotations_dock.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -86,8 +86,6 @@ public:
 
 private:
 
-  struct annotationblock *annotation;
-
   int file_num,
       relative,
       selected,
diff --git a/ascii2edf.cpp b/ascii2edf.cpp
index 17ce528..56fde18 100644
--- a/ascii2edf.cpp
+++ b/ascii2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/ascii2edf.h b/ascii2edf.h
index 71eb5ba..f1476d6 100644
--- a/ascii2edf.h
+++ b/ascii2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/ascii_export.cpp b/ascii_export.cpp
index a435896..46e35ae 100644
--- a/ascii_export.cpp
+++ b/ascii_export.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/ascii_export.h b/ascii_export.h
index 2740e3f..9249b12 100644
--- a/ascii_export.h
+++ b/ascii_export.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/averager_curve_wnd.cpp b/averager_curve_wnd.cpp
index 95e4602..d5db6b3 100644
--- a/averager_curve_wnd.cpp
+++ b/averager_curve_wnd.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/averager_curve_wnd.h b/averager_curve_wnd.h
index d888960..e2c01b7 100644
--- a/averager_curve_wnd.h
+++ b/averager_curve_wnd.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/averager_dialog.cpp b/averager_dialog.cpp
index be3b624..6342718 100644
--- a/averager_dialog.cpp
+++ b/averager_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -34,11 +34,11 @@
 
 UI_AveragerWindow::UI_AveragerWindow(QWidget *w_parent, int annot_nr)
 {
-  int i, n;
+  int i;
 
   long long recording_duration;
 
-  struct annotationblock *annot;
+  struct annotationblock *annot_ptr;
 
   mainwindow = (UI_Mainwindow *)w_parent;
 
@@ -139,18 +139,9 @@ UI_AveragerWindow::UI_AveragerWindow(QWidget *w_parent, int annot_nr)
 
   list->setCurrentRow(0, QItemSelectionModel::Select);
 
-  annot = mainwindow->annotationlist[0];
-
-  n = annot_nr;
-
-  while(n)
-  {
-    annot = annot->next_annotation;
-
-    n--;
-  }
+  annot_ptr = edfplus_annotation_get_item(&mainwindow->edfheaderlist[0]->annot_list, annot_nr);
 
-  strcpy(annot_str, annot->annotation);
+  strcpy(annot_str, annot_ptr->annotation);
   remove_trailing_spaces(annot_str);
 
   annotNameLabel->setText(annot_str);
@@ -184,7 +175,7 @@ void UI_AveragerWindow::startButtonClicked()
             l_time1,
             l_time2;
 
-  struct annotationblock *annot;
+  struct annotationblock *annot_ptr;
 
   QList<QListWidgetItem *> itemList;
 
@@ -246,18 +237,18 @@ void UI_AveragerWindow::startButtonClicked()
 
   mainwindow->signal_averaging_active = 1;
 
-  n = edfplus_annotation_count(&mainwindow->annotationlist[0]);
+  n = edfplus_annotation_size(&mainwindow->edfheaderlist[0]->annot_list);
 
   avg_cnt = 0;
 
   for(i=0; i<n; i++)
   {
-    annot = edfplus_annotation_item(&mainwindow->annotationlist[0], i);
+    annot_ptr = edfplus_annotation_get_item(&mainwindow->edfheaderlist[0]->annot_list, i);
 
-    if(((annot->onset - mainwindow->edfheaderlist[0]->starttime_offset) >= l_time1)
-      && ((annot->onset - mainwindow->edfheaderlist[0]->starttime_offset) <= l_time2))
+    if(((annot_ptr->onset - mainwindow->edfheaderlist[0]->starttime_offset) >= l_time1)
+      && ((annot_ptr->onset - mainwindow->edfheaderlist[0]->starttime_offset) <= l_time2))
     {
-      strcpy(str, annot->annotation);
+      strcpy(str, annot_ptr->annotation);
 
       remove_trailing_spaces(str);
 
@@ -335,18 +326,18 @@ void UI_AveragerWindow::startButtonClicked()
       return;
     }
 
-    n = edfplus_annotation_count(&mainwindow->annotationlist[0]);
+    n = edfplus_annotation_size(&mainwindow->edfheaderlist[0]->annot_list);
 
     avg_cnt = 0;
 
     for(i=0; i<n; i++)
     {
-      annot = edfplus_annotation_item(&mainwindow->annotationlist[0], i);
+      annot_ptr = edfplus_annotation_get_item(&mainwindow->edfheaderlist[0]->annot_list, i);
 
-      if(((annot->onset - mainwindow->edfheaderlist[0]->starttime_offset) >= l_time1)
-        && ((annot->onset - mainwindow->edfheaderlist[0]->starttime_offset) <= l_time2))
+      if(((annot_ptr->onset - mainwindow->edfheaderlist[0]->starttime_offset) >= l_time1)
+        && ((annot_ptr->onset - mainwindow->edfheaderlist[0]->starttime_offset) <= l_time2))
       {
-        strcpy(str, annot->annotation);
+        strcpy(str, annot_ptr->annotation);
 
         remove_trailing_spaces(str);
 
@@ -374,7 +365,7 @@ void UI_AveragerWindow::startButtonClicked()
             }
           }
 
-          mainwindow->edfheaderlist[0]->viewtime = annot->onset;
+          mainwindow->edfheaderlist[0]->viewtime = annot_ptr->onset;
 
           mainwindow->edfheaderlist[0]->viewtime -= mainwindow->edfheaderlist[0]->starttime_offset;
 
diff --git a/averager_dialog.h b/averager_dialog.h
index 8519339..6f6a4fe 100644
--- a/averager_dialog.h
+++ b/averager_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/bdf2edf.cpp b/bdf2edf.cpp
index ac0a8d7..fcc019b 100644
--- a/bdf2edf.cpp
+++ b/bdf2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/bdf2edf.h b/bdf2edf.h
index 99aa4f0..7919eca 100644
--- a/bdf2edf.h
+++ b/bdf2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/bdf_triggers.cpp b/bdf_triggers.cpp
index 08d415e..7d87b79 100644
--- a/bdf_triggers.cpp
+++ b/bdf_triggers.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -31,7 +31,7 @@
 
 
 
-int BDF_triggers::get_triggers(struct edfhdrblock *hdr, struct annotationblock **list)
+int BDF_triggers::get_triggers(struct edfhdrblock *hdr)
 {
   int i, j,
       sf,
@@ -53,15 +53,11 @@ int BDF_triggers::get_triggers(struct edfhdrblock *hdr, struct annotationblock *
 
   FILE *inputfile;
 
-  struct annotationblock *annotation=NULL;
+  struct annotation_list *annot_list = &hdr->annot_list;
 
-  struct annotationblock *annotlist;
+  struct annotationblock annotation;
 
-
-
-  *list = NULL;
-
-  annotlist = NULL;
+  memset(&annotation, 0, sizeof(struct annotationblock));
 
   inputfile = hdr->file_hdl;
   edfsignals = hdr->edfsignals;
@@ -216,22 +212,19 @@ int BDF_triggers::get_triggers(struct edfhdrblock *hdr, struct annotationblock *
       {
         if(!status[16])  // rising edge detected
         {
-          annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-          if(annotation == NULL)
+          annotation.file_num = hdr->file_num;
+          annotation.onset = (records_read * TIME_DIMENSION) + ((long long)(i / 3) * status_sample_duration);
+          annotation.onset += hdr->starttime_offset;
+          sprintf(annotation.annotation, "new epoch");
+          annotation.ident = (1 << ANNOT_ID_BS_TRIGGER);
+          if(edfplus_annotation_add_item(annot_list, annotation))
           {
             progress.reset();
             QMessageBox messagewindow(QMessageBox::Critical, "Error", "Malloc error (annotation).");
             messagewindow.exec();
-            *list = annotlist;
             free(buf);
             return(1);
           }
-          annotation->file_num = hdr->file_num;
-          annotation->onset = (records_read * TIME_DIMENSION) + ((long long)(i / 3) * status_sample_duration);
-          annotation->onset += hdr->starttime_offset;
-          sprintf(annotation->annotation, "new epoch");
-          annotation->ident = (1 << ANNOT_ID_BS_TRIGGER);
-          edfplus_annotation_add_item(&annotlist, annotation);
 
           trigger_cnt++;
 
@@ -252,21 +245,18 @@ int BDF_triggers::get_triggers(struct edfhdrblock *hdr, struct annotationblock *
         {
           if(!status[j])  // rising edge detected
           {
-            annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-            if(annotation == NULL)
+            annotation.onset = (records_read * TIME_DIMENSION) + ((long long)(i / 3) * status_sample_duration);
+            annotation.onset += hdr->starttime_offset;
+            sprintf(annotation.annotation, "Trigger Input %i", j + 1);
+            annotation.ident = (1 << ANNOT_ID_BS_TRIGGER);
+            if(edfplus_annotation_add_item(annot_list, annotation))
             {
               progress.reset();
               QMessageBox messagewindow(QMessageBox::Critical, "Error", "Malloc error (annotation).");
               messagewindow.exec();
-              *list = annotlist;
               free(buf);
               return(1);
             }
-            annotation->onset = (records_read * TIME_DIMENSION) + ((long long)(i / 3) * status_sample_duration);
-            annotation->onset += hdr->starttime_offset;
-            sprintf(annotation->annotation, "Trigger Input %i", j + 1);
-            annotation->ident = (1 << ANNOT_ID_BS_TRIGGER);
-            edfplus_annotation_add_item(&annotlist, annotation);
 
             trigger_cnt++;
 
@@ -286,8 +276,6 @@ int BDF_triggers::get_triggers(struct edfhdrblock *hdr, struct annotationblock *
 
   progress.reset();
 
-  *list = annotlist;
-
   free(buf);
 
   hdr->genuine_biosemi = 1;
diff --git a/bdf_triggers.h b/bdf_triggers.h
index 8c7f7ec..b816a01 100644
--- a/bdf_triggers.h
+++ b/bdf_triggers.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -54,12 +54,7 @@ class BDF_triggers
 
 public:
 
-  int get_triggers(struct edfhdrblock *, struct annotationblock **);
-
-
-private:
-
-  struct edfhdrblock *edfhdr;
+  int get_triggers(struct edfhdrblock *);
 
 };
 
diff --git a/bi9800.cpp b/bi9800.cpp
index a5b2b62..287cf93 100644
--- a/bi9800.cpp
+++ b/bi9800.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/bi9800.h b/bi9800.h
index 4fdf75f..af2bcec 100644
--- a/bi9800.h
+++ b/bi9800.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/biosemi2bdfplus.cpp b/biosemi2bdfplus.cpp
index 39de6b9..6534b15 100644
--- a/biosemi2bdfplus.cpp
+++ b/biosemi2bdfplus.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -143,9 +143,15 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
 
   struct edf_hdr_struct hdr;
 
-  struct annotationblock *annotlist=NULL;
+  struct annotation_list annot_list;
 
-  struct annotationblock *annotation;
+  memset(&annot_list, 0, sizeof(struct annotation_list));
+
+  struct annotationblock annotation;
+
+  memset(&annotation, 0, sizeof(struct annotationblock));
+
+  struct annotationblock *annot_ptr=NULL;
 
 
   for(i=0; i<16; i++)
@@ -522,7 +528,7 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
         edfclose_file(hdl_in);
         edfclose_file(hdl_out);
         free(buf);
-        edfplus_annotation_delete_list(&annotlist);
+        edfplus_annotation_empty_list(&annot_list);
         return;
       }
     }
@@ -535,7 +541,7 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
       edfclose_file(hdl_in);
       edfclose_file(hdl_out);
       free(buf);
-      edfplus_annotation_delete_list(&annotlist);
+      edfplus_annotation_empty_list(&annot_list);
       return;
     }
 
@@ -549,8 +555,10 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
           {
             if((!rising_edge) && (j < 16))
             {
-              annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-              if(annotation == NULL)
+              annotation.onset = (datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration);
+              annotation.onset += hdr.starttime_subsecond;
+              strcpy(annotation.annotation, triggerlabel[j]);
+              if(edfplus_annotation_add_item(&annot_list, annotation))
               {
                 progress.reset();
                 QMessageBox messagewindow(QMessageBox::Critical, "Error", "Malloc error (annotation).");
@@ -558,13 +566,9 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
                 edfclose_file(hdl_in);
                 edfclose_file(hdl_out);
                 free(buf);
-                edfplus_annotation_delete_list(&annotlist);
+                edfplus_annotation_empty_list(&annot_list);
                 return;
               }
-              annotation->onset = (datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration);
-              annotation->onset += hdr.starttime_subsecond;
-              strcpy(annotation->annotation, triggerlabel[j]);
-              edfplus_annotation_add_item(&annotlist, annotation);
 
               trigger_cnt++;
             }
@@ -572,19 +576,19 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
             {
               if(set_duration)
               {
-                k = edfplus_annotation_count(&annotlist);
+                k = edfplus_annotation_size(&annot_list);
                 for(; k>0; k--)
                 {
-                  annotation = edfplus_annotation_item(&annotlist, k - 1);
-                  if(annotation == NULL)
+                  annot_ptr = edfplus_annotation_get_item(&annot_list, k - 1);
+                  if(annot_ptr == NULL)
                   {
                     break;
                   }
-                  if(!strcmp(annotation->annotation, triggerlabel[j]))
+                  if(!strcmp(annot_ptr->annotation, triggerlabel[j]))
                   {
-                    sprintf(str, "%.4f", (double)((datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration) - annotation->onset) / (double)EDFLIB_TIME_DIMENSION);
+                    sprintf(str, "%.4f", (double)((datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration) - annot_ptr->onset) / (double)EDFLIB_TIME_DIMENSION);
                     str[15] = 0;
-                    strcpy(annotation->duration, str);
+                    strcpy(annot_ptr->duration, str);
                     break;
                   }
                 }
@@ -597,8 +601,10 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
           {
             if(rising_edge || (j == 16))
             {
-              annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-              if(annotation == NULL)
+              annotation.onset = (datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration);
+              annotation.onset += hdr.starttime_subsecond;
+              strcpy(annotation.annotation, triggerlabel[j]);
+              if(edfplus_annotation_add_item(&annot_list, annotation))
               {
                 progress.reset();
                 QMessageBox messagewindow(QMessageBox::Critical, "Error", "Malloc error (annotation).");
@@ -606,13 +612,9 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
                 edfclose_file(hdl_in);
                 edfclose_file(hdl_out);
                 free(buf);
-                edfplus_annotation_delete_list(&annotlist);
+                edfplus_annotation_empty_list(&annot_list);
                 return;
               }
-              annotation->onset = (datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration);
-              annotation->onset += hdr.starttime_subsecond;
-              strcpy(annotation->annotation, triggerlabel[j]);
-              edfplus_annotation_add_item(&annotlist, annotation);
 
               trigger_cnt++;
             }
@@ -620,19 +622,19 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
             {
               if(set_duration)
               {
-                k = edfplus_annotation_count(&annotlist);
+                k = edfplus_annotation_size(&annot_list);
                 for(; k>0; k--)
                 {
-                  annotation = edfplus_annotation_item(&annotlist, k - 1);
-                  if(annotation == NULL)
+                  annot_ptr = edfplus_annotation_get_item(&annot_list, k - 1);
+                  if(annot_ptr == NULL)
                   {
                     break;
                   }
-                  if(!strcmp(annotation->annotation, triggerlabel[j]))
+                  if(!strcmp(annot_ptr->annotation, triggerlabel[j]))
                   {
-                    sprintf(str, "%.4f", (double)((datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration) - annotation->onset) / (double)EDFLIB_TIME_DIMENSION);
+                    sprintf(str, "%.4f", (double)((datarecords * EDFLIB_TIME_DIMENSION) + ((long long)i * status_sample_duration) - annot_ptr->onset) / (double)EDFLIB_TIME_DIMENSION);
                     str[15] = 0;
-                    strcpy(annotation->duration, str);
+                    strcpy(annot_ptr->duration, str);
                     break;
                   }
                 }
@@ -648,19 +650,19 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
 
   edfwrite_annotation_latin1(hdl_out, 0LL, -1LL, "Recording starts");
 
-  j = edfplus_annotation_count(&annotlist);
+  j = edfplus_annotation_size(&annot_list);
 
   for(i=0; i<j; i++)
   {
-    annotation = edfplus_annotation_item(&annotlist, i);
+    annot_ptr = edfplus_annotation_get_item(&annot_list, i);
 
-    if(annotation->duration[0] == 0)
+    if(annot_ptr->duration[0] == 0)
     {
-      edfwrite_annotation_utf8(hdl_out, annotation->onset / 1000LL, -1LL, annotation->annotation);
+      edfwrite_annotation_utf8(hdl_out, annot_ptr->onset / 1000LL, -1LL, annot_ptr->annotation);
     }
     else
     {
-      edfwrite_annotation_utf8(hdl_out, annotation->onset / 1000LL, (long long)(atof(annotation->duration) * 10000.0), annotation->annotation);
+      edfwrite_annotation_utf8(hdl_out, annot_ptr->onset / 1000LL, (long long)(atof(annot_ptr->duration) * 10000.0), annot_ptr->annotation);
     }
   }
 
@@ -672,11 +674,9 @@ void UI_BIOSEMI2BDFPLUSwindow::SelectFileButton()
 
   samplerate_divider = 1;
 
-  i = edfplus_annotation_count(&annotlist);
-
-  edfplus_annotation_delete_list(&annotlist);
+  i = edfplus_annotation_size(&annot_list);
 
-  annotlist = NULL;
+  edfplus_annotation_empty_list(&annot_list);
 
   if(i % 2)
   {
diff --git a/biosemi2bdfplus.h b/biosemi2bdfplus.h
index 4861606..4411ebc 100644
--- a/biosemi2bdfplus.h
+++ b/biosemi2bdfplus.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/biox2edf.cpp b/biox2edf.cpp
index a420396..87c206c 100644
--- a/biox2edf.cpp
+++ b/biox2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2015, 2016 Teunis van Beelen
+* Copyright (C) 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/biox2edf.h b/biox2edf.h
index 6a66f22..5e540c7 100644
--- a/biox2edf.h
+++ b/biox2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2015, 2016 Teunis van Beelen
+* Copyright (C) 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/check_edf_file.cpp b/check_edf_file.cpp
index b417006..88f04d9 100644
--- a/check_edf_file.cpp
+++ b/check_edf_file.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/check_edf_file.h b/check_edf_file.h
index 112d76e..10682e3 100644
--- a/check_edf_file.h
+++ b/check_edf_file.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/check_for_updates.cpp b/check_for_updates.cpp
index 1472a86..8bf2ff9 100644
--- a/check_for_updates.cpp
+++ b/check_for_updates.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/check_for_updates.h b/check_for_updates.h
index 39951a6..a38d97c 100644
--- a/check_for_updates.h
+++ b/check_for_updates.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/colordialog.cpp b/colordialog.cpp
index e5496a1..88572e7 100644
--- a/colordialog.cpp
+++ b/colordialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/colordialog.h b/colordialog.h
index 83a070e..872de93 100644
--- a/colordialog.h
+++ b/colordialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/date_time_stamp_parser.c b/date_time_stamp_parser.c
index b42c7ec..f622955 100644
--- a/date_time_stamp_parser.c
+++ b/date_time_stamp_parser.c
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/date_time_stamp_parser.h b/date_time_stamp_parser.h
index 81af8f0..92f24b2 100644
--- a/date_time_stamp_parser.h
+++ b/date_time_stamp_parser.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/doc/manual.html b/doc/manual.html
index 9355fb3..d801fff 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -7,7 +7,7 @@
     <meta name="description" content="EDFbrowser manual">
 </head><body>
 
-<h1>EDFbrowser 1.58 manual</h1>
+<h1>EDFbrowser 1.59 manual</h1>
 
 <p><br></p>
 
@@ -55,7 +55,7 @@
   <li><a href="#Nihon_Kohden_to_EDF_format_converter">Nihon Kohden to EDF(+) format converter</a></li>
   <li><a href="#UNISENS_TO_EDFPLUS">Unisens to EDF+ format converter</a></li>
   <li><a href="#SCP_ECG_to_EDFplus">SCP ECG to EDF+ format converter</a></li>
-  <li><a href="#MIT_to_EDFplus">MIT to EDF+ format converter</a></li>
+  <li><a href="#MIT_to_EDFplus">MIT (PhysioBank)to EDF+ format converter</a></li>
   <li><a href="#Manscan_to_EDFplus">Manscan to EDF+ format converter</a></li>
   <li><a href="#Biosemi_to_BDFplus">Biosemi to BDF+ format converter</a></li>
   <li><a href="#Fino_to_EDF">Finometer to EDF format converter</a></li>
@@ -823,7 +823,7 @@
   If you don't want to downsample, set the samplerate divider to 1 (default). Otherwise select one of the possible<br>
   divider values. Those values depend on the actual samplerate and the datarecord duration.<br>
 <br>
-  The anti-aliasing filter order can be choosen as well. The default is 5th order. This prevents practically<br>
+  The anti-aliasing filter order can be choosen as well. The default is 4th order. This prevents practically<br>
   any change of aliasing.
 </p>
 
@@ -1129,14 +1129,15 @@
 
 <p><br><br></p>
 
-<h3><a name="MIT_to_EDFplus">MIT to EDF+ format converter</a></h3>
+<h3><a name="MIT_to_EDFplus">MIT (PhysioBank) to EDF+ format converter</a></h3>
 
 <p>
   This tool converts the waveform data and annotations from the MIT-format to EDF+.<br>
-  It's used for files from PhysioBank at physionet.org.<br>
-  At this moment it supports the "Format 212" and "Format 16".<br>
+  It's used for files from PhysioBank at <a href="https://physionet.org/">physionet.org</a>.<br>
+  At this moment it supports the Formats "212", "16" and "61".<br>
   Most of the signal files in PhysioBank are written in format 212.<br>
-  Annotations (in the *.atr or *.ari file) will be read and converted to EDF+ as well.<br>
+  Annotations (in the files with extensions *.atr, *.ari, *.ecg, *.trigger, *.qrs, *.apn, *.st)<br>
+  will be read and converted to EDF+ as well.<br>
   In case the file that contains the annotations has a different extension, just rename the<br>
   extension to .atr. Otherwise the converter will not read the annotations.
 </p>
diff --git a/ecg_export.cpp b/ecg_export.cpp
index 67b1d30..1cd5dc8 100644
--- a/ecg_export.cpp
+++ b/ecg_export.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -82,10 +82,15 @@ UI_ECGExport::UI_ECGExport(QWidget *w_parent)
   cancelButton->setGeometry(280, 400, 100, 25);
   cancelButton->setText("Cancel");
 
+  helpButton = new QPushButton(myobjectDialog);
+  helpButton->setGeometry(280, 300, 100, 25);
+  helpButton->setText("Help");
+
   load_signalcomps();
 
   QObject::connect(cancelButton, SIGNAL(clicked()), myobjectDialog, SLOT(close()));
   QObject::connect(startButton,  SIGNAL(clicked()), this,           SLOT(Export_RR_intervals()));
+  QObject::connect(helpButton,   SIGNAL(clicked()), this,           SLOT(helpbuttonpressed()));
 
   myobjectDialog->exec();
 }
@@ -124,7 +129,7 @@ void UI_ECGExport::Export_RR_intervals()
 
   QList<QListWidgetItem *> selectedlist;
 
-  struct annotationblock *annotation;
+  struct annotationblock annotation;
 
 
   selectedlist = list->selectedItems();
@@ -238,6 +243,11 @@ void UI_ECGExport::Export_RR_intervals()
 
   if(import_as_annots)
   {
+    if(mainwindow->annotationlist_backup==NULL)
+    {
+      mainwindow->annotationlist_backup = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[filenum]->annot_list);
+    }
+
     for(i=0; i<beat_cnt; i++)
     {
       if(whole_recording)
@@ -267,17 +277,11 @@ void UI_ECGExport::Export_RR_intervals()
         l_time += (mainwindow->edfheaderlist[mainwindow->sel_viewtime]->viewtime - signalcomp->edfhdr->viewtime);
       }
 
-      annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-      if(annotation == NULL)
-      {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
-        messagewindow.exec();
-        return;
-      }
-      annotation->onset = l_time;
-      strncpy(annotation->annotation, "R-onset", MAX_ANNOTATION_LEN);
-      annotation->annotation[MAX_ANNOTATION_LEN] = 0;
-      edfplus_annotation_add_item(&mainwindow->annotationlist[filenum], annotation);
+      memset(&annotation, 0, sizeof(struct annotationblock));
+      annotation.onset = l_time;
+      strncpy(annotation.annotation, "R-onset", MAX_ANNOTATION_LEN);
+      annotation.annotation[MAX_ANNOTATION_LEN] = 0;
+      edfplus_annotation_add_item(&mainwindow->edfheaderlist[filenum]->annot_list, annotation);
     }
 
     if(mainwindow->annotations_dock[signalcomp->filenum] == NULL)
@@ -286,13 +290,13 @@ void UI_ECGExport::Export_RR_intervals()
 
       mainwindow->addDockWidget(Qt::RightDockWidgetArea, mainwindow->annotations_dock[filenum]->docklist, Qt::Vertical);
 
-      if(!mainwindow->annotationlist[filenum])
+      if(edfplus_annotation_size(&mainwindow->edfheaderlist[filenum]->annot_list) < 1)
       {
         mainwindow->annotations_dock[filenum]->docklist->hide();
       }
     }
 
-    if(mainwindow->annotationlist[filenum])
+    if(edfplus_annotation_size(&mainwindow->edfheaderlist[filenum]->annot_list) > 0)
     {
       mainwindow->annotations_dock[filenum]->docklist->show();
 
@@ -436,6 +440,25 @@ void UI_ECGExport::load_signalcomps(void)
 }
 
 
+void UI_ECGExport::helpbuttonpressed()
+{
+#ifdef Q_OS_LINUX
+  QDesktopServices::openUrl(QUrl("file:///usr/share/doc/edfbrowser/manual.html#ECG_detection"));
+#endif
+
+#ifdef Q_OS_WIN32
+  char p_path[MAX_PATH_LENGTH];
+
+  strcpy(p_path, "file:///");
+  strcat(p_path, mainwindow->specialFolder(CSIDL_PROGRAM_FILES).toLocal8Bit().data());
+  strcat(p_path, "\\EDFbrowser\\manual.html#ECG_detection");
+  QDesktopServices::openUrl(QUrl(p_path));
+#endif
+}
+
+
+
+
 
 
 
diff --git a/ecg_export.h b/ecg_export.h
index edaca3a..b839946 100644
--- a/ecg_export.h
+++ b/ecg_export.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -52,6 +52,8 @@
 #include <QString>
 #include <QPixmap>
 #include <QCheckBox>
+#include <QDesktopServices>
+#include <QUrl>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -89,7 +91,8 @@ QDialog      *myobjectDialog;
 QListWidget  *list;
 
 QPushButton  *startButton,
-             *cancelButton;
+             *cancelButton,
+             *helpButton;
 
 QGroupBox    *groupBox1;
 
@@ -107,6 +110,7 @@ void load_signalcomps(void);
 private slots:
 
 void Export_RR_intervals();
+void helpbuttonpressed();
 
 };
 
diff --git a/ecg_filter.cpp b/ecg_filter.cpp
index fdd07f6..5b5c325 100644
--- a/ecg_filter.cpp
+++ b/ecg_filter.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/ecg_filter.h b/ecg_filter.h
index 03f9c1a..b9aa991 100644
--- a/ecg_filter.h
+++ b/ecg_filter.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/edf_annot_list.c b/edf_annot_list.c
index 4e875ab..b132066 100644
--- a/edf_annot_list.c
+++ b/edf_annot_list.c
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -30,402 +30,327 @@
 #include "edf_annot_list.h"
 
 
+#define EDF_ANNOT_MEMBLOCKSZ_II   1000
 
-void edfplus_annotation_add_item(struct annotationblock **list, struct annotationblock *annotation)
-{
-  struct annotationblock *annotlist;
+#define TIME_DIMENSION_II (10000000LL)
 
-  annotlist = *list;
 
-  annotation->next_annotation = NULL;
 
-  if(annotlist == NULL)
-  {
-    annotation->former_annotation = NULL;
+int edfplus_annotation_add_item(struct annotation_list *list, struct annotationblock annotation)
+{
+  struct annotationblock *tmp_block_list;
 
-    *list = annotation;
+  int *tmp_idx;
 
-    return;
-  }
+  if(list == NULL)  return -1;
 
-  while(annotlist->next_annotation != NULL)
+  if(list->used_sz >= list->mem_sz)
   {
-    if(annotlist->next_annotation->onset > annotation->onset)
+    tmp_block_list = (struct annotationblock *)realloc(list->items, (list->mem_sz + EDF_ANNOT_MEMBLOCKSZ_II) * sizeof(struct annotationblock));
+    if(tmp_block_list == NULL)
     {
-      break;
+      return -2;
     }
 
-    annotlist = annotlist->next_annotation;
-  }
+    list->items = tmp_block_list;
 
-  annotation->next_annotation = annotlist->next_annotation;
+    tmp_idx = (int *)realloc(list->idx, (list->mem_sz + EDF_ANNOT_MEMBLOCKSZ_II) * sizeof(int));
+    if(tmp_idx == NULL)
+    {
+      return -3;
+    }
 
-  if(annotation->next_annotation != NULL)
-  {
-    annotation->next_annotation->former_annotation = annotation;
+    list->idx = tmp_idx;
+
+    list->mem_sz += EDF_ANNOT_MEMBLOCKSZ_II;
   }
 
-  annotlist->next_annotation = annotation;
+  list->items[list->used_sz] = annotation;
 
-  annotation->former_annotation = annotlist;
-}
+  list->idx[list->sz] = list->used_sz;
 
+  list->sz++;
 
-void edfplus_annotation_add_copy(struct annotationblock **list, struct annotationblock *annotation)
-{
-  struct annotationblock *annotlist, *new_annot;
+  list->used_sz++;
 
-  annotlist = *list;
+  return 0;
+}
 
-  new_annot = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-  if(new_annot == NULL)
-  {
-    return;
-  }
 
-  memcpy(new_annot, annotation, sizeof(struct annotationblock));
+void edfplus_annotation_remove_item(struct annotation_list *list, int n)
+{
+  int i;
 
-  new_annot->next_annotation = NULL;
+  if(list == NULL)  return;
 
-  if(annotlist == NULL)
-  {
-    new_annot->former_annotation = NULL;
+  if((n >= list->sz) || (n < 0) || (list->sz < 1))  return;
 
-    *list = new_annot;
+  list->sz--;
 
-    return;
-  }
-
-  while(annotlist->next_annotation != NULL)
+  for(i=n; i<list->sz; i++)
   {
-    annotlist = annotlist->next_annotation;
+    list->idx[i] = list->idx[i+1];
   }
-
-  annotlist->next_annotation = new_annot;
-
-  new_annot->former_annotation = annotlist;
 }
 
 
-int edfplus_annotation_count(struct annotationblock **list)
+int edfplus_annotation_size(struct annotation_list *list)
 {
-  int n=0;
-
-  struct annotationblock *annotlist;
+  if(list == NULL)  return 0;
 
-  annotlist = *list;
-
-  while(annotlist != NULL)
-  {
-    annotlist = annotlist->next_annotation;
+  return(list->sz);
+}
 
-    n++;
-  }
 
-  return(n);
+void edfplus_annotation_empty_list(struct annotation_list *list)
+{
+  if(list == NULL)  return;
+
+  free(list->items);
+  free(list->idx);
+  list->items = NULL;
+  list->idx = NULL;
+  list->sz = 0;
+  list->mem_sz = 0;
+  list->used_sz = 0;
 }
 
 
-void edfplus_annotation_delete(struct annotationblock **list, int n)
+int edfplus_annotation_get_index(struct annotation_list *list, struct annotationblock *annot)
 {
-  struct annotationblock *annotlist;
-
-  annotlist = *list;
+  int i;
 
-  if(annotlist==NULL)
-  {
-    return;
-  }
+  if(list == NULL)  return -2;
 
-  while(n)
+  for(i=0; i<list->sz; i++)
   {
-    if(annotlist->next_annotation==NULL)
+    if(&list->items[list->idx[i]] == annot)
     {
-      return;
+      return i;
     }
-
-    annotlist = annotlist->next_annotation;
-
-    n--;
   }
 
-  if(annotlist->former_annotation!=NULL)
-  {
-    annotlist->former_annotation->next_annotation = annotlist->next_annotation;
-  }
-
-  if(annotlist->next_annotation!=NULL)
-  {
-    annotlist->next_annotation->former_annotation = annotlist->former_annotation;
-  }
-
-  if(annotlist->former_annotation==NULL)
-  {
-    *list = annotlist->next_annotation;
-  }
-
-  free(annotlist);
+  return -1;
 }
 
 
-void edfplus_annotation_delete_list(struct annotationblock **list)
+struct annotationblock * edfplus_annotation_get_item(struct annotation_list *list, int n)
 {
-  struct annotationblock *annotlist;
-
-  annotlist = *list;
-
-  if(annotlist == NULL)
-  {
-    return;
-  }
+  if(list == NULL)  return NULL;
 
-  while(annotlist->next_annotation != NULL)
-  {
-    annotlist = annotlist->next_annotation;
+  if((n >= list->sz) || (n < 0))  return NULL;
 
-    free(annotlist->former_annotation);
-  }
-
-  free(annotlist);
-
-  *list = NULL;
+  return &list->items[list->idx[n]];
 }
 
 
-struct annotationblock * edfplus_annotation_item(struct annotationblock **list, int n)
+void edfplus_annotation_sort(struct annotation_list *list, void (*callback)(void))  /* sort the annotationlist based on the onset time */
 {
-  struct annotationblock *annotlist;
+  int i, j, p, idx;
 
-  annotlist = *list;
+  long long onset;
 
-  if(annotlist == NULL)
-  {
-    return(NULL);
-  }
+  if(list == NULL)  return;
 
-  while(n)
+  for(i=0; i<(list->sz - 1); i++)
   {
-    if(annotlist->next_annotation == NULL)
+    if(!(i % 1000))
     {
-      return(NULL);
+      if(callback != NULL)
+      {
+        callback();
+      }
     }
 
-    annotlist = annotlist->next_annotation;
-
-    n--;
-  }
-
-  return(annotlist);
-}
-
-
-void edfplus_annotation_sort(struct annotationblock **list)  // sort the annotationlist based on the onset time
-{
-  struct annotationblock *p1, *p2, *p3, *pm, *p5;
-
-  p1 = *list;
-
-  while(p1 != NULL)
-  {
-    if(p1->next_annotation == NULL)
+    if(list->items[list->idx[i+1]].onset >= list->items[list->idx[i]].onset)
     {
-      break;
+      continue;
     }
 
-    if(p1->next_annotation->onset < p1->onset)
-    {
-      pm = p1;
-
-      p2 = p1->next_annotation;  // this one we take out
+    idx = list->idx[i+1];
 
-      p3 = p2->next_annotation;
+    onset = list->items[idx].onset;
 
-// take out
-      p1->next_annotation = p3;
-
-      if(p3 != NULL)
+    for(j=i/2, p=i; (p-j)>0; )
+    {
+      if(onset < list->items[list->idx[j]].onset)
       {
-        p3->former_annotation = p1;
-      }
-// take out done
+        p = j;
 
-      while(1)  // search backwards till we find the right place to put it
+        j /= 2;
+      }
+      else
       {
-        p5 = pm->former_annotation;
-
-        if(p5 == NULL)
-        {
-          pm->former_annotation = p2;
-
-          p2->next_annotation = pm;
-
-          p2->former_annotation = NULL;
-
-          *list = p2;
-
-          break;
-        }
-
-        if(p5->onset <= p2->onset)  // insert it here
+        if((p-j) == 1)
         {
-          pm->former_annotation = p2;
-
-          p2->next_annotation = pm;
-
-          p2->former_annotation = p5;
-
-          p5->next_annotation = p2;
+          j++;
 
           break;
         }
 
-        pm = p5;
+        j = (j + p) / 2;
       }
     }
-    else
-    {
-      p1 = p1->next_annotation;  // continue searching the list from where we stopped before
-    }
+
+    memmove(list->idx + j + 1, list->idx + j, (i - j + 1) * sizeof(int));
+
+    list->idx[j] = idx;
   }
 }
 
 
-struct annotationblock * edfplus_annotation_copy_list(struct annotationblock **list)
+struct annotation_list * edfplus_annotation_create_list_copy(struct annotation_list *list)
 {
-  struct annotationblock *annot, *annot2, *annot3;
+  struct annotation_list *cpy;
 
-  annot = *list;
+  if(list == NULL)  return NULL;
 
-  if(annot==NULL)
+  cpy = (struct annotation_list *)calloc(1, sizeof(struct annotation_list));
+  if(cpy == NULL)
   {
-    return(NULL);
+    return NULL;
   }
 
-  annot2 = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-
-  annot3 = annot2;
-
-  memcpy(annot2, annot, sizeof(struct annotationblock));
+  if(list->sz > 0)
+  {
+    cpy->items = (struct annotationblock *)calloc(1, sizeof(struct annotationblock) * list->mem_sz);
+    if(cpy->items == NULL)
+    {
+      free(cpy);
+      return NULL;
+    }
 
-  annot = annot->next_annotation;
+    cpy->idx = (int *)calloc(1, sizeof(int) * list->mem_sz);
+    if(cpy->idx == NULL)
+    {
+      free(cpy->items);
+      free(cpy);
+      return NULL;
+    }
 
-  while(annot!=NULL)
-  {
-    annot2->next_annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
+    cpy->mem_sz = list->mem_sz;
 
-    memcpy(annot2->next_annotation, annot, sizeof(struct annotationblock));
+    cpy->sz = list->sz;
 
-    annot2->next_annotation->former_annotation = annot2;
+    cpy->used_sz = list->used_sz;
 
-    annot2 = annot2->next_annotation;
+    memcpy(cpy->items, list->items, cpy->mem_sz * sizeof(struct annotationblock));
 
-    annot = annot->next_annotation;
+    memcpy(cpy->idx, list->idx, cpy->mem_sz * sizeof(int));
   }
 
-  return(annot3);
+  return cpy;
 }
 
 
-int get_tal_timestamp_digit_cnt(struct edfhdrblock *hdr)
+void edfplus_annotation_copy_list(struct annotation_list *destlist, struct annotation_list *srclist)
 {
-  int timestamp_digits;
+  if((destlist == NULL) || (srclist == NULL)) return;
+
+  if(destlist->sz > 0)
+  {
+    free(destlist->items);
+
+    destlist->items = NULL;
 
-  char scratchpad[256];
+    free(destlist->idx);
 
-  long long time;
+    destlist->idx = NULL;
 
+    destlist->sz = 0;
 
-  if(hdr==NULL)
+    destlist->mem_sz = 0;
+
+    destlist->used_sz = 0;
+  }
+
+  destlist->items = (struct annotationblock *)calloc(1, srclist->mem_sz * sizeof(struct annotationblock));
+  if(destlist->items == NULL)
   {
-    return(-1);
+    return;
   }
 
-  time = (hdr->datarecords * hdr->long_data_record_duration) / TIME_DIMENSION;
+  destlist->idx = (int *)calloc(1, srclist->mem_sz * sizeof(int));
+  if(destlist->idx == NULL)
+  {
+    free(destlist->items);
+    destlist->items = NULL;
+    return;
+  }
 
-#ifdef _WIN32
-  timestamp_digits = __mingw_snprintf(scratchpad, 256, "%lli", time);
-#else
-  timestamp_digits = snprintf(scratchpad, 256, "%lli", time);
-#endif
+  destlist->sz = srclist->sz;
+
+  destlist->used_sz = srclist->used_sz;
+
+  destlist->mem_sz = srclist->mem_sz;
 
-  return(timestamp_digits);
+  memcpy(destlist->items, srclist->items, destlist->mem_sz * sizeof(struct annotationblock));
+
+  memcpy(destlist->idx, srclist->idx, destlist->mem_sz * sizeof(int));
 }
 
 
-int get_tal_timestamp_decimal_cnt(struct edfhdrblock *hdr)
+int edfplus_annotation_remove_duplicates(struct annotation_list *list)
 {
-  int i, j,
-      timestamp_decimals;
+  int i, j, dup_cnt=0;
 
+  struct annotationblock *annot;
 
-  if(hdr==NULL)
-  {
-    return(-1);
-  }
+  if(list == NULL)  return -1;
 
-  j = 10;
+  if(list->sz < 2)  return 0;
 
-  for(timestamp_decimals=7; timestamp_decimals>0; timestamp_decimals--)
+  for(i=0; i<(list->sz - 1); i++)
   {
-    if(hdr->long_data_record_duration % j)
-    {
-      break;
-    }
+    annot = &list->items[list->idx[i]];
 
-    j *= 10;
-  }
+    if(annot->file_num != list->items[list->idx[i + 1]].file_num)  continue;
 
-  if((hdr->edfplus==1)||(hdr->bdfplus==1))
-  {
-    j = 10;
+    if(annot->onset != list->items[list->idx[i + 1]].onset)  continue;
 
-    for(i=7; i>0; i--)
-    {
-      if(hdr->starttime_offset % j)
-      {
-        break;
-      }
+    if(strcmp(annot->annotation, list->items[list->idx[i + 1]].annotation))  continue;
 
-      j *= 10;
-    }
+    if(strcmp(annot->duration, list->items[list->idx[i + 1]].duration))  continue;
+
+    list->sz--;
 
-    if(i > timestamp_decimals)
+    for(j=i; j<(list->sz); j++)
     {
-      timestamp_decimals = i;
+      list->idx[j] = list->idx[j+1];
     }
+
+    dup_cnt++;
   }
 
-  return(timestamp_decimals);
+  return dup_cnt;
 }
 
 
-int get_max_annotation_strlen(struct annotationblock **list)
+int edfplus_annotation_get_max_annotation_strlen(struct annotation_list *list)
 {
-  int j,
+  int i, j,
       len,
       annot_descr_len=0,
       annot_duration_len=0,
       timestamp_digits=0,
       timestamp_decimals=0;
 
-  char scratchpad[256];
+  char scratchpad[1024];
 
   struct annotationblock *annot;
 
-
-  annot = list[0];
-
-  if(annot==NULL)
+  if(list == NULL)
   {
-    return(0);
+    return 0;
   }
 
-  while(annot!=NULL)
+  for(i=0; i<list->sz; i++)
   {
+    annot = &list->items[list->idx[i]];
 #ifdef _WIN32
-    len = __mingw_snprintf(scratchpad, 256, "%lli", annot->onset / TIME_DIMENSION);
+    len = __mingw_snprintf(scratchpad, 256, "%lli", annot->onset / TIME_DIMENSION_II);
 #else
-    len = snprintf(scratchpad, 256, "%lli", annot->onset / TIME_DIMENSION);
+    len = snprintf(scratchpad, 256, "%lli", annot->onset / TIME_DIMENSION_II);
 #endif
 
     if(len > timestamp_digits)
@@ -463,8 +388,6 @@ int get_max_annotation_strlen(struct annotationblock **list)
     {
       annot_duration_len = len;
     }
-
-    annot = annot->next_annotation;
   }
 
   if(annot_duration_len)
@@ -495,3 +418,14 @@ int get_max_annotation_strlen(struct annotationblock **list)
 
 
 
+
+
+
+
+
+
+
+
+
+
+
diff --git a/edf_annot_list.h b/edf_annot_list.h
index e43356a..f434eab 100644
--- a/edf_annot_list.h
+++ b/edf_annot_list.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -32,28 +32,49 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 
-#include "global.h"
+#define MAX_ANNOTATION_LEN_II   512
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
-void edfplus_annotation_add_item(struct annotationblock **, struct annotationblock *);
-void edfplus_annotation_add_copy(struct annotationblock **, struct annotationblock *);
-int edfplus_annotation_count(struct annotationblock **);
-void edfplus_annotation_delete(struct annotationblock **, int);
-void edfplus_annotation_delete_list(struct annotationblock **);
-struct annotationblock * edfplus_annotation_item(struct annotationblock **, int);
-void edfplus_annotation_sort(struct annotationblock **);
-struct annotationblock * edfplus_annotation_copy_list(struct annotationblock **);
-
-int get_tal_timestamp_digit_cnt(struct edfhdrblock *);
-int get_tal_timestamp_decimal_cnt(struct edfhdrblock *);
-int get_max_annotation_strlen(struct annotationblock **);
-
+struct annotationblock{
+        int file_num;
+        long long onset;
+        char duration[16];
+        char annotation[MAX_ANNOTATION_LEN_II + 1];
+        int modified;
+        int x_pos;
+        int selected;
+        int jump;
+        int hided;
+        int hided_in_list;
+        unsigned int ident;
+       };
+
+struct annotation_list{
+        struct annotationblock *items;
+        int sz;
+        int used_sz;
+        int mem_sz;
+        int *idx;
+};
+
+
+int edfplus_annotation_add_item(struct annotation_list *, struct annotationblock);
+int edfplus_annotation_size(struct annotation_list *);
+void edfplus_annotation_empty_list(struct annotation_list *);
+void edfplus_annotation_remove_item(struct annotation_list *, int);
+struct annotationblock * edfplus_annotation_get_item(struct annotation_list *, int);
+int edfplus_annotation_get_index(struct annotation_list *, struct annotationblock *);
+void edfplus_annotation_sort(struct annotation_list *, void (*)(void));
+struct annotation_list * edfplus_annotation_create_list_copy(struct annotation_list *);
+int edfplus_annotation_remove_duplicates(struct annotation_list *);
+int edfplus_annotation_get_max_annotation_strlen(struct annotation_list *);
+void edfplus_annotation_copy_list(struct annotation_list *, struct annotation_list *);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/edf_annotations.cpp b/edf_annotations.cpp
index db4790f..5f636a2 100644
--- a/edf_annotations.cpp
+++ b/edf_annotations.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -31,7 +31,13 @@
 
 
 
-int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr, struct annotationblock **annotslist, int read_nk_trigger_signal)
+static void process_events(void)
+{
+  qApp->processEvents();
+}
+
+
+int EDF_annotations::get_annotations(struct edfhdrblock *edf_hdr, int read_nk_trigger_signal)
 {
   int i, j, k, p, r=0, n,
       edfsignals,
@@ -77,10 +83,7 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
 
   struct edfparamblock *edfparam;
 
-  struct annotationblock *new_annotation=NULL,
-                         *temp_annotation;
-
-
+  struct annotationblock annotblock;
 
   inputfile = edf_hdr->file_hdl;
   edfsignals = edf_hdr->edfsignals;
@@ -422,8 +425,19 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
             {
               if(n >= 0)
               {
-                new_annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-                if(new_annotation==NULL)
+                memset(&annotblock, 0, sizeof(annotationblock));
+                annotblock.file_num = edf_hdr->file_num;
+                annotblock.onset = get_long_time(time_in_txt);
+                for(j=0; j<n; j++)
+                {
+                  if(j==MAX_ANNOTATION_LEN)  break;
+                  annotblock.annotation[j] = scratchpad[j];
+                }
+                annotblock.annotation[j] = 0;
+
+                if(duration)  strcpy(annotblock.duration, duration_in_txt);
+
+                if(edfplus_annotation_add_item(&edf_hdr->annot_list, annotblock))
                 {
                   progress.reset();
                   QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred while reading annotations.");
@@ -434,39 +448,6 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
                   free(duration_in_txt);
                   return(1);
                 }
-
-                new_annotation->next_annotation = NULL;
-                new_annotation->file_num = file_num;
-
-                new_annotation->annotation[0] = 0;
-
-                if(duration)  strcpy(new_annotation->duration, duration_in_txt);
-                else  new_annotation->duration[0] = 0;
-
-                for(j=0; j<n; j++)
-                {
-                  if(j==MAX_ANNOTATION_LEN)  break;
-                  new_annotation->annotation[j] = scratchpad[j];
-                }
-                new_annotation->annotation[j] = 0;
-
-                new_annotation->file_num = edf_hdr->file_num;
-
-                new_annotation->onset = get_long_time(time_in_txt);
-
-                if(*annotslist!=NULL)
-                {
-                  temp_annotation = *annotslist;
-                  while(temp_annotation->next_annotation)  temp_annotation = temp_annotation->next_annotation;
-
-                  new_annotation->former_annotation = temp_annotation;
-                  temp_annotation->next_annotation = new_annotation;
-                }
-                else
-                {
-                  new_annotation->former_annotation = NULL;
-                  *annotslist = new_annotation;
-                }
               }
             }
 
@@ -558,8 +539,14 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
             {
               nk_triggers_cnt++;
 
-              new_annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-              if(new_annotation==NULL)
+              memset(&annotblock, 0, sizeof(annotationblock));
+              annotblock.file_num = edf_hdr->file_num;
+              annotblock.onset = ((long long)i * data_record_duration) + ((long long)k * nk_trigger_sample_duration);
+              annotblock.onset += edf_hdr->starttime_offset;
+              strcpy(annotblock.annotation, nk_triggerlabel[j]);
+              annotblock.ident = (1 << ANNOT_ID_NK_TRIGGER);
+
+              if(edfplus_annotation_add_item(&edf_hdr->annot_list, annotblock))
               {
                 progress.reset();
                 QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred while reading annotations.");
@@ -570,31 +557,6 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
                 free(duration_in_txt);
                 return(1);
               }
-
-              new_annotation->file_num = edf_hdr->file_num;
-              new_annotation->next_annotation = NULL;
-              new_annotation->file_num = file_num;
-              strcpy(new_annotation->annotation, nk_triggerlabel[j]);
-
-              new_annotation->onset = ((long long)i * data_record_duration) + ((long long)k * nk_trigger_sample_duration);
-
-              new_annotation->onset += edf_hdr->starttime_offset;
-
-              new_annotation->ident = (1 << ANNOT_ID_NK_TRIGGER);
-
-              if(*annotslist!=NULL)
-              {
-                temp_annotation = *annotslist;
-                while(temp_annotation->next_annotation)  temp_annotation = temp_annotation->next_annotation;
-
-                new_annotation->former_annotation = temp_annotation;
-                temp_annotation->next_annotation = new_annotation;
-              }
-              else
-              {
-                new_annotation->former_annotation = NULL;
-                *annotslist = new_annotation;
-              }
             }
           }
 
@@ -606,7 +568,13 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
     }
   }
 
-  edfplus_annotation_sort(&annotslist[file_num]);
+  QApplication::setOverrideCursor(Qt::WaitCursor);
+
+  qApp->processEvents();
+
+  edfplus_annotation_sort(&edf_hdr->annot_list, &process_events);
+
+  QApplication::restoreOverrideCursor();
 
   progress.reset();
 
@@ -619,8 +587,6 @@ int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr,
 }
 
 
-
-
 int EDF_annotations::is_duration_number(char *str)
 {
   int i, l, hasdot = 0;
diff --git a/edf_annotations.h b/edf_annotations.h
index 458088e..ce4bcbc 100644
--- a/edf_annotations.h
+++ b/edf_annotations.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -54,8 +54,7 @@ class EDF_annotations
 
 public:
 
-  int get_annotations(int, struct edfhdrblock *, struct annotationblock **, int);
-
+  int get_annotations(struct edfhdrblock *, int);
 
 private:
 
@@ -65,7 +64,6 @@ private:
   long long get_long_time(char *);
 
   int check_device(char *);
-
 };
 
 
diff --git a/edf_annotations_new.cpp b/edf_annotations_new.cpp
deleted file mode 100644
index 0676588..0000000
--- a/edf_annotations_new.cpp
+++ /dev/null
@@ -1,769 +0,0 @@
-/*
-***************************************************************************
-*
-* Author: Teunis van Beelen
-*
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
-*
-* Email: teuniz at gmail.com
-*
-***************************************************************************
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*
-***************************************************************************
-*/
-
-
-
-#include "edf_annotations.h"
-
-
-
-int EDF_annotations::get_annotations(int file_num, struct edfhdrblock *edf_hdr, struct annotationblock **annotslist, int read_nk_trigger_signal)
-{
-  int i, j, k, p, r=0, n,
-      edfsignals,
-      datarecords,
-      recordsize,
-      discontinuous,
-      *annot_ch,
-      nr_annot_chns,
-      max,
-      onset,
-      duration,
-      duration_start,
-      zero,
-      max_tal_ln,
-      error,
-      annots_in_record,
-      annots_in_tal,
-      samplesize=2,
-      nk_triggers_smpls=0,
-      nk_triggers_bufoffset=0,
-      nk_triggers_enabled=0,
-      nk_triggers_channel=0,
-      nk_triggers_cnt=0,
-      sf,
-      progress_steps,
-      annotlist_sz=0,
-      annots_in_file=0;
-
-  unsigned short nk_triggerfields=0,
-                 nk_old_triggerfields=0;
-
-  char *scratchpad,
-       *cnv_buf,
-       *time_in_txt,
-       *duration_in_txt,
-       nk_triggerlabel[16][32];
-
-
-  long long data_record_duration,
-            elapsedtime,
-            time_tmp=0LL,
-            nk_trigger_sample_duration=0LL;
-
-  FILE *inputfile;
-
-  struct edfparamblock *edfparam;
-
-  struct annotationblock *new_annotation=NULL,
-                         *temp_annotation,
-                         *malloc_list;
-
-
-  inputfile = edf_hdr->file_hdl;
-  edfsignals = edf_hdr->edfsignals;
-  recordsize = edf_hdr->recordsize;
-  edfparam = edf_hdr->edfparam;
-  nr_annot_chns = edf_hdr->nr_annot_chns;
-  datarecords = edf_hdr->datarecords;
-  data_record_duration = edf_hdr->long_data_record_duration;
-  discontinuous = edf_hdr->discontinuous;
-  annot_ch = edf_hdr->annot_ch;
-
-  if(edf_hdr->edfplus)
-  {
-    samplesize = 2;
-  }
-  if(edf_hdr->bdfplus)
-  {
-    samplesize = 3;
-  }
-
-  if((edf_hdr->edfplus) && (read_nk_trigger_signal))
-  {
-    if(data_record_duration == 1000000LL)
-    {
-      if(check_device(edf_hdr->plus_equipment) == 0)
-      {
-        for(i=0; i<edfsignals; i++)
-        {
-          if(!strcmp(edfparam[i].label, "Events/Markers  "))
-          {
-            sf = edf_hdr->edfparam[i].smp_per_record;
-
-            error = 1;
-
-            switch(sf)
-            {
-              case  10 : error = 0;
-                         break;
-              case  20 : error = 0;
-                         break;
-              case  50 : error = 0;
-                         break;
-              case 100 : error = 0;
-                         break;
-            }
-
-            for(j=0; j<edfsignals; j++)
-            {
-              if(edf_hdr->edfparam[j].smp_per_record != sf)
-              {
-                if(!edf_hdr->edfparam[j].annotation)
-                {
-                  error = 1;
-                }
-              }
-            }
-
-            if(edf_hdr->nr_annot_chns != 1)  error = 1;
-
-            if(!error)
-            {
-              nk_triggers_channel = i;
-
-              nk_triggers_bufoffset = edfparam[nk_triggers_channel].buf_offset;
-
-              nk_triggers_smpls = edfparam[nk_triggers_channel].smp_per_record;
-
-              nk_trigger_sample_duration = data_record_duration / (long long)nk_triggers_smpls;
-
-              strcpy(nk_triggerlabel[0], "CAL mode");
-              strcpy(nk_triggerlabel[1], "RESET condition");
-              strcpy(nk_triggerlabel[2], "External mark");
-              strcpy(nk_triggerlabel[3], "Photo/HV mark");
-              strcpy(nk_triggerlabel[4], "Remote mark");
-              strcpy(nk_triggerlabel[5], "HV mark");
-              strcpy(nk_triggerlabel[6], "DC trigger 9");
-              strcpy(nk_triggerlabel[7], "DC trigger 10");
-              strcpy(nk_triggerlabel[8], "DC trigger 11");
-              strcpy(nk_triggerlabel[9], "DC trigger 12");
-              strcpy(nk_triggerlabel[10], "DC trigger 13");
-              strcpy(nk_triggerlabel[11], "DC trigger 14");
-              strcpy(nk_triggerlabel[12], "DC trigger 15");
-              strcpy(nk_triggerlabel[13], "DC trigger 16");
-              strcpy(nk_triggerlabel[14], "");
-              strcpy(nk_triggerlabel[15], "");
-
-              nk_triggers_enabled = 1;
-
-              edf_hdr->genuine_nk = 1;
-
-              break;
-            }
-          }
-        }
-      }
-    }
-  }
-
-  cnv_buf = (char *)calloc(1, recordsize);
-  if(cnv_buf==NULL)
-  {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "Memory allocation error occurred when trying to read annotations.\n(cnv_buf)");
-    messagewindow.exec();
-    return(1);
-  }
-
-  max_tal_ln = 0;
-
-  for(i=0; i<nr_annot_chns; i++)
-  {
-    if(max_tal_ln<edfparam[annot_ch[i]].smp_per_record * samplesize)  max_tal_ln = edfparam[annot_ch[i]].smp_per_record * samplesize;
-  }
-
-  if(max_tal_ln<128)  max_tal_ln = 128;
-
-  scratchpad = (char *)calloc(1, max_tal_ln + 3);
-  if(scratchpad==NULL)
-  {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "Memory allocation error occurred when trying to read annotations.\n(scratchpad)");
-    messagewindow.exec();
-    free(cnv_buf);
-    return(1);
-  }
-
-  time_in_txt = (char *)calloc(1, max_tal_ln + 3);
-  if(time_in_txt==NULL)
-  {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "Memory allocation error occurred when trying to read annotations.\n(time_in_txt)");
-    messagewindow.exec();
-    free(cnv_buf);
-    free(scratchpad);
-    return(1);
-  }
-
-  duration_in_txt = (char *)calloc(1, max_tal_ln + 3);
-  if(duration_in_txt==NULL)
-  {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "Memory allocation error occurred when trying to read annotations.\n(duration_in_txt)");
-    messagewindow.exec();
-    free(cnv_buf);
-    free(scratchpad);
-    free(time_in_txt);
-    return(1);
-  }
-
-  if(fseeko(inputfile, (long long)((edfsignals + 1) * 256), SEEK_SET))
-  {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred when reading inputfile annotations. (fseek())");
-    messagewindow.exec();
-    free(cnv_buf);
-    free(scratchpad);
-    free(time_in_txt);
-    free(duration_in_txt);
-    return(2);
-  }
-
-  QProgressDialog progress("Scanning file for annotations...", "Abort", 0, datarecords);
-  progress.setWindowModality(Qt::WindowModal);
-  progress.setMinimumDuration(200);
-
-  progress_steps = datarecords / 100;
-  if(progress_steps < 1)
-  {
-    progress_steps = 1;
-  }
-
-  elapsedtime = 0;
-
-  for(i=0; i<datarecords; i++)
-  {
-    if(!(i%progress_steps))
-    {
-      progress.setValue(i);
-
-      qApp->processEvents();
-
-      if(progress.wasCanceled() == true)
-      {
-        edf_hdr->annots_not_read = 1;
-
-        free(cnv_buf);
-        free(scratchpad);
-        free(time_in_txt);
-        free(duration_in_txt);
-        return(11);
-      }
-    }
-
-    if(fread(cnv_buf, recordsize, 1, inputfile)!=1)
-    {
-      progress.reset();
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred while reading inputfile annotations. (fread())");
-      messagewindow.exec();
-      free(cnv_buf);
-      free(scratchpad);
-      free(time_in_txt);
-      free(duration_in_txt);
-      return(2);
-    }
-
-
-/************** process annotationsignals (if any) **************/
-
-    error = 0;
-
-    for(r=0; r<nr_annot_chns; r++)
-    {
-      n = 0;
-      zero = 0;
-      onset = 0;
-      duration = 0;
-      duration_start = 0;
-      scratchpad[0] = 0;
-      annots_in_tal = 0;
-      annots_in_record = 0;
-
-      p = edfparam[annot_ch[r]].buf_offset;
-      max = edfparam[annot_ch[r]].smp_per_record * samplesize;
-
-/************** process one annotation signal ****************/
-
-      if(cnv_buf[p + max - 1]!=0)
-      {
-        error = 5;
-        goto END;
-      }
-
-      if(!r)  /* if it's the first annotation signal, then check */
-      {       /* the timekeeping annotation */
-        error = 1;
-
-        for(k=0; k<(max-2); k++)
-        {
-          scratchpad[k] = cnv_buf[p + k];
-
-          if(scratchpad[k]==20)
-          {
-            if(cnv_buf[p + k + 1]!=20)
-            {
-              error = 6;
-              goto END;
-            }
-            scratchpad[k] = 0;
-            if(is_onset_number(scratchpad))
-            {
-              error = 36;
-              goto END;
-            }
-            else
-            {
-              time_tmp = get_long_time(scratchpad);
-              if(i)
-              {
-                if(discontinuous)
-                {
-                  if((time_tmp-elapsedtime)<data_record_duration)
-                  {
-                    error = 4;
-                    goto END;
-                  }
-                }
-                else
-                {
-                  if((time_tmp-elapsedtime)!=data_record_duration)
-                  {
-                    error = 3;
-                    goto END;
-                  }
-                }
-              }
-              else
-              {
-                if(time_tmp>=TIME_DIMENSION)
-                {
-                  error = 2;
-                  goto END;
-                }
-                else
-                {
-                  edf_hdr->starttime_offset = time_tmp;
-                }
-              }
-              elapsedtime = time_tmp;
-              error = 0;
-              break;
-            }
-          }
-        }
-      }
-
-      for(k=0; k<max; k++)
-      {
-        scratchpad[n] = cnv_buf[p + k];
-
-        if(!scratchpad[n])
-        {
-          if(!zero)
-          {
-            if(k)
-            {
-              if(cnv_buf[p + k - 1]!=20)
-              {
-                error = 33;
-                goto END;
-              }
-            }
-            n = 0;
-            onset = 0;
-            duration = 0;
-            duration_start = 0;
-            scratchpad[0] = 0;
-            annots_in_tal = 0;
-          }
-          zero++;
-          continue;
-        }
-        if(zero>1)
-        {
-          error = 34;
-          goto END;
-        }
-        zero = 0;
-
-        if((scratchpad[n]==20)||(scratchpad[n]==21))
-        {
-          if(scratchpad[n]==21)
-          {
-            if(duration||duration_start||onset||annots_in_tal)
-            {               /* it's not allowed to have multiple duration fields */
-              error = 35;   /* in one TAL or to have a duration field which is   */
-              goto END;     /* not immediately behind the onsetfield             */
-            }
-            duration_start = 1;
-          }
-
-          if((scratchpad[n]==20)&&onset&&(!duration_start))
-          {
-            if(r||annots_in_record)
-            {
-              if(n >= 0)
-              {
-                if(annots_in_file >= annotlist_sz)
-                {
-                  malloc_list = (struct annotationblock *)realloc(*annotslist, sizeof(struct annotationblock) * (annotlist_sz + EDF_ANNOTS_MEMBLOCKSZ));
-                  if(malloc_list == NULL)
-                  {
-                    progress.reset();
-                    QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred while reading annotations.");
-                    messagewindow.exec();
-                    free(cnv_buf);
-                    free(scratchpad);
-                    free(time_in_txt);
-                    free(duration_in_txt);
-                    return(1);
-                  }
-
-                  memset(malloc_list + (sizeof(struct annotationblock) * annotlist_sz), 0, EDF_ANNOTS_MEMBLOCKSZ);
-
-                  annotlist_sz += EDF_ANNOTS_MEMBLOCKSZ;
-
-                  *annotslist = malloc_list;
-                }
-
-                ((*annotslist) + annots_in_file)->next_annotation = NULL;
-                ((*annotslist) + annots_in_file)->file_num = file_num;
-
-                ((*annotslist) + annots_in_file)->annotation[0] = 0;
-
-                if(duration)  strcpy(((*annotslist) + annots_in_file)->duration, duration_in_txt);
-                else  ((*annotslist) + annots_in_file)->duration[0] = 0;
-
-                for(j=0; j<n; j++)
-                {
-                  if(j==MAX_ANNOTATION_LEN)  break;
-                  ((*annotslist) + annots_in_file)->annotation[j] = scratchpad[j];
-                }
-                ((*annotslist) + annots_in_file)->annotation[j] = 0;
-
-                ((*annotslist) + annots_in_file)->file_num = edf_hdr->file_num;
-
-                ((*annotslist) + annots_in_file)->onset = get_long_time(time_in_txt);
-
-                if(annots_in_file > 0)
-                {
-                  ((*annotslist) + annots_in_file)->former_annotation = (*annotslist) + annots_in_file - 1;
-                  ((*annotslist) + annots_in_file - 1)->next_annotation = (*annotslist) + 1;
-                }
-                else
-                {
-                  ((*annotslist) + annots_in_file)->former_annotation = NULL;
-                }
-
-                annots_in_file++;
-              }
-            }
-
-            annots_in_tal++;
-            annots_in_record++;
-            n = 0;
-            continue;
-          }
-
-          if(!onset)
-          {
-            scratchpad[n] = 0;
-            if(is_onset_number(scratchpad))
-            {
-              error = 36;
-              goto END;
-            }
-            onset = 1;
-            n = 0;
-            strcpy(time_in_txt, scratchpad);
-            continue;
-          }
-
-          if(duration_start)
-          {
-            scratchpad[n] = 0;
-            if(is_duration_number(scratchpad))
-            {
-              error = 37;
-              goto END;
-            }
-
-            for(j=0; j<n; j++)
-            {
-              if(j==15)  break;
-              duration_in_txt[j] = scratchpad[j];
-              if((duration_in_txt[j]<32)||(duration_in_txt[j]>126))
-              {
-                duration_in_txt[j] = '.';
-              }
-            }
-            duration_in_txt[j] = 0;
-
-            duration = 1;
-            duration_start = 0;
-            n = 0;
-            continue;
-          }
-        }
-
-        n++;
-      }
-
- END:
-
-/****************** end ************************/
-
-      if(error)
-      {
-        progress.reset();
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not read annotations because there is an EDF or BDF incompatibility in this file.\n"
-                                                                  "For more information, run the EDF/BDF compatibility checker in the Tools menu.");
-        messagewindow.exec();
-        free(cnv_buf);
-        free(scratchpad);
-        free(time_in_txt);
-        free(duration_in_txt);
-        return(9);
-      }
-    }
-
-/************** process NK triggers ****************/
-
-    if(nk_triggers_enabled)
-    {
-      if(nk_triggers_cnt < 100000)
-      {
-        for(k=0; k<nk_triggers_smpls; k++)
-        {
-          nk_triggerfields = *((unsigned char *)cnv_buf + nk_triggers_bufoffset + (k * 2) + 1);
-
-          nk_triggerfields <<= 8;
-
-          nk_triggerfields += *((unsigned char *)cnv_buf + nk_triggers_bufoffset + (k * 2));
-
-          for(j=0; j<14; j++)
-          {
-            if((nk_triggerfields & (1 << j)) && (!(nk_old_triggerfields & (1 << j))))
-            {
-              nk_triggers_cnt++;
-
-              new_annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-              if(new_annotation==NULL)
-              {
-                progress.reset();
-                QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred while reading annotations.");
-                messagewindow.exec();
-                free(cnv_buf);
-                free(scratchpad);
-                free(time_in_txt);
-                free(duration_in_txt);
-                return(1);
-              }
-
-              new_annotation->file_num = edf_hdr->file_num;
-              new_annotation->next_annotation = NULL;
-              new_annotation->file_num = file_num;
-              strcpy(new_annotation->annotation, nk_triggerlabel[j]);
-
-              new_annotation->onset = ((long long)i * data_record_duration) + ((long long)k * nk_trigger_sample_duration);
-
-              new_annotation->onset += edf_hdr->starttime_offset;
-
-              new_annotation->ident = (1 << ANNOT_ID_NK_TRIGGER);
-
-              if(*annotslist!=NULL)
-              {
-                temp_annotation = *annotslist;
-                while(temp_annotation->next_annotation)  temp_annotation = temp_annotation->next_annotation;
-
-                new_annotation->former_annotation = temp_annotation;
-                temp_annotation->next_annotation = new_annotation;
-              }
-              else
-              {
-                new_annotation->former_annotation = NULL;
-                *annotslist = new_annotation;
-              }
-            }
-          }
-
-          nk_old_triggerfields = nk_triggerfields;
-        }
-      }
-
-      edf_hdr->nk_triggers_read = 1;
-    }
-  }
-
-  edfplus_annotation_sort(&annotslist[file_num]);
-
-  progress.reset();
-
-  free(cnv_buf);
-  free(scratchpad);
-  free(time_in_txt);
-  free(duration_in_txt);
-
-  return(0);
-}
-
-
-
-
-int EDF_annotations::is_duration_number(char *str)
-{
-  int i, l, hasdot = 0;
-
-  l = strlen(str);
-
-  if(!l)  return(1);
-
-  if((str[0] == '.')||(str[l-1] == '.'))  return(1);
-
-  for(i=0; i<l; i++)
-  {
-    if(str[i]=='.')
-    {
-      if(hasdot)  return(1);
-      hasdot++;
-    }
-    else
-    {
-      if((str[i]<48)||(str[i]>57))  return(1);
-    }
-  }
-
-  return(0);
-}
-
-
-
-int EDF_annotations::is_onset_number(char *str)
-{
-  int i, l, hasdot = 0;
-
-  l = strlen(str);
-
-  if(l<2)  return(1);
-
-  if((str[0]!='+')&&(str[0]!='-'))  return(1);
-
-  if((str[1] == '.')||(str[l-1] == '.'))  return(1);
-
-  for(i=1; i<l; i++)
-  {
-    if(str[i]=='.')
-    {
-      if(hasdot)  return(1);
-      hasdot++;
-    }
-    else
-    {
-      if((str[i]<48)||(str[i]>57))  return(1);
-    }
-  }
-
-  return(0);
-}
-
-
-
-long long EDF_annotations::get_long_time(char *str)
-{
-  int i, len, hasdot=0, dotposition=0;
-
-  long long value=0, radix;
-
-  str = str + 1;
-
-  len = strlen(str);
-
-  for(i=0; i<len; i++)
-  {
-    if(str[i]=='.')
-    {
-      hasdot = 1;
-      dotposition = i;
-      break;
-    }
-  }
-
-  if(hasdot)
-  {
-    radix = TIME_DIMENSION;
-
-    for(i=dotposition-1; i>=0; i--)
-    {
-        value += ((long long)(str[i] - 48)) * radix;
-        radix *= 10;
-    }
-
-    radix = TIME_DIMENSION / 10;
-
-    for(i=dotposition+1; i<len; i++)
-    {
-        value += ((long long)(str[i] - 48)) * radix;
-        radix /= 10;
-    }
-  }
-  else
-  {
-    radix = TIME_DIMENSION;
-
-    for(i=len-1; i>=0; i--)
-    {
-        value += ((long long)(str[i] - 48)) * radix;
-        radix *= 10;
-    }
-  }
-
-  if(str[-1]=='-')  value = -value;
-
-  return(value);
-}
-
-
-int EDF_annotations::check_device(char *str)
-{
-  int error = 1;
-
-  if(strlen(str) < 29)  return(1);
-
-  if(!strncmp(str, "Nihon Kohden EEG-1100A V01.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden EEG-1100B V01.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden EEG-1100C V01.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden QI-403A   V01.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden QI-403A   V02.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden EEG-2100  V01.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden EEG-2100  V02.00", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden DAE-2100D V01.30", 29))  error = 0;
-  if(!strncmp(str, "Nihon Kohden DAE-2100D V02.00", 29))  error = 0;
-//  if(!strncmp(str, "Nihon Kohden EEG-1200A V01.00", 29))  error = 0;
-
-  return(error);
-}
-
-
-
-
-
diff --git a/edf_compat.cpp b/edf_compat.cpp
index af0140d..f946773 100644
--- a/edf_compat.cpp
+++ b/edf_compat.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/edf_compat.h b/edf_compat.h
index 878365f..da69d5b 100644
--- a/edf_compat.h
+++ b/edf_compat.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/edf_helper.c b/edf_helper.c
new file mode 100644
index 0000000..75591af
--- /dev/null
+++ b/edf_helper.c
@@ -0,0 +1,113 @@
+/*
+***************************************************************************
+*
+* Author: Teunis van Beelen
+*
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
+*
+* Email: teuniz at gmail.com
+*
+***************************************************************************
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*
+***************************************************************************
+*/
+
+
+
+#include "edf_helper.h"
+
+
+
+int edfplus_annotation_get_tal_timestamp_digit_cnt(struct edfhdrblock *hdr)
+{
+  int timestamp_digits;
+
+  char scratchpad[256];
+
+  long long time;
+
+
+  if(hdr==NULL)
+  {
+    return(-1);
+  }
+
+  time = (hdr->datarecords * hdr->long_data_record_duration) / TIME_DIMENSION;
+
+#ifdef _WIN32
+  timestamp_digits = __mingw_snprintf(scratchpad, 256, "%lli", time);
+#else
+  timestamp_digits = snprintf(scratchpad, 256, "%lli", time);
+#endif
+
+  return(timestamp_digits);
+}
+
+
+int edfplus_annotation_get_tal_timestamp_decimal_cnt(struct edfhdrblock *hdr)
+{
+  int i, j,
+      timestamp_decimals;
+
+
+  if(hdr==NULL)
+  {
+    return(-1);
+  }
+
+  j = 10;
+
+  for(timestamp_decimals=7; timestamp_decimals>0; timestamp_decimals--)
+  {
+    if(hdr->long_data_record_duration % j)
+    {
+      break;
+    }
+
+    j *= 10;
+  }
+
+  if((hdr->edfplus==1)||(hdr->bdfplus==1))
+  {
+    j = 10;
+
+    for(i=7; i>0; i--)
+    {
+      if(hdr->starttime_offset % j)
+      {
+        break;
+      }
+
+      j *= 10;
+    }
+
+    if(i > timestamp_decimals)
+    {
+      timestamp_decimals = i;
+    }
+  }
+
+  return(timestamp_decimals);
+}
+
+
+
+
+
+
+
+
+
diff --git a/date_time_stamp_parser.h b/edf_helper.h
similarity index 75%
copy from date_time_stamp_parser.h
copy to edf_helper.h
index 81af8f0..6a282c8 100644
--- a/date_time_stamp_parser.h
+++ b/edf_helper.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -26,18 +26,22 @@
 */
 
 
+#ifndef EDFPLUS_HELPER_H
+#define EDFPLUS_HELPER_H
 
 
-#ifndef DATE_TIME_STAMP_PARSER_INCLUDED
-#define DATE_TIME_STAMP_PARSER_INCLUDED
+#include <stdlib.h>
+#include <string.h>
+
+#include "global.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
-long long parse_date_time_stamp(const char *);
+int edfplus_annotation_get_tal_timestamp_digit_cnt(struct edfhdrblock *);
+int edfplus_annotation_get_tal_timestamp_decimal_cnt(struct edfhdrblock *);
 
 
 #ifdef __cplusplus
@@ -48,3 +52,5 @@ long long parse_date_time_stamp(const char *);
 
 
 
+
+
diff --git a/edfbrowser.pro b/edfbrowser.pro
index 532110a..082270a 100644
--- a/edfbrowser.pro
+++ b/edfbrowser.pro
@@ -126,6 +126,7 @@ HEADERS += spike_filter.h
 HEADERS += spike_filter_dialog.h
 HEADERS += mit2edf.h
 HEADERS += biox2edf.h
+HEADERS += edf_helper.h
 
 HEADERS += third_party/fidlib/fidlib.h
 HEADERS += third_party/fidlib/fidmkf.h
@@ -215,6 +216,7 @@ SOURCES += spike_filter.cpp
 SOURCES += spike_filter_dialog.cpp
 SOURCES += mit2edf.cpp
 SOURCES += biox2edf.cpp
+SOURCES += edf_helper.c
 
 SOURCES += third_party/fidlib/fidlib.c
 
diff --git a/edflib.c b/edflib.c
index f099744..eb76896 100644
--- a/edflib.c
+++ b/edflib.c
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 * All rights reserved.
 *
 * email: teuniz at gmail.com
diff --git a/edflib.h b/edflib.h
index 2592323..2b28798 100644
--- a/edflib.h
+++ b/edflib.h
@@ -1,7 +1,7 @@
 /*
 *****************************************************************************
 *
-* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 * All rights reserved.
 *
 * email: teuniz at gmail.com
diff --git a/edfplusd_cnv.cpp b/edfplusd_cnv.cpp
index 99ebc16..ea09601 100644
--- a/edfplusd_cnv.cpp
+++ b/edfplusd_cnv.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -75,7 +75,7 @@ void UI_EDFDwindow::SelectFileButton()
   FILE *inputfile=NULL,
        *outputfile=NULL;
 
-  int i,
+  int i, j,
       file_number,
       offset,
       offset_2,
@@ -89,7 +89,8 @@ void UI_EDFDwindow::SelectFileButton()
       annot_signal_nr_2,
       annots_written,
       len,
-      progress_steps;
+      progress_steps,
+      annot_list_size;
 
   long long former_timestamp,
             next_timestamp,
@@ -104,8 +105,7 @@ void UI_EDFDwindow::SelectFileButton()
        *readbuf,
        *tal;
 
-  struct annotationblock *annotationlist[1],
-                         *annotblock;
+  struct annotationblock *annot_ptr;
 
   struct edfhdrblock *edfhdr=NULL;
 
@@ -163,11 +163,9 @@ void UI_EDFDwindow::SelectFileButton()
 
   EDF_annotations annotations_func;
 
-  annotationlist[0] = NULL;
-
-  if(annotations_func.get_annotations(0, edfhdr, &annotationlist[0], 0))
+  if(annotations_func.get_annotations(edfhdr, 0))
   {
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
@@ -178,7 +176,7 @@ void UI_EDFDwindow::SelectFileButton()
 
   if(edfhdr->annots_not_read)
   {
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
@@ -187,7 +185,7 @@ void UI_EDFDwindow::SelectFileButton()
     return;
   }
 
-  annotblock = annotationlist[0];
+  annot_list_size = edfplus_annotation_size(&edfhdr->annot_list);
 
 /***************** start conversion ******************************/
 
@@ -210,7 +208,7 @@ void UI_EDFDwindow::SelectFileButton()
   if(fileheader==NULL)
   {
     textEdit1->append("Malloc error, (fileheader).\n");
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
@@ -222,7 +220,7 @@ void UI_EDFDwindow::SelectFileButton()
   if(readbuf==NULL)
   {
     textEdit1->append("Malloc error, (readbuf).\n");
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     free(fileheader);
@@ -235,7 +233,7 @@ void UI_EDFDwindow::SelectFileButton()
   if(fread(fileheader, edfhdr->hdrsize, 1, inputfile) != 1)
   {
     textEdit1->append("Read error.\n");
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     free(fileheader);
@@ -269,7 +267,7 @@ void UI_EDFDwindow::SelectFileButton()
   if(outputfile==NULL)
   {
     textEdit1->append("Error, can not open outputfile for writing.\n");
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     free(fileheader);
@@ -282,7 +280,7 @@ void UI_EDFDwindow::SelectFileButton()
   if(fwrite(fileheader, edfhdr->hdrsize, 1, outputfile) != 1)
   {
     textEdit1->append("Write error.\n");
-    free_annotations(annotationlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     free(fileheader);
@@ -339,7 +337,7 @@ void UI_EDFDwindow::SelectFileButton()
     {
       progress.reset();
       textEdit1->append("Read error.\n");
-      free_annotations(annotationlist[0]);
+      edfplus_annotation_empty_list(&edfhdr->annot_list);
       free(edfhdr->edfparam);
       free(edfhdr);
       free(fileheader);
@@ -384,80 +382,75 @@ void UI_EDFDwindow::SelectFileButton()
 
       write_values_to_hdr(outputfile, new_hdr_timestamp, datarecords_written, edfhdr);
 
-      annotblock = annotationlist[0];
-
       annots_written = 0;
 
-      if(annotblock!=NULL)
+      for(j=0; j<annot_list_size; j++)
       {
-        while(annotblock!=NULL)
+        annot_ptr = edfplus_annotation_get_item(&edfhdr->annot_list, j);
+
+        if(((annot_ptr->onset>=chunk_starttime)||(file_number==1))
+           &&(annot_ptr->onset<chunk_endtime)
+           &&(annots_written<datarecords_written))
         {
-          if(((annotblock->onset>=chunk_starttime)||(file_number==1))
-             &&(annotblock->onset<chunk_endtime)
-             &&(annots_written<datarecords_written))
-          {
-            fseeko(outputfile, (long long)(edfhdr->hdrsize + (annots_written * edfhdr->recordsize) + offset), SEEK_SET);
+          fseeko(outputfile, (long long)(edfhdr->hdrsize + (annots_written * edfhdr->recordsize) + offset), SEEK_SET);
 
-            for(cnt=1; ; cnt++)
-            {
-              if(fgetc(outputfile)==0)  break;
-            }
+          for(cnt=1; ; cnt++)
+          {
+            if(fgetc(outputfile)==0)  break;
+          }
 
-            fseeko(outputfile, 0LL, SEEK_CUR);
+          fseeko(outputfile, 0LL, SEEK_CUR);
 
-            cnt += fprintf(outputfile, "+%i", (int)((annotblock->onset - new_hdr_timestamp) / TIME_DIMENSION));
+          cnt += fprintf(outputfile, "+%i", (int)((annot_ptr->onset - new_hdr_timestamp) / TIME_DIMENSION));
 
-            if(annotblock->onset%TIME_DIMENSION)
-            {
-              cnt += fprintf(outputfile, ".%07i", (int)((annotblock->onset - new_hdr_timestamp) % TIME_DIMENSION));
+          if(annot_ptr->onset%TIME_DIMENSION)
+          {
+            cnt += fprintf(outputfile, ".%07i", (int)((annot_ptr->onset - new_hdr_timestamp) % TIME_DIMENSION));
 
-              fseeko(outputfile, -1LL, SEEK_CUR);
+            fseeko(outputfile, -1LL, SEEK_CUR);
 
-              while(fgetc(outputfile)=='0')
-              {
-                fseeko(outputfile, -2LL, SEEK_CUR);
+            while(fgetc(outputfile)=='0')
+            {
+              fseeko(outputfile, -2LL, SEEK_CUR);
 
-                cnt--;
-              }
+              cnt--;
             }
+          }
 
-            fseeko(outputfile, 0LL, SEEK_CUR);
+          fseeko(outputfile, 0LL, SEEK_CUR);
 
-            if(annotblock->duration[0]!=0)
-            {
-              fputc(21, outputfile);
+          if(annot_ptr->duration[0]!=0)
+          {
+            fputc(21, outputfile);
 
-              cnt++;
+            cnt++;
 
-              cnt += fprintf(outputfile, "%s", annotblock->duration);
-            }
+            cnt += fprintf(outputfile, "%s", annot_ptr->duration);
+          }
 
-            fputc(20, outputfile);
+          fputc(20, outputfile);
 
-            cnt++;
-
-            for(i = 0; i < (annot_signal_size - cnt - 2); i++)
-            {
-             if(annotblock->annotation[i]==0)  break;
+          cnt++;
 
-             fputc(annotblock->annotation[i], outputfile);
+          for(i = 0; i < (annot_signal_size - cnt - 2); i++)
+          {
+           if(annot_ptr->annotation[i]==0)  break;
 
-             cnt++;
-            }
+           fputc(annot_ptr->annotation[i], outputfile);
 
-            fputc(20, outputfile);
+           cnt++;
+          }
 
-            cnt++;
+          fputc(20, outputfile);
 
-            for(i = cnt; i < annot_signal_size; i++)
-            {
-              fputc(0, outputfile);
-            }
+          cnt++;
 
-            annots_written++;
+          for(i = cnt; i < annot_signal_size; i++)
+          {
+            fputc(0, outputfile);
           }
 
-          annotblock = annotblock->next_annotation;
+          annots_written++;
         }
       }
 
@@ -494,7 +487,7 @@ void UI_EDFDwindow::SelectFileButton()
       {
         progress.reset();
         textEdit1->append("Error, can not open outputfile for writing.\n");
-        free_annotations(annotationlist[0]);
+        edfplus_annotation_empty_list(&edfhdr->annot_list);
         free(edfhdr->edfparam);
         free(edfhdr);
         free(fileheader);
@@ -508,7 +501,7 @@ void UI_EDFDwindow::SelectFileButton()
       {
         progress.reset();
         textEdit1->append("Write error.\n");
-        free_annotations(annotationlist[0]);
+        edfplus_annotation_empty_list(&edfhdr->annot_list);
         free(edfhdr->edfparam);
         free(edfhdr);
         free(fileheader);
@@ -546,7 +539,7 @@ void UI_EDFDwindow::SelectFileButton()
     {
       progress.reset();
       textEdit1->append("Write error.\n");
-      free_annotations(annotationlist[0]);
+      edfplus_annotation_empty_list(&edfhdr->annot_list);
       free(edfhdr->edfparam);
       free(edfhdr);
       free(fileheader);
@@ -564,82 +557,77 @@ void UI_EDFDwindow::SelectFileButton()
 
   write_values_to_hdr(outputfile, new_hdr_timestamp, datarecords_written, edfhdr);
 
-  annotblock = annotationlist[0];
-
   annots_written = 0;
 
-  if(annotblock!=NULL)
+  for(j=0; j<annot_list_size; j++)
   {
-    while(annotblock!=NULL)
-    {
-      if((annotblock->onset>=chunk_starttime)&&(annots_written<datarecords_written))
-      {
-        fseeko(outputfile, (long long)(edfhdr->hdrsize + (annots_written * edfhdr->recordsize) + offset), SEEK_SET);
-
-        for(cnt=1; ; cnt++)
-        {
-          if(fgetc(outputfile)==0)  break;
-        }
+    annot_ptr = edfplus_annotation_get_item(&edfhdr->annot_list, j);
 
-        fseeko(outputfile, 0LL, SEEK_CUR);
+    if((annot_ptr->onset>=chunk_starttime)&&(annots_written<datarecords_written))
+    {
+      fseeko(outputfile, (long long)(edfhdr->hdrsize + (annots_written * edfhdr->recordsize) + offset), SEEK_SET);
 
-        cnt += fprintf(outputfile, "+%i", (int)((annotblock->onset - new_hdr_timestamp) / TIME_DIMENSION));
+      for(cnt=1; ; cnt++)
+      {
+        if(fgetc(outputfile)==0)  break;
+      }
 
-        if(annotblock->onset%TIME_DIMENSION)
-        {
-          cnt += fprintf(outputfile, ".%07i", (int)((annotblock->onset - new_hdr_timestamp) % TIME_DIMENSION));
+      fseeko(outputfile, 0LL, SEEK_CUR);
 
-          fseeko(outputfile, -1LL, SEEK_CUR);
+      cnt += fprintf(outputfile, "+%i", (int)((annot_ptr->onset - new_hdr_timestamp) / TIME_DIMENSION));
 
-          while(fgetc(outputfile)=='0')
-          {
-            fseeko(outputfile, -2LL, SEEK_CUR);
-
-            cnt--;
-          }
-        }
+      if(annot_ptr->onset%TIME_DIMENSION)
+      {
+        cnt += fprintf(outputfile, ".%07i", (int)((annot_ptr->onset - new_hdr_timestamp) % TIME_DIMENSION));
 
-        fseeko(outputfile, 0LL, SEEK_CUR);
+        fseeko(outputfile, -1LL, SEEK_CUR);
 
-        if(annotblock->duration[0]!=0)
+        while(fgetc(outputfile)=='0')
         {
-          fputc(21, outputfile);
+          fseeko(outputfile, -2LL, SEEK_CUR);
 
-          cnt++;
-
-          cnt += fprintf(outputfile, "%s", annotblock->duration);
+          cnt--;
         }
+      }
 
-        fputc(20, outputfile);
+      fseeko(outputfile, 0LL, SEEK_CUR);
+
+      if(annot_ptr->duration[0]!=0)
+      {
+        fputc(21, outputfile);
 
         cnt++;
 
-        for(i = 0; i < (annot_signal_size - cnt - 2); i++)
-        {
-          if(annotblock->annotation[i]==0)  break;
+        cnt += fprintf(outputfile, "%s", annot_ptr->duration);
+      }
 
-          fputc(annotblock->annotation[i], outputfile);
+      fputc(20, outputfile);
 
-          cnt++;
-        }
+      cnt++;
 
-        fputc(20, outputfile);
+      for(i = 0; i < (annot_signal_size - cnt - 2); i++)
+      {
+        if(annot_ptr->annotation[i]==0)  break;
+
+        fputc(annot_ptr->annotation[i], outputfile);
 
         cnt++;
+      }
 
-        for(i = cnt; i < annot_signal_size; i++)
-        {
-          fputc(0, outputfile);
-        }
+      fputc(20, outputfile);
 
-        annots_written++;
+      cnt++;
+
+      for(i = cnt; i < annot_signal_size; i++)
+      {
+        fputc(0, outputfile);
       }
 
-      annotblock = annotblock->next_annotation;
+      annots_written++;
     }
   }
 
-  free_annotations(annotationlist[0]);
+  edfplus_annotation_empty_list(&edfhdr->annot_list);
   free(edfhdr->edfparam);
   free(edfhdr);
   free(fileheader);
@@ -763,22 +751,6 @@ long long UI_EDFDwindow::get_datarecord_timestamp(char *str)
 
 
 
-void UI_EDFDwindow::free_annotations(struct annotationblock *annot)
-{
-  if(annot==NULL)
-  {
-    return;
-  }
-
-  while(annot->next_annotation)
-  {
-    annot = annot->next_annotation;
-
-    free(annot->former_annotation);
-  }
-
-  free(annot);
-}
 
 
 
diff --git a/edfplusd_cnv.h b/edfplusd_cnv.h
index 1022919..dcb0bdc 100644
--- a/edfplusd_cnv.h
+++ b/edfplusd_cnv.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -54,6 +54,7 @@
 #include "check_edf_file.h"
 #include "edf_annotations.h"
 #include "utils.h"
+#include "edf_annot_list.h"
 
 
 
@@ -80,7 +81,6 @@ char *recent_opendir,
 
 long long get_datarecord_timestamp(char *);
 void write_values_to_hdr(FILE *, long long, int, struct edfhdrblock *);
-void free_annotations(struct annotationblock *);
 
 private slots:
 
diff --git a/edit_annotation_dock.cpp b/edit_annotation_dock.cpp
index 0abe71e..35aada9 100644
--- a/edit_annotation_dock.cpp
+++ b/edit_annotation_dock.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -31,13 +31,11 @@
 
 
 
-UI_AnnotationEditwindow::UI_AnnotationEditwindow(int file_number, QWidget *w_parent)
+UI_AnnotationEditwindow::UI_AnnotationEditwindow(QWidget *w_parent)
 {
   mainwindow = (UI_Mainwindow *)w_parent;
 
-  file_num = file_number;
-
-  annotation = mainwindow->annotationlist[file_num];
+  file_num = 0;
 
   dockedit = new QDockWidget("Annotation editor", w_parent);
   dockedit->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
@@ -120,7 +118,7 @@ void UI_AnnotationEditwindow::open_close_dock(bool visible)
 
     if(mainwindow->annotationlist_backup==NULL)
     {
-      mainwindow->annotationlist_backup = edfplus_annotation_copy_list(&mainwindow->annotationlist[0]);
+      mainwindow->annotationlist_backup = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[0]->annot_list);
     }
   }
   else
@@ -137,37 +135,35 @@ void UI_AnnotationEditwindow::open_close_dock(bool visible)
 
 void UI_AnnotationEditwindow::modifyButtonClicked()
 {
-  annotation = edfplus_annotation_item(&mainwindow->annotationlist[file_num], annot_num);
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot = edfplus_annotation_get_item(annot_list, annot_num);
 
-  annotation->onset =  onset_daySpinbox->value() * 86400 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().hour() * 3600 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().minute() * 60 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().second() * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().msec() * (TIME_DIMENSION / 1000);
+  annot->onset = annotEditGetOnset();
 
   if(posNegTimebox->currentIndex() == 1)
   {
-    annotation->onset = -(annotation->onset);
+    annot->onset = -(annot->onset);
   }
 
-  annotation->onset += mainwindow->edfheaderlist[file_num]->starttime_offset;
+  annot->onset += mainwindow->edfheaderlist[file_num]->starttime_offset;
 
   if(duration_spinbox->value()>0.0)
   {
-    snprintf(annotation->duration, 16, "%f", duration_spinbox->value());
+    snprintf(annot->duration, 16, "%f", duration_spinbox->value());
   }
   else
   {
-    annotation->duration[0] = 0;
+    annot->duration[0] = 0;
   }
 
-  strncpy(annotation->annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);
+  strncpy(annot->annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);
 
-  annotation->annotation[MAX_ANNOTATION_LEN] = 0;
+  annot->annotation[MAX_ANNOTATION_LEN] = 0;
 
-  annotation->modified = 1;
+  annot->modified = 1;
 
-  annotation->selected = 1;
+  annot->selected = 1;
 
   mainwindow->annotations_edited = 1;
 
@@ -180,15 +176,21 @@ void UI_AnnotationEditwindow::modifyButtonClicked()
 
 void UI_AnnotationEditwindow::deleteButtonClicked()
 {
-  edfplus_annotation_delete(&mainwindow->annotationlist[file_num], annot_num);
+  int sz;
+
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot = edfplus_annotation_get_item(annot_list, annot_num);
+
+  edfplus_annotation_remove_item(annot_list, annot_num);
 
-  annotation = edfplus_annotation_item(&mainwindow->annotationlist[file_num], annot_num);
+  sz = edfplus_annotation_size(annot_list);
 
-  if(annotation!=NULL)
+  if(annot_num < sz)
   {
-    annotation->selected = 1;
+    annot->selected = 1;
 
-    annotation->jump = 1;
+    annot->jump = 1;
   }
 
   modifybutton->setEnabled(false);
@@ -208,39 +210,39 @@ void UI_AnnotationEditwindow::deleteButtonClicked()
 
 void UI_AnnotationEditwindow::createButtonClicked()
 {
-  annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-  annotation->onset =  onset_daySpinbox->value() * 86400 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().hour() * 3600 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().minute() * 60 * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().second() * TIME_DIMENSION;
-  annotation->onset += onset_timeEdit->time().msec() * (TIME_DIMENSION / 1000);
+  struct annotationblock annotation;
+
+  memset(&annotation, 0, sizeof(struct annotationblock));
+
+  annotation.onset = annotEditGetOnset();
 
   if(posNegTimebox->currentIndex() == 1)
   {
-    annotation->onset = -(annotation->onset);
+    annotation.onset = -(annotation.onset);
   }
 
-  annotation->onset += mainwindow->edfheaderlist[file_num]->starttime_offset;
+  annotation.onset += mainwindow->edfheaderlist[file_num]->starttime_offset;
 
-  annotation->file_num = file_num;
+  annotation.file_num = file_num;
 
   if(duration_spinbox->value()>0.0)
   {
-    snprintf(annotation->duration, 16, "%f", duration_spinbox->value());
+    snprintf(annotation.duration, 16, "%f", duration_spinbox->value());
   }
   else
   {
-    annotation->duration[0] = 0;
+    annotation.duration[0] = 0;
   }
 
-  strncpy(annotation->annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);
+  strncpy(annotation.annotation, annot_descript_lineEdit->text().toUtf8().data(), MAX_ANNOTATION_LEN);
 
-  annotation->annotation[MAX_ANNOTATION_LEN] = 0;
+  annotation.annotation[MAX_ANNOTATION_LEN] = 0;
 
-  annotation->modified = 1;
+  annotation.modified = 1;
 
-  edfplus_annotation_add_item(&mainwindow->annotationlist[file_num], annotation);
+  edfplus_annotation_add_item(annot_list, annotation);
 
   mainwindow->annotations_edited = 1;
 
@@ -283,14 +285,30 @@ void UI_AnnotationEditwindow::annotEditSetOnset(long long onset)
 
 
 
-void UI_AnnotationEditwindow::annotEditSetDuration(long long duration)
+long long UI_AnnotationEditwindow::annotEditGetOnset(void)
 {
-  double tmp;
+  long long tmp;
 
-  tmp = duration;
-  tmp /= TIME_DIMENSION;
+  tmp = onset_daySpinbox->value() * 86400;
+  tmp += onset_timeEdit->time().hour() * 3600;
+  tmp += onset_timeEdit->time().minute() * 60;
+  tmp += onset_timeEdit->time().second();
+  tmp *= TIME_DIMENSION;
+  tmp += (onset_timeEdit->time().msec() * (TIME_DIMENSION / 1000));
 
-  duration_spinbox->setValue(tmp);
+  if(posNegTimebox->currentIndex() == 1)
+  {
+    tmp *= -1LL;
+  }
+
+  return tmp;
+}
+
+
+
+void UI_AnnotationEditwindow::annotEditSetDuration(long long duration)
+{
+  duration_spinbox->setValue(((double)duration) / TIME_DIMENSION);
 }
 
 
@@ -306,11 +324,15 @@ void UI_AnnotationEditwindow::set_selected_annotation(int file_nr, int annot_nr)
 
   annot_num = annot_nr;
 
-  annotation = edfplus_annotation_item(&mainwindow->annotationlist[file_num], annot_num);
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
+
+  struct annotationblock *annot = edfplus_annotation_get_item(annot_list, annot_num);
+
+  annot = edfplus_annotation_get_item(annot_list, annot_num);
 
-  annot_descript_lineEdit->setText(QString::fromUtf8(annotation->annotation));
+  annot_descript_lineEdit->setText(QString::fromUtf8(annot->annotation));
 
-  l_tmp = annotation->onset - mainwindow->edfheaderlist[annotation->file_num]->starttime_offset;
+  l_tmp = annot->onset - mainwindow->edfheaderlist[annot->file_num]->starttime_offset;
 
   if(l_tmp < 0LL)
   {
@@ -336,9 +358,9 @@ void UI_AnnotationEditwindow::set_selected_annotation(int file_nr, int annot_nr)
   }
   onset_timeEdit->setTime(ta);
 
-  if(strlen(annotation->duration))
+  if(strlen(annot->duration))
   {
-    duration_spinbox->setValue(atof(annotation->duration));
+    duration_spinbox->setValue(atof(annot->duration));
   }
   else
   {
@@ -351,21 +373,27 @@ void UI_AnnotationEditwindow::set_selected_annotation(int file_nr, int annot_nr)
 }
 
 
-
-
 void UI_AnnotationEditwindow::set_selected_annotation(struct annotationblock *annot)
 {
+  int n;
+
   long long l_tmp;
 
   QTime ta;
 
-  annotation = annot;
+  struct annotation_list *annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
   file_num = annot->file_num;
 
-  annot_descript_lineEdit->setText(QString::fromUtf8(annotation->annotation));
+  n = edfplus_annotation_get_index(annot_list, annot);
+
+  if(n < 0)  return;
+
+  annot_num = n;
+
+  annot_descript_lineEdit->setText(QString::fromUtf8(annot->annotation));
 
-  l_tmp = annotation->onset - mainwindow->edfheaderlist[annotation->file_num]->starttime_offset;
+  l_tmp = annot->onset - mainwindow->edfheaderlist[annot->file_num]->starttime_offset;
 
   if(l_tmp < 0LL)
   {
@@ -391,9 +419,9 @@ void UI_AnnotationEditwindow::set_selected_annotation(struct annotationblock *an
   }
   onset_timeEdit->setTime(ta);
 
-  if(strlen(annotation->duration))
+  if(strlen(annot->duration))
   {
-    duration_spinbox->setValue(atof(annotation->duration));
+    duration_spinbox->setValue(atof(annot->duration));
   }
   else
   {
@@ -418,3 +446,11 @@ void UI_AnnotationEditwindow::set_selected_annotation(struct annotationblock *an
 
 
 
+
+
+
+
+
+
+
+
diff --git a/edit_annotation_dock.h b/edit_annotation_dock.h
index b475df7..ffacb35 100644
--- a/edit_annotation_dock.h
+++ b/edit_annotation_dock.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -71,7 +71,7 @@ class UI_AnnotationEditwindow : public QObject
   Q_OBJECT
 
 public:
-  UI_AnnotationEditwindow(int, QWidget *parent);
+  UI_AnnotationEditwindow(QWidget *parent);
 
   UI_Mainwindow *mainwindow;
 
@@ -79,6 +79,8 @@ public:
 
   void annotEditSetOnset(long long);
 
+  long long annotEditGetOnset(void);
+
   void annotEditSetDuration(long long);
 
   void set_selected_annotation(int, int);
@@ -87,8 +89,6 @@ public:
 
 private:
 
-  struct annotationblock *annotation;
-
   int file_num,
       annot_num;
 
diff --git a/edit_predefined_mtg.cpp b/edit_predefined_mtg.cpp
index b7ca8ab..6dd3ec3 100644
--- a/edit_predefined_mtg.cpp
+++ b/edit_predefined_mtg.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/edit_predefined_mtg.h b/edit_predefined_mtg.h
index 0304c4a..973c158 100644
--- a/edit_predefined_mtg.h
+++ b/edit_predefined_mtg.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/emsa2edf.cpp b/emsa2edf.cpp
index c3f04f9..b4d03b0 100644
--- a/emsa2edf.cpp
+++ b/emsa2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/emsa2edf.h b/emsa2edf.h
index 6d0c647..dbce34c 100644
--- a/emsa2edf.h
+++ b/emsa2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/export_annotations.cpp b/export_annotations.cpp
index 7eab9ec..b94408e 100644
--- a/export_annotations.cpp
+++ b/export_annotations.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -90,6 +90,7 @@ UI_ExportAnnotationswindow::UI_ExportAnnotationswindow(QWidget *w_parent)
   separatorBox = new QComboBox(ExportAnnotsDialog);
   separatorBox->addItem("comma");
   separatorBox->addItem("tab");
+  separatorBox->addItem("semicolon");
 
   asciiSecondsRadioButton = new QRadioButton("seconds relative to start of file");
   asciiSecondsRadioButton->setChecked(true);
@@ -215,7 +216,9 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
   FILE *annotationfile=NULL;
 
-  struct annotationblock *annot, *annot_list;
+  struct annotation_list *annot_list;
+
+  struct annotationblock *annot;
 
   struct edfhdrblock *hdr;
 
@@ -260,18 +263,23 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
     csv_format = 8;
   }
 
-   mainwindow->export_annotations_var->format = csv_format;
+  mainwindow->export_annotations_var->format = csv_format;
 
   if(separatorBox->currentIndex() == 0)
   {
     separator = ',';
     mainwindow->export_annotations_var->separator = 0;
   }
-  else
+  else if(separatorBox->currentIndex() == 1)
   {
     separator = '\t';
     mainwindow->export_annotations_var->separator = 1;
   }
+  else
+  {
+    separator = ';';
+    mainwindow->export_annotations_var->separator = 2;
+  }
 
   if(durationCheckBox->checkState() == Qt::Checked)
   {
@@ -367,7 +375,7 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
     return;
   }
 
-  annot_list = edfplus_annotation_copy_list(&mainwindow->annotationlist[n]);
+  annot_list = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[n]->annot_list);
 
   if(mergeRadioButton->isChecked() == true)
   {
@@ -375,23 +383,23 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
     {
       if(i != mainwindow->sel_viewtime)
       {
-        annot_cnt = edfplus_annotation_count(&mainwindow->annotationlist[i]);
+        annot_cnt = edfplus_annotation_size(&mainwindow->edfheaderlist[i]->annot_list);
 
         for(j=0; j < annot_cnt; j++)
         {
-          edfplus_annotation_add_copy(&annot_list, edfplus_annotation_item(&mainwindow->annotationlist[i], j));
+          edfplus_annotation_add_item(annot_list, *(edfplus_annotation_get_item(&mainwindow->edfheaderlist[i]->annot_list, j)));
 
-          annot = edfplus_annotation_item(&annot_list, edfplus_annotation_count(&annot_list) - 1);
+          annot = edfplus_annotation_get_item(annot_list, edfplus_annotation_size(annot_list) - 1);
 
           annot->onset -= (mainwindow->edfheaderlist[i]->viewtime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->viewtime);
         }
       }
     }
 
-    edfplus_annotation_sort(&annot_list);
+    edfplus_annotation_sort(annot_list, NULL);
   }
 
-  annot_cnt = edfplus_annotation_count(&annot_list);
+  annot_cnt = edfplus_annotation_size(annot_list);
 
 ///////////////////////////// CSV (text) export //////////////////////////////////////
 
@@ -403,7 +411,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open annotationfile for writing.");
       messagewindow.exec();
       ExportAnnotsDialog->close();
-      edfplus_annotation_delete_list(&annot_list);
+      edfplus_annotation_empty_list(annot_list);
+      free(annot_list);
       return;
     }
 
@@ -416,9 +425,9 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
       fprintf(annotationfile, "Onset%cAnnotation\n", separator);
     }
 
-    for(j=0; j < annot_cnt; j++)
+    for(j=0; j<annot_cnt; j++)
     {
-      annot = edfplus_annotation_item(&annot_list, j);
+      annot = edfplus_annotation_get_item(annot_list, j);
       if(annot == NULL)
       {
         break;
@@ -547,7 +556,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
     fclose(annotationfile);
 
-    edfplus_annotation_delete_list(&annot_list);
+    edfplus_annotation_empty_list(annot_list);
+    free(annot_list);
 
     QMessageBox messagewindow(QMessageBox::Information, "Ready", "Done.");
     messagewindow.setIconPixmap(QPixmap(":/images/ok.png"));
@@ -568,7 +578,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open annotationfile for writing.");
       messagewindow.exec();
       ExportAnnotsDialog->close();
-      edfplus_annotation_delete_list(&annot_list);
+      edfplus_annotation_empty_list(annot_list);
+      free(annot_list);
       return;
     }
 
@@ -585,7 +596,7 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
     for(j=0; j < annot_cnt; j++)
     {
-      annot = edfplus_annotation_item(&annot_list, j);
+      annot = edfplus_annotation_get_item(annot_list, j);
       if(annot == NULL)
       {
         break;
@@ -620,7 +631,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
     fclose(annotationfile);
 
-    edfplus_annotation_delete_list(&annot_list);
+    edfplus_annotation_empty_list(annot_list);
+    free(annot_list);
 
     QMessageBox messagewindow(QMessageBox::Information, "Ready", "Done.");
     messagewindow.setIconPixmap(QPixmap(":/images/ok.png"));
@@ -656,7 +668,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
       QMessageBox messagewindow(QMessageBox::Critical, "Error", str);
       messagewindow.exec();
-      edfplus_annotation_delete_list(&annot_list);
+      edfplus_annotation_empty_list(annot_list);
+      free(annot_list);
       ExportAnnotsDialog->close();
       return;
     }
@@ -709,7 +722,7 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
 
     for(j=0; j < annot_cnt; j++)
     {
-      annot = edfplus_annotation_item(&annot_list, j);
+      annot = edfplus_annotation_get_item(annot_list, j);
       if(annot == NULL)
       {
         break;
@@ -773,7 +786,8 @@ void UI_ExportAnnotationswindow::ExportButtonClicked()
       messagewindow.exec();
     }
 
-    edfplus_annotation_delete_list(&annot_list);
+    edfplus_annotation_empty_list(annot_list);
+    free(annot_list);
 
     QMessageBox messagewindow(QMessageBox::Information, "Ready", "Done.");
     messagewindow.setIconPixmap(QPixmap(":/images/ok.png"));
diff --git a/export_annotations.h b/export_annotations.h
index 405f091..7b913a3 100644
--- a/export_annotations.h
+++ b/export_annotations.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filter.cpp b/filter.cpp
index 6faae35..11972b4 100644
--- a/filter.cpp
+++ b/filter.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filter.h b/filter.h
index 3209f9f..2b0aafb 100644
--- a/filter.h
+++ b/filter.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filter_dialog.cpp b/filter_dialog.cpp
index 1e07986..c69502b 100644
--- a/filter_dialog.cpp
+++ b/filter_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filter_dialog.h b/filter_dialog.h
index 2efb163..caa4ec2 100644
--- a/filter_dialog.h
+++ b/filter_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filtercurve.cpp b/filtercurve.cpp
index c1f8dfc..9c8d51c 100644
--- a/filtercurve.cpp
+++ b/filtercurve.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filtercurve.h b/filtercurve.h
index 67b5188..d992a87 100644
--- a/filtercurve.h
+++ b/filtercurve.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filteredblockread.cpp b/filteredblockread.cpp
index 9a451e0..dbb70d7 100644
--- a/filteredblockread.cpp
+++ b/filteredblockread.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/filteredblockread.h b/filteredblockread.h
index 87f7295..4e33744 100644
--- a/filteredblockread.h
+++ b/filteredblockread.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/fino2edf.cpp b/fino2edf.cpp
index a52472d..c83c6f1 100644
--- a/fino2edf.cpp
+++ b/fino2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/fino2edf.h b/fino2edf.h
index 16c66a7..303bca7 100644
--- a/fino2edf.h
+++ b/fino2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/flywheel.cpp b/flywheel.cpp
index 4588595..f6b65f7 100644
--- a/flywheel.cpp
+++ b/flywheel.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/flywheel.h b/flywheel.h
index 1f9cd06..aef8380 100644
--- a/flywheel.h
+++ b/flywheel.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/fma_ecg2edf.cpp b/fma_ecg2edf.cpp
index 85a4168..d26dbb0 100644
--- a/fma_ecg2edf.cpp
+++ b/fma_ecg2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2015, 2016 Teunis van Beelen
+* Copyright (C) 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -46,8 +46,10 @@
 
 
 
-UI_FMaudio2EDFwindow::UI_FMaudio2EDFwindow(char *recent_dir, char *save_dir)
+UI_FMaudio2EDFwindow::UI_FMaudio2EDFwindow(QWidget *w_parent, char *recent_dir, char *save_dir)
 {
+  mainwindow = (UI_Mainwindow *)w_parent;
+
   recent_opendir = recent_dir;
   recent_savedir = save_dir;
 
@@ -92,8 +94,13 @@ UI_FMaudio2EDFwindow::UI_FMaudio2EDFwindow(char *recent_dir, char *save_dir)
   pushButton2->setGeometry(480, 250, 100, 25);
   pushButton2->setText("Close");
 
+  helpButton = new QPushButton(myobjectDialog);
+  helpButton->setGeometry(240, 250, 100, 25);
+  helpButton->setText("Help");
+
   QObject::connect(pushButton1, SIGNAL(clicked()), this,           SLOT(SelectFileButton()));
   QObject::connect(pushButton2, SIGNAL(clicked()), myobjectDialog, SLOT(close()));
+  QObject::connect(helpButton,  SIGNAL(clicked()), this,           SLOT(helpbuttonpressed()));
 
   myobjectDialog->exec();
 }
@@ -772,6 +779,25 @@ bool UI_FMaudio2EDFwindow::allocateFilters(int uf, int usf, int dsf)
 }
 
 
+void UI_FMaudio2EDFwindow::helpbuttonpressed()
+{
+#ifdef Q_OS_LINUX
+  QDesktopServices::openUrl(QUrl("file:///usr/share/doc/edfbrowser/manual.html#FMaudio_to_EDF"));
+#endif
+
+#ifdef Q_OS_WIN32
+  char p_path[MAX_PATH_LENGTH];
+
+  strcpy(p_path, "file:///");
+  strcat(p_path, mainwindow->specialFolder(CSIDL_PROGRAM_FILES).toLocal8Bit().data());
+  strcat(p_path, "\\EDFbrowser\\manual.html#FMaudio_to_EDF");
+  QDesktopServices::openUrl(QUrl(p_path));
+#endif
+}
+
+
+
+
 
 
 
diff --git a/fma_ecg2edf.h b/fma_ecg2edf.h
index 4f5ec16..13a7012 100644
--- a/fma_ecg2edf.h
+++ b/fma_ecg2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2015, 2016 Teunis van Beelen
+* Copyright (C) 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -46,17 +46,21 @@
 #include <QMessageBox>
 #include <QString>
 #include <QPixmap>
+#include <QDesktopServices>
+#include <QUrl>
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "global.h"
+#include "mainwindow.h"
 #include "utils.h"
 #include "edflib.h"
 #include "ravg_filter.h"
 
 
+class UI_Mainwindow;
 
 
 class UI_FMaudio2EDFwindow : public QObject
@@ -64,14 +68,17 @@ class UI_FMaudio2EDFwindow : public QObject
   Q_OBJECT
 
 public:
-  UI_FMaudio2EDFwindow(char *recent_dir=NULL, char *save_dir=NULL);
+  UI_FMaudio2EDFwindow(QWidget *, char *recent_dir=NULL, char *save_dir=NULL);
+
+  UI_Mainwindow  *mainwindow;
 
 private:
 
 QDialog       *myobjectDialog;
 
 QPushButton   *pushButton1,
-              *pushButton2;
+              *pushButton2,
+              *helpButton;
 
 QLabel        *PatientnameLabel,
               *RecordingLabel,
@@ -105,6 +112,7 @@ void deleteFilters(void);
 private slots:
 
 void SelectFileButton();
+void helpbuttonpressed();
 
 };
 
diff --git a/global.h b/global.h
index 7b467c4..a0967d6 100644
--- a/global.h
+++ b/global.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -44,7 +44,7 @@
 #endif
 
 #define PROGRAM_NAME "EDFbrowser"
-#define PROGRAM_VERSION "1.58"
+#define PROGRAM_VERSION "1.59"
 #define MINIMUM_QT_VERSION 0x040701
 #define MAXFILES 32
 #define MAXSIGNALS 512
@@ -84,7 +84,7 @@
 #include "spike_filter.h"
 #include "ecg_filter.h"
 #include "z_ratio_filter.h"
-
+#include "edf_annot_list.h"
 
 
 struct edfparamblock{
@@ -146,6 +146,7 @@ struct edfhdrblock{
         int       annots_not_read;
         int       recording_len_sec;
         struct edfparamblock *edfparam;
+        struct annotation_list annot_list;
       };
 
 struct signalcompblock{
@@ -240,22 +241,6 @@ struct zoomhistoryblock{
         double screen_offset[MAXZOOMHISTORY][MAXSIGNALS];
        };
 
-struct annotationblock{
-        int file_num;
-        long long onset;
-        char duration[16];
-        char annotation[MAX_ANNOTATION_LEN + 1];
-        struct annotationblock *former_annotation;
-        struct annotationblock *next_annotation;
-        int modified;
-        int x_pos;
-        int selected;
-        int jump;
-        int hided;
-        int hided_in_list;
-        unsigned int ident;
-       };
-
 struct active_markersblock{
         int file_num;
         struct annotationblock *list[MAX_ACTIVE_ANNOT_MARKERS];
diff --git a/header_editor.cpp b/header_editor.cpp
index e914fde..a0bc0a5 100644
--- a/header_editor.cpp
+++ b/header_editor.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -45,11 +45,11 @@ UI_headerEditorWindow::UI_headerEditorWindow(QWidget *w_parent)
 
   file = NULL;
 
-  setMinimumSize(690, 525);
-  setMaximumSize(690, 525);
+  setMinimumSize(690, 560);
+  setMaximumSize(690, 560);
 
   tabholder = new QTabWidget(this);
-  tabholder->setGeometry(0, 0, 690, 455);
+  tabholder->setGeometry(0, 0, 690, 490);
 
   tab1 = new QWidget;
   tab2 = new QWidget;
@@ -152,51 +152,51 @@ UI_headerEditorWindow::UI_headerEditorWindow(QWidget *w_parent)
   lineEdit5->setVisible(false);
 
   label6 = new QLabel(tab1);
-  label6->setGeometry(10, 255, 80, 25);
+  label6->setGeometry(10, 290, 80, 25);
   label6->setText("Admin. code");
   label6->setVisible(false);
 
   lineEdit6 = new QLineEdit(tab1);
-  lineEdit6->setGeometry(100, 255, 580, 25);
+  lineEdit6->setGeometry(100, 290, 580, 25);
   lineEdit6->setMaxLength(80);
   lineEdit6->setVisible(false);
 
   label7 = new QLabel(tab1);
-  label7->setGeometry(10, 290, 80, 25);
+  label7->setGeometry(10, 325, 80, 25);
   label7->setText("Technician");
   label7->setVisible(false);
 
   lineEdit7 = new QLineEdit(tab1);
-  lineEdit7->setGeometry(100, 290, 580, 25);
+  lineEdit7->setGeometry(100, 325, 580, 25);
   lineEdit7->setMaxLength(80);
   lineEdit7->setVisible(false);
 
   label8 = new QLabel(tab1);
-  label8->setGeometry(10, 325, 80, 25);
+  label8->setGeometry(10, 360, 80, 25);
   label8->setText("Device");
   label8->setVisible(false);
 
   lineEdit8 = new QLineEdit(tab1);
-  lineEdit8->setGeometry(100, 325, 580, 25);
+  lineEdit8->setGeometry(100, 360, 580, 25);
   lineEdit8->setMaxLength(80);
   lineEdit8->setVisible(false);
 
   label9 = new QLabel(tab1);
-  label9->setGeometry(10, 360, 80, 25);
+  label9->setGeometry(10, 395, 80, 25);
   label9->setText("Additional info");
   label9->setVisible(false);
 
   lineEdit9 = new QLineEdit(tab1);
-  lineEdit9->setGeometry(100, 360, 580, 25);
+  lineEdit9->setGeometry(100, 395, 580, 25);
   lineEdit9->setMaxLength(80);
   lineEdit9->setVisible(false);
 
   charsleft2Label = new QLabel(tab1);
-  charsleft2Label->setGeometry(500, 395, 120, 25);
+  charsleft2Label->setGeometry(500, 430, 120, 25);
   charsleft2Label->setVisible(false);
 
   signallist = new QTableWidget(tab2);
-  signallist->setGeometry(10, 10, 670, 375);
+  signallist->setGeometry(10, 10, 670, 430);
   signallist->setSelectionMode(QAbstractItemView::NoSelection);
   signallist->setEditTriggers(QAbstractItemView::NoEditTriggers);
   signallist->setColumnCount(4);
@@ -213,19 +213,19 @@ UI_headerEditorWindow::UI_headerEditorWindow(QWidget *w_parent)
   signallist->setHorizontalHeaderLabels(horizontallabels);
 
   pushButton1 = new QPushButton(this);
-  pushButton1->setGeometry(580, 475, 100, 25);
+  pushButton1->setGeometry(580, 510, 100, 25);
   pushButton1->setText("Close");
 
   pushButton2 = new QPushButton(this);
-  pushButton2->setGeometry(200, 475, 100, 25);
+  pushButton2->setGeometry(200, 510, 100, 25);
   pushButton2->setText("Save");
 
   pushButton3 = new QPushButton(this);
-  pushButton3->setGeometry(10, 475, 100, 25);
+  pushButton3->setGeometry(10, 510, 100, 25);
   pushButton3->setText("Select file");
 
   helpButton = new QPushButton(this);
-  helpButton->setGeometry(380, 475, 100, 25);
+  helpButton->setGeometry(380, 510, 100, 25);
   helpButton->setText("Help");
 
   connect(pushButton1, SIGNAL(clicked()), this, SLOT(close()));
@@ -281,6 +281,7 @@ void UI_headerEditorWindow::open_file()
   disconnect(lineEdit3,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
   disconnect(lineEdit4,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
   disconnect(lineEdit5,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
+  disconnect(checkBox1,   SIGNAL(stateChanged(int)),           this, SLOT(calculate_chars_left_name(int)));
   disconnect(lineEdit6,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
   disconnect(lineEdit7,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
   disconnect(lineEdit8,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
@@ -750,6 +751,7 @@ void UI_headerEditorWindow::read_header()
     connect(lineEdit3,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
     connect(lineEdit4,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
     connect(lineEdit5,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_name(const QString &)));
+    connect(checkBox1,   SIGNAL(stateChanged(int)),           this, SLOT(calculate_chars_left_name(int)));
     connect(lineEdit6,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
     connect(lineEdit7,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
     connect(lineEdit8,   SIGNAL(textEdited(const QString &)), this, SLOT(calculate_chars_left_recording(const QString &)));
@@ -922,6 +924,13 @@ void UI_headerEditorWindow::save_hdr()
 
   if(edfplus || bdfplus)
   {
+    if((calculate_chars_left_name("") < 0) || (calculate_chars_left_recording("") < 0))
+    {
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", "Too many characters.");
+      messagewindow.exec();
+      return;
+    }
+
     str[0] = 0;
 
     len = strlen(lineEdit3->text().toLatin1().data());  // patient code
@@ -1449,7 +1458,13 @@ void UI_headerEditorWindow::save_hdr()
 }
 
 
-void UI_headerEditorWindow::calculate_chars_left_name(const QString &)
+void UI_headerEditorWindow::calculate_chars_left_name(int)
+{
+  calculate_chars_left_name("");
+}
+
+
+int UI_headerEditorWindow::calculate_chars_left_name(const QString &)
 {
   int n = 61;
 
@@ -1459,6 +1474,10 @@ void UI_headerEditorWindow::calculate_chars_left_name(const QString &)
 
   char str[128];
 
+  if(checkBox1->checkState() == Qt::Checked)  // birthdate
+  {
+    n += 10;
+  }
 
   cursorposition[0] = lineEdit3->cursorPosition();
   cursorposition[1] = lineEdit4->cursorPosition();
@@ -1502,12 +1521,14 @@ void UI_headerEditorWindow::calculate_chars_left_name(const QString &)
   sprintf(str, "Characters left:  %i", n);
 
   charsleft1Label->setText(str);
+
+  return n;
 }
 
 
-void UI_headerEditorWindow::calculate_chars_left_recording(const QString &)
+int UI_headerEditorWindow::calculate_chars_left_recording(const QString &)
 {
-  int n = 42;
+  int n = 52;
 
   int len;
 
@@ -1540,9 +1561,9 @@ void UI_headerEditorWindow::calculate_chars_left_recording(const QString &)
   }
 
   len = strlen(lineEdit9->text().toLatin1().data());
-  if(len>1)
+  if(len>0)
   {
-    n -= (len - 1);
+    n -= len;
   }
 
   if(n<1)
@@ -1568,6 +1589,8 @@ void UI_headerEditorWindow::calculate_chars_left_recording(const QString &)
   sprintf(str, "Characters left:  %i", n);
 
   charsleft2Label->setText(str);
+
+  return n;
 }
 
 
diff --git a/header_editor.h b/header_editor.h
index 5e51ede..754d153 100644
--- a/header_editor.h
+++ b/header_editor.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -145,8 +145,9 @@ void open_file();
 void save_hdr();
 void read_header();
 void closeEvent(QCloseEvent *);
-void calculate_chars_left_name(const QString &);
-void calculate_chars_left_recording(const QString &);
+void calculate_chars_left_name(int);
+int calculate_chars_left_name(const QString &);
+int calculate_chars_left_recording(const QString &);
 void helpbuttonpressed();
 
 };
diff --git a/images/splash.png b/images/splash.png
index ba4f406..3c1d222 100644
Binary files a/images/splash.png and b/images/splash.png differ
diff --git a/import_annotations.cpp b/import_annotations.cpp
index da9e974..0550064 100644
--- a/import_annotations.cpp
+++ b/import_annotations.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -482,13 +482,13 @@ void UI_ImportAnnotationswindow::ImportButtonClicked()
 
     mainwindow->addDockWidget(Qt::RightDockWidgetArea, mainwindow->annotations_dock[0]->docklist, Qt::Vertical);
 
-    if(!mainwindow->annotationlist[0])
+    if(edfplus_annotation_size(&mainwindow->edfheaderlist[0]->annot_list) < 1)
     {
       mainwindow->annotations_dock[0]->docklist->hide();
     }
   }
 
-  if(mainwindow->annotationlist[0])
+  if(edfplus_annotation_size(&mainwindow->edfheaderlist[0]->annot_list) > 0)
   {
     mainwindow->annotations_dock[0]->docklist->show();
 
@@ -532,7 +532,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
             l_temp,
             utc_time=0LL;
 
-  struct annotationblock *annotation;
+  struct annotationblock annotation;
 
   struct date_time_struct date_time;
 
@@ -556,22 +556,17 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
 
   if(!strcmp(path, ""))
   {
-    return(1);
+    return 1;
   }
 
   get_directory_from_path(mainwindow->recent_opendir, path, MAX_PATH_LENGTH);
 
-  if(mainwindow->annotationlist_backup==NULL)
-  {
-    mainwindow->annotationlist_backup = edfplus_annotation_copy_list(&mainwindow->annotationlist[0]);
-  }
-
   xml_hdl = xml_get_handle(path);
   if(xml_hdl==NULL)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open file for reading.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if((xml_hdl->encoding != 1) && (xml_hdl->encoding != 2))
@@ -579,7 +574,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Encoding of XML-file must be UTF-8 or ISO-8859-1.");
     messagewindow.exec();
     xml_close(xml_hdl);
-    return(1);
+    return 1;
   }
 
   if(strcmp(xml_hdl->elementname[xml_hdl->level], "annotationlist"))
@@ -587,14 +582,19 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not find root element \"annotationlist\".");
     messagewindow.exec();
     xml_close(xml_hdl);
-    return(1);
+    return 1;
   }
 
   QApplication::setOverrideCursor(Qt::WaitCursor);
 
   for(j=0; j<10; j++)  qApp->processEvents();
 
-  for(i=0; i<10000; i++)
+  if(mainwindow->annotationlist_backup==NULL)
+  {
+    mainwindow->annotationlist_backup = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[0]->annot_list);
+  }
+
+  for(i=0; i<100000; i++)
   {
     if(xml_goto_nth_element_inside(xml_hdl, "annotation", i))
     {
@@ -604,7 +604,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
         QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not find child element \"annotation\".");
         messagewindow.exec();
         xml_close(xml_hdl);
-        return(1);
+        return 1;
       }
 
       break;
@@ -622,7 +622,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not get content of element \"annotation\".");
       messagewindow.exec();
       xml_close(xml_hdl);
-      return(1);
+      return 1;
     }
 
     if(strlen(result) > 17)
@@ -685,7 +685,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
         QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not get content of element \"duration\".");
         messagewindow.exec();
         xml_close(xml_hdl);
-        return(1);
+        return 1;
       }
 
       strncpy(duration, result, 16);
@@ -714,29 +714,28 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not get content of element \"description\".");
       messagewindow.exec();
       xml_close(xml_hdl);
-      return(1);
+      return 1;
     }
 
     if((!ignore_consecutive) || (strcmp(result, last_description)))
     {
-      annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-      if(annotation == NULL)
+      memset(&annotation, 0, sizeof(struct annotationblock));
+      annotation.onset = onset;
+      strncpy(annotation.annotation, result, MAX_ANNOTATION_LEN);
+      if(xml_hdl->encoding == 1)
+      {
+        latin1_to_utf8(annotation.annotation, MAX_ANNOTATION_LEN);
+      }
+      annotation.annotation[MAX_ANNOTATION_LEN] = 0;
+      strcpy(annotation.duration, duration);
+      if(edfplus_annotation_add_item(&mainwindow->edfheaderlist[0]->annot_list, annotation))
       {
         QApplication::restoreOverrideCursor();
         QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
         messagewindow.exec();
         xml_close(xml_hdl);
-        return(1);
-      }
-      annotation->onset = onset;
-      strncpy(annotation->annotation, result, MAX_ANNOTATION_LEN);
-      if(xml_hdl->encoding == 1)
-      {
-        latin1_to_utf8(annotation->annotation, MAX_ANNOTATION_LEN);
+        return 1;
       }
-      annotation->annotation[MAX_ANNOTATION_LEN] = 0;
-      strcpy(annotation->duration, duration);
-      edfplus_annotation_add_item(&mainwindow->annotationlist[0], annotation);
 
       strcpy(last_description, result);
     }
@@ -750,7 +749,7 @@ int UI_ImportAnnotationswindow::import_from_xml(void)
 
   QApplication::restoreOverrideCursor();
 
-  return(0);
+  return 0;
 }
 
 
@@ -793,7 +792,7 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
 
   FILE *inputfile=NULL;
 
-  struct annotationblock *annotation;
+  struct annotationblock annotation;
 
   struct date_time_struct date_time;
 
@@ -829,28 +828,28 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
     {
       QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Separator must be one character or \"tab\".");
       messagewindow.exec();
-      return(1);
+      return 1;
     }
 
     if((str[0]<32)||(str[0]>126))
     {
       QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Separator character is not a valid ASCII character.");
       messagewindow.exec();
-      return(1);
+      return 1;
     }
 
     if(str[0]=='.')
     {
       QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Separator character can not be a dot.");
       messagewindow.exec();
-      return(1);
+      return 1;
     }
 
     if((str[0]>47)&&(str[0]<58))
     {
       QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Separator character can not be a number.");
       messagewindow.exec();
-      return(1);
+      return 1;
     }
 
     separator = str[0];
@@ -881,21 +880,21 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Onset and Description can not be in the same column.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if((duration_column == onset_column) && use_duration)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Onset and Duration can not be in the same column.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if((descr_column == duration_column) && (!manualdescription) && use_duration)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Invalid input", "Duration and Description can not be in the same column.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   mainwindow->import_annotations_var->onsettimeformat = onsettime_coding;
@@ -929,22 +928,17 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
 
   if(!strcmp(path, ""))
   {
-    return(1);
+    return 1;
   }
 
   get_directory_from_path(mainwindow->recent_opendir, path, MAX_PATH_LENGTH);
 
-  if(mainwindow->annotationlist_backup==NULL)
-  {
-    mainwindow->annotationlist_backup = edfplus_annotation_copy_list(&mainwindow->annotationlist[0]);
-  }
-
   inputfile = fopeno(path, "rb");
   if(inputfile==NULL)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open file for reading.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   rewind(inputfile);
@@ -953,6 +947,11 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
 
   for(j=0; j<10; j++)  qApp->processEvents();
 
+  if(mainwindow->annotationlist_backup==NULL)
+  {
+    mainwindow->annotationlist_backup = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[0]->annot_list);
+  }
+
   for(i=0; i<(startline-1);)
   {
     temp = fgetc(inputfile);
@@ -963,7 +962,7 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "File does not contain enough lines.");
       messagewindow.exec();
       fclose(inputfile);
-      return(1);
+      return 1;
     }
 
     if(temp=='\n')
@@ -1468,18 +1467,10 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
         {
           if((!ignore_consecutive) || strcmp(description, last_description))
           {
-            annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-            if(annotation == NULL)
-            {
-              QApplication::restoreOverrideCursor();
-              QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
-              messagewindow.exec();
-              fclose(inputfile);
-              return(1);
-            }
-            annotation->onset = onset + (86400LL * TIME_DIMENSION * days);
-            strncpy(annotation->annotation, description, MAX_ANNOTATION_LEN);
-            annotation->annotation[MAX_ANNOTATION_LEN] = 0;
+            memset(&annotation, 0, sizeof(struct annotationblock));
+            annotation.onset = onset + (86400LL * TIME_DIMENSION * days);
+            strncpy(annotation.annotation, description, MAX_ANNOTATION_LEN);
+            annotation.annotation[MAX_ANNOTATION_LEN] = 0;
             if(use_duration)
             {
               if((!(is_number(duration))) && (duration[0] != '-'))
@@ -1487,15 +1478,22 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
                 remove_trailing_zeros(duration);
                 if(duration[0] == '+')
                 {
-                  strcpy(annotation->duration, duration + 1);
+                  strcpy(annotation.duration, duration + 1);
                 }
                 else
                 {
-                  strcpy(annotation->duration, duration);
+                  strcpy(annotation.duration, duration);
                 }
               }
             }
-            edfplus_annotation_add_item(&mainwindow->annotationlist[0], annotation);
+            if(edfplus_annotation_add_item(&mainwindow->edfheaderlist[0]->annot_list, annotation))
+            {
+              QApplication::restoreOverrideCursor();
+              QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
+              messagewindow.exec();
+              fclose(inputfile);
+              return 1;
+            }
 
             strcpy(last_description, description);
           }
@@ -1503,18 +1501,10 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
 
         if(onset_is_set && manualdescription)
         {
-          annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-          if(annotation == NULL)
-          {
-            QApplication::restoreOverrideCursor();
-            QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
-            messagewindow.exec();
-            fclose(inputfile);
-            return(1);
-          }
-          annotation->onset = onset + (86400LL * TIME_DIMENSION * days);
-          strncpy(annotation->annotation, description, MAX_ANNOTATION_LEN);
-          annotation->annotation[MAX_ANNOTATION_LEN] = 0;
+          memset(&annotation, 0, sizeof(struct annotationblock));
+          annotation.onset = onset + (86400LL * TIME_DIMENSION * days);
+          strncpy(annotation.annotation, description, MAX_ANNOTATION_LEN);
+          annotation.annotation[MAX_ANNOTATION_LEN] = 0;
           if(use_duration)
           {
             if((!(is_number(duration))) && (duration[0] != '-'))
@@ -1522,15 +1512,22 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
               remove_trailing_zeros(duration);
               if(duration[0] == '+')
               {
-                strcpy(annotation->duration, duration + 1);
+                strcpy(annotation.duration, duration + 1);
               }
               else
               {
-                strcpy(annotation->duration, duration);
+                strcpy(annotation.duration, duration);
               }
             }
           }
-          edfplus_annotation_add_item(&mainwindow->annotationlist[0], annotation);
+          if(edfplus_annotation_add_item(&mainwindow->edfheaderlist[0]->annot_list, annotation))
+          {
+            QApplication::restoreOverrideCursor();
+            QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
+            messagewindow.exec();
+            fclose(inputfile);
+            return 1;
+          }
         }
       }
 
@@ -1564,7 +1561,7 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
       QMessageBox messagewindow(QMessageBox::Critical, "Error", scratchpad);
       messagewindow.exec();
       fclose(inputfile);
-      return(1);
+      return 1;
     }
   }
 
@@ -1574,10 +1571,10 @@ int UI_ImportAnnotationswindow::import_from_ascii(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred while closing inputfile.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
-  return(0);
+  return 0;
 }
 
 
@@ -1595,8 +1592,6 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
 
   struct edfhdrblock *edfhdr=NULL;
 
-  struct annotationblock *annotlist[1];
-
   struct annotationblock *annotation;
 
 
@@ -1604,22 +1599,17 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
 
   if(!strcmp(path, ""))
   {
-    return(1);
+    return 1;
   }
 
   get_directory_from_path(mainwindow->recent_opendir, path, MAX_PATH_LENGTH);
 
-  if(mainwindow->annotationlist_backup==NULL)
-  {
-    mainwindow->annotationlist_backup = edfplus_annotation_copy_list(&mainwindow->annotationlist[0]);
-  }
-
   inputfile = fopeno(path, "rb");
   if(inputfile==NULL)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open file for reading.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   rewind(inputfile);
@@ -1628,8 +1618,6 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
 
   str[0] = 0;
 
-  annotlist[0] = NULL;
-
   edfhdr = EDFfilechecker.check_edf_file(inputfile, str, 0);
   if(edfhdr==NULL)
   {
@@ -1637,7 +1625,7 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
     QMessageBox messagewindow(QMessageBox::Critical, "Error", str);
     messagewindow.exec();
     fclose(inputfile);
-    return(1);
+    return 1;
   }
 
   if(!(edfhdr->edfplus || edfhdr->bdfplus))
@@ -1647,7 +1635,7 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
-    return(1);
+    return 1;
   }
 
   strcpy(edfhdr->filename, path);
@@ -1656,25 +1644,26 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
 
   EDF_annotations annotations;
 
-  annotations.get_annotations(0, edfhdr, &annotlist[0], mainwindow->read_nk_trigger_signal);
+  annotations.get_annotations(edfhdr, mainwindow->read_nk_trigger_signal);
   if(edfhdr->annots_not_read)
   {
-    edfplus_annotation_delete_list(&annotlist[0]);
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
-    return(1);
+    return 1;
   }
 
-  annotlist_size = edfplus_annotation_count(&annotlist[0]);
-  if(annotlist_size == 0)
+  annotlist_size = edfplus_annotation_size(&edfhdr->annot_list);
+  if(annotlist_size < 1)
   {
     QMessageBox messagewindow(QMessageBox::Information, "Import annotations", "No annotations found.");
     messagewindow.exec();
+    edfplus_annotation_empty_list(&edfhdr->annot_list);
     free(edfhdr->edfparam);
     free(edfhdr);
     fclose(inputfile);
-    return(1);
+    return 1;
   }
 
   starttime_diff = edfhdr->utc_starttime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->utc_starttime;
@@ -1683,23 +1672,28 @@ int UI_ImportAnnotationswindow::import_from_edfplus(void)
 
   QApplication::setOverrideCursor(Qt::WaitCursor);
 
+  if(mainwindow->annotationlist_backup==NULL)
+  {
+    mainwindow->annotationlist_backup = edfplus_annotation_create_list_copy(&mainwindow->edfheaderlist[0]->annot_list);
+  }
+
   for(i=0; i<annotlist_size; i++)
   {
-    annotation = edfplus_annotation_item(&annotlist[0], i);
+    annotation = edfplus_annotation_get_item(&edfhdr->annot_list, i);
     annotation->onset += starttime_diff;
-    edfplus_annotation_add_copy(&mainwindow->annotationlist[0], annotation);
+    edfplus_annotation_add_item(&mainwindow->edfheaderlist[0]->annot_list, *annotation);
   }
 
-  edfplus_annotation_sort(&mainwindow->annotationlist[0]);
+  edfplus_annotation_sort(&mainwindow->edfheaderlist[0]->annot_list, NULL);
 
-  edfplus_annotation_delete_list(&annotlist[0]);
+  edfplus_annotation_empty_list(&edfhdr->annot_list);
   free(edfhdr->edfparam);
   free(edfhdr);
   fclose(inputfile);
 
   QApplication::restoreOverrideCursor();
 
-  return(0);
+  return 0;
 }
 
 
@@ -1742,7 +1736,7 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
 
   FILE *inputfile=NULL;
 
-  struct annotationblock *annotation;
+  struct annotationblock annotation;
 
   struct signalcompblock *signalcomp;
 
@@ -1766,14 +1760,14 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "You need to put at least one signal on the screen.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if(mainwindow->signalcomp[signal_nr]->num_of_signals > 1)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "The signal can not be a derivation of multiple signals.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   mainwindow->import_annotations_var->dceventbittime = BitTimeSpinbox->value();
@@ -1813,7 +1807,7 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Bit Time is set too low compared to the samplerate of the selected signal.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   triggervalue = mainwindow->import_annotations_var->triggerlevel / signalcomp->edfhdr->edfparam[signalcomp->edfsignal[0]].bitvalue;
@@ -1824,21 +1818,21 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Trigger Level is equal or higher than physical maximum.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if(triggervalue <= signalcomp->edfhdr->edfparam[signalcomp->edfsignal[0]].dig_min)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Trigger Level is equal or lower than physical minimum.");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   if(fseeko(inputfile, signalcomp->edfhdr->hdrsize + bufoffset, SEEK_SET))
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred while reading inputfile. (fseek)");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   buf = (char *)malloc(bytes_per_datrec);
@@ -1846,7 +1840,7 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred. (buf)");
     messagewindow.exec();
-    return(1);
+    return 1;
   }
 
   annotations_found = 0;
@@ -1913,7 +1907,7 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
       QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred while reading inputfile. (fread)");
       messagewindow.exec();
       free(buf);
-      return(1);
+      return 1;
     }
 
     for(i=0; i<smpls_per_datrec; i++)
@@ -1970,21 +1964,20 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
 
                 if((!ignore_consecutive) || (strcmp(scratchpad, last_description)))
                 {
-                  annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-                  if(annotation == NULL)
+                  memset(&annotation, 0, sizeof(struct annotationblock));
+                  annotation.onset = ((trigger_datrec * signalcomp->edfhdr->long_data_record_duration) + (trigger_sample * time_per_sample));
+                  annotation.onset += signalcomp->edfhdr->starttime_offset;
+                  annotation.file_num = signalcomp->edfhdr->file_num;
+                  strncpy(annotation.annotation, scratchpad, MAX_ANNOTATION_LEN);
+                  annotation.annotation[MAX_ANNOTATION_LEN] = 0;
+                  if(edfplus_annotation_add_item(&mainwindow->edfheaderlist[0]->annot_list, annotation))
                   {
                     progress.reset();
                     QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
                     messagewindow.exec();
                     free(buf);
-                    return(1);
+                    return 1;
                   }
-                  annotation->onset = ((trigger_datrec * signalcomp->edfhdr->long_data_record_duration) + (trigger_sample * time_per_sample));
-                  annotation->onset += signalcomp->edfhdr->starttime_offset;
-                  annotation->file_num = signalcomp->edfhdr->file_num;
-                  strncpy(annotation->annotation, scratchpad, MAX_ANNOTATION_LEN);
-                  annotation->annotation[MAX_ANNOTATION_LEN] = 0;
-                  edfplus_annotation_add_item(&mainwindow->annotationlist[0], annotation);
 
                   annotations_found++;
 
@@ -2027,7 +2020,7 @@ int UI_ImportAnnotationswindow::import_from_dcevent(void)
 
   progress.reset();
 
-  return(0);
+  return 0;
 }
 
 
diff --git a/import_annotations.h b/import_annotations.h
index 4883621..f9a70f0 100644
--- a/import_annotations.h
+++ b/import_annotations.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -102,7 +102,7 @@ class UI_ImportAnnotationswindow : public QObject
 
 public:
 
-UI_ImportAnnotationswindow(QWidget *parent);
+UI_ImportAnnotationswindow(QWidget *);
 
 UI_Mainwindow  *mainwindow;
 
diff --git a/jump_dialog.cpp b/jump_dialog.cpp
index b95a7f8..aa8ff08 100644
--- a/jump_dialog.cpp
+++ b/jump_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -103,9 +103,6 @@ UI_JumpMenuDialog::UI_JumpMenuDialog(QWidget *w_parent)
 
     timeEdit2->setTime(time2);
 
-    recording_duration = mainwindow->edfheaderlist[0]->datarecords * mainwindow->edfheaderlist[0]->long_data_record_duration;
-    recording_duration /= (TIME_DIMENSION / 1000LL);
-
     jumpButton->setEnabled(true);
   }
 
@@ -144,6 +141,15 @@ void UI_JumpMenuDialog::offsetday_changed(int days)
 
   daybox2->setValue((int)(milliseconds / 86400000LL));
 
+  if(daybox2->value() < 1)
+  {
+    timeEdit2->setMinimumTime(QTime((int)((starttime / 3600000LL) % 24LL), (int)((starttime % 3600000LL) / 60000LL), (int)((starttime % 60000LL) / 1000LL), (int)(starttime % 1000LL)));
+  }
+  else
+  {
+    timeEdit2->setMinimumTime(QTime(0, 0, 0, 0));
+  }
+
   QObject::connect(daybox2,     SIGNAL(valueChanged(int)),          this,        SLOT(absoluteday_changed(int)));
   QObject::connect(timeEdit2,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(absolutetime_changed(const QTime &)));
 }
@@ -157,6 +163,16 @@ void UI_JumpMenuDialog::absoluteday_changed(int days)
 
   QObject::disconnect(daybox1,     SIGNAL(valueChanged(int)),          this,        SLOT(offsetday_changed(int)));
   QObject::disconnect(timeEdit1,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(offsettime_changed(const QTime &)));
+  QObject::disconnect(timeEdit2,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(absolutetime_changed(const QTime &)));
+
+  if(days < 1)
+  {
+    timeEdit2->setMinimumTime(QTime((int)((starttime / 3600000LL) % 24LL), (int)((starttime % 3600000LL) / 60000LL), (int)((starttime % 60000LL) / 1000LL), (int)(starttime % 1000LL)));
+  }
+  else
+  {
+    timeEdit2->setMinimumTime(QTime(0, 0, 0, 0));
+  }
 
   milliseconds = (long long)(timeEdit2->time().hour()) * 3600000LL;
   milliseconds += (long long)(timeEdit2->time().minute()) * 60000LL;
@@ -177,6 +193,7 @@ void UI_JumpMenuDialog::absoluteday_changed(int days)
 
   QObject::connect(daybox1,     SIGNAL(valueChanged(int)),          this,        SLOT(offsetday_changed(int)));
   QObject::connect(timeEdit1,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(offsettime_changed(const QTime &)));
+  QObject::connect(timeEdit2,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(absolutetime_changed(const QTime &)));
 }
 
 
@@ -204,6 +221,15 @@ void UI_JumpMenuDialog::offsettime_changed(const QTime &time_1)
 
   daybox2->setValue((int)(milliseconds / 86400000LL));
 
+  if(daybox2->value() < 1)
+  {
+    timeEdit2->setMinimumTime(QTime((int)((starttime / 3600000LL) % 24LL), (int)((starttime % 3600000LL) / 60000LL), (int)((starttime % 60000LL) / 1000LL), (int)(starttime % 1000LL)));
+  }
+  else
+  {
+    timeEdit2->setMinimumTime(QTime(0, 0, 0, 0));
+  }
+
   QObject::connect(daybox2,     SIGNAL(valueChanged(int)),          this,        SLOT(absoluteday_changed(int)));
   QObject::connect(timeEdit2,   SIGNAL(timeChanged(const QTime &)), this,        SLOT(absolutetime_changed(const QTime &)));
 }
diff --git a/jump_dialog.h b/jump_dialog.h
index 13d037d..6ab9e64 100644
--- a/jump_dialog.h
+++ b/jump_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -85,8 +85,7 @@ QTime        time1,
 QSpinBox     *daybox1,
              *daybox2;
 
-long long    recording_duration,
-             starttime;
+long long    starttime;
 
 
 private slots:
diff --git a/load_montage_dialog.cpp b/load_montage_dialog.cpp
index 23483a9..4ff9c74 100644
--- a/load_montage_dialog.cpp
+++ b/load_montage_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -117,6 +117,7 @@ void UI_LoadMontagewindow::LoadButtonClicked()
   char result[XML_STRBUFLEN],
        scratchpad[2048],
        str[128],
+       str2[512],
        *err,
        *filter_spec,
        spec_str[256];
@@ -159,7 +160,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
   if(strcmp(xml_hdl->elementname[xml_hdl->level], PROGRAM_NAME "_montage"))
   {
-    QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+    sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+    QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
     messagewindow.exec();
     xml_close(xml_hdl);
     return;
@@ -308,7 +310,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
     if(xml_goto_nth_element_inside(xml_hdl, "num_of_signals", 0))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -316,7 +319,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     }
     if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -325,7 +329,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     signal_cnt = atoi(result);
     if((signal_cnt<1)||(signal_cnt>MAXSIGNALS))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -351,7 +356,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -370,7 +376,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
     if(xml_goto_nth_element_inside(xml_hdl, "voltpercm", 0))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -378,7 +385,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     }
     if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -389,7 +397,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     xml_go_up(xml_hdl);
     if(xml_goto_nth_element_inside(xml_hdl, "screen_offset", 0))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -397,7 +406,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     }
     if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -410,7 +420,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -426,7 +437,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
     if(xml_goto_nth_element_inside(xml_hdl, "color", 0))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -434,7 +446,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     }
     if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       free(newsignalcomp);
       xml_close(xml_hdl);
@@ -452,7 +465,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -469,7 +483,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -486,7 +501,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -509,7 +525,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -527,7 +544,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "signal", signals_read))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -536,7 +554,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "factor", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -544,7 +563,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -570,7 +590,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_goto_nth_element_inside(xml_hdl, "label", 0))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -578,7 +599,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
         }
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -615,7 +637,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -714,7 +737,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "spike_filter", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -723,7 +747,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "velocity", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -731,7 +756,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -744,7 +770,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "holdoff", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -752,7 +779,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -770,7 +798,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(newsignalcomp->spike_filter == NULL)
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating a spike filter.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -789,7 +818,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "filter", filters_read))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -798,7 +828,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "LPF", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -806,7 +837,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -817,7 +849,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "frequency", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -825,7 +858,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -835,7 +869,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if((type   < 0) || (type   >   1) || (frequency < 0.0001))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (filter values)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -846,7 +881,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
                       / newsignalcomp->edfhdr->data_record_duration)
                       / 2.0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -871,7 +907,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(err != NULL)
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", err);
+        sprintf(str2, "%s\nFile: %s line: %i", err, __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(err);
         free(newsignalcomp);
@@ -909,7 +946,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "ravg_filter", filters_read))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -918,7 +956,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "type", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -926,7 +965,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -937,7 +977,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "size", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -945,7 +986,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -955,7 +997,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if((type   < 0) || (type   >   1) || (size < 2) || (size > 10000))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (ravg_filter values)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -965,7 +1008,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       newsignalcomp->ravg_filter[filters_read] = create_ravg_filter(type, size);
       if(newsignalcomp->ravg_filter[filters_read] == NULL)
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating an ravg filter.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -986,7 +1030,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "fidfilter", filters_read))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (fidfilter)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -995,7 +1040,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "type", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (type)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1003,7 +1049,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1014,7 +1061,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "model", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (model)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1022,7 +1070,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1033,7 +1082,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "frequency", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (frequency)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1041,7 +1091,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1052,7 +1103,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "frequency2", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (frequency2)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1060,7 +1112,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1071,7 +1124,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "ripple", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (ripple)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1079,7 +1133,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1090,7 +1145,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       xml_go_up(xml_hdl);
       if(xml_goto_nth_element_inside(xml_hdl, "order", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (order)");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1098,7 +1154,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       }
       if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1112,7 +1169,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
          (ripple < (-6.0))    || (ripple > (-0.1))    ||
          (frequency < 0.0001) || (frequency2 < 0.0001))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (fidfilter values)");
+        sprintf(str2, "There seems to be an error in this montage file. (fidfilter values)\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1123,7 +1181,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
                       / newsignalcomp->edfhdr->data_record_duration)
                       / 2.0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2");
+        sprintf(str2, "There seems to be an error in this montage file.\nThe frequency of the filter(s) must be less than: samplerate / 2\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1136,7 +1195,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
                         / newsignalcomp->edfhdr->data_record_duration)
                         / 2.0))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2");
+          sprintf(str2, "There seems to be an error in this montage file.\nThe frequency of the filter(s) must be less than: samplerate / 2\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1306,7 +1366,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "type", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         free(newsignalcomp);
         xml_close(xml_hdl);
@@ -1330,7 +1391,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
                                                       mainwindow->powerlinefreq);
         if(newsignalcomp->ecg_filter == NULL)
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating an ECG filter.");
+          sprintf(str2, "A memory allocation error occurred when creating an ECG filter.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1355,7 +1417,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_goto_nth_element_inside(xml_hdl, "type", 0))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1363,7 +1426,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
         }
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1377,7 +1441,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
         {
           if(xml_goto_nth_element_inside(xml_hdl, "crossoverfreq", 0))
           {
-            QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+            sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+            QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
             messagewindow.exec();
             free(newsignalcomp);
             xml_close(xml_hdl);
@@ -1385,7 +1450,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
           }
           if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
           {
-            QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+            sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+            QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
             messagewindow.exec();
             free(newsignalcomp);
             xml_close(xml_hdl);
@@ -1405,7 +1471,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
           if(newsignalcomp->zratio_filter == NULL)
           {
-            QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating a Z-ratio filter.");
+            sprintf(str2, "A memory allocation error occurred when creating a Z-ratio filter.\nFile: %s line: %i", __FILE__, __LINE__);
+            QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
             messagewindow.exec();
             free(newsignalcomp);
             xml_close(xml_hdl);
@@ -1433,7 +1500,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_goto_nth_element_inside(xml_hdl, "hasruler", 0))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1441,7 +1509,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
         }
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           free(newsignalcomp);
           xml_close(xml_hdl);
@@ -1463,7 +1532,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
           {
             if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
             {
-              QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+              sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+              QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
               messagewindow.exec();
               free(newsignalcomp);
               xml_close(xml_hdl);
@@ -1483,7 +1553,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
           {
           if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
           {
-            QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+            sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+            QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
             messagewindow.exec();
             free(newsignalcomp);
             xml_close(xml_hdl);
@@ -1503,7 +1574,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
           {
             if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
             {
-              QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+              sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+              QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
               messagewindow.exec();
               free(newsignalcomp);
               xml_close(xml_hdl);
@@ -1539,7 +1611,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
   {
     if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
     {
-      QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+      sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+      QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
       messagewindow.exec();
       xml_close(xml_hdl);
       return;
@@ -1566,7 +1639,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
     {
       if(xml_goto_nth_element_inside(xml_hdl, "signalnum", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1575,7 +1649,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1588,7 +1663,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "amp", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1597,7 +1673,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1616,7 +1693,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1629,7 +1707,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "wheel", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1638,7 +1717,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1651,7 +1731,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "span", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1660,7 +1741,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1673,7 +1755,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "center", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1682,7 +1765,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1695,7 +1779,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "log", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1704,7 +1789,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1717,7 +1803,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "sqrt", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1726,7 +1813,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1739,7 +1827,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "colorbar", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1748,7 +1837,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1761,7 +1851,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "maxvalue", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1770,7 +1861,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1783,7 +1875,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "maxvalue_sqrt", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1792,7 +1885,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1805,7 +1899,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "maxvalue_vlog", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1814,7 +1909,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1827,7 +1923,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "maxvalue_sqrt_vlog", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1836,7 +1933,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1849,7 +1947,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "minvalue_vlog", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1858,7 +1957,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
@@ -1871,7 +1971,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
 
       if(xml_goto_nth_element_inside(xml_hdl, "minvalue_sqrt_vlog", 0))
       {
-        QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+        sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+        QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
         messagewindow.exec();
         xml_close(xml_hdl);
         return;
@@ -1880,7 +1981,8 @@ void UI_LoadMontagewindow::LoadButtonClicked()
       {
         if(xml_get_content_of_element(xml_hdl, result, XML_STRBUFLEN))
         {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file.");
+          sprintf(str2, "There seems to be an error in this montage file.\nFile: %s line: %i", __FILE__, __LINE__);
+          QMessageBox messagewindow(QMessageBox::Critical, "Error", str2);
           messagewindow.exec();
           xml_close(xml_hdl);
           return;
diff --git a/load_montage_dialog.h b/load_montage_dialog.h
index 9d6e536..5597f9c 100644
--- a/load_montage_dialog.h
+++ b/load_montage_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/main.cpp b/main.cpp
index 3b5cbd5..1a3129d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
 {
   QApplication app(argc, argv);
 
-  app.setAttribute(Qt::AA_DontUseNativeMenuBar);
+//   app.setAttribute(Qt::AA_DontUseNativeMenuBar);
 
   QPixmap pixmap(":/images/splash.png");
   QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 69cdce9..5825f03 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -282,8 +282,6 @@ void UI_Mainwindow::save_file()
 
   struct edfhdrblock *hdr;
 
-  struct annotationblock *annot;
-
   FILE *outputfile;
 
 
@@ -334,7 +332,7 @@ void UI_Mainwindow::save_file()
     return;
   }
 
-  if(save_annotations(this, outputfile, hdr, annotationlist[0]))
+  if(save_annotations(this, outputfile, hdr))
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred during saving.");
     messagewindow.exec();
@@ -344,13 +342,16 @@ void UI_Mainwindow::save_file()
 
   fclose(outputfile);
 
-  annot = annotationlist[0];
+  edfplus_annotation_empty_list(&hdr->annot_list);
 
-  annotationlist[0] = annotationlist_backup;
+  if(annotationlist_backup != NULL)
+  {
+    hdr->annot_list = *annotationlist_backup;
 
-  annotationlist_backup = NULL;
+    free(annotationlist_backup);
 
-  edfplus_annotation_delete_list(&annot);
+    annotationlist_backup = NULL;
+  }
 
   annotations_dock[0]->updateList();
 
@@ -612,7 +613,7 @@ void UI_Mainwindow::convert_wave_to_edf()
 
 void UI_Mainwindow::convert_fm_audio_to_edf()
 {
-  UI_FMaudio2EDFwindow fma2edf(recent_opendir, recent_savedir);
+  UI_FMaudio2EDFwindow fma2edf(this, recent_opendir, recent_savedir);
 }
 
 
@@ -1135,18 +1136,27 @@ void UI_Mainwindow::stop_playback_realtime()
 
 void UI_Mainwindow::playback_realtime_timer_func()
 {
-  if((viewtime_sync==VIEWTIME_SYNCED_OFFSET)||(viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)||(viewtime_sync==VIEWTIME_USER_DEF_SYNCED))
-  {
-    for(int i=0; i<files_open; i++)
-    {
-      edfheaderlist[i]->viewtime += (playback_realtime_time->restart() * 10000);
-    }
-  }
+  int i;
+
+  long long elapsed_time;
 
   if(viewtime_sync==VIEWTIME_UNSYNCED)
   {
     edfheaderlist[sel_viewtime]->viewtime += (playback_realtime_time->restart() * 10000);
   }
+  else if((viewtime_sync==VIEWTIME_SYNCED_OFFSET) ||
+      (viewtime_sync==VIEWTIME_SYNCED_ABSOLUT) ||
+      (viewtime_sync==VIEWTIME_USER_DEF_SYNCED))
+      {
+        elapsed_time = playback_realtime_time->restart() * 10000LL;
+
+        for(i=0; i<files_open; i++)
+        {
+          edfheaderlist[i]->viewtime += elapsed_time;
+        }
+
+        playback_realtime_time->restart();
+      }
 
   setup_viewbuf();
 }
@@ -1235,11 +1245,11 @@ void UI_Mainwindow::show_annotations()
       {
         edfheaderlist[i]->annots_not_read = 0;
 
-        annotations.get_annotations(i, edfheaderlist[i], &annotationlist[i], read_nk_trigger_signal);
+        annotations.get_annotations(edfheaderlist[i], read_nk_trigger_signal);
 
         if(edfheaderlist[i]->annots_not_read)
         {
-          edfplus_annotation_delete_list(&annotationlist[i]);
+          edfplus_annotation_empty_list(&edfheaderlist[files_open]->annot_list);
         }
         else
         {
@@ -1253,7 +1263,7 @@ void UI_Mainwindow::show_annotations()
       }
     }
 
-    if(annotationlist[i] != NULL)
+    if(edfplus_annotation_size(&edfheaderlist[i]->annot_list) > 0)
     {
       if(annotations_dock[i] != NULL)
       {
@@ -1276,7 +1286,7 @@ void UI_Mainwindow::annotation_editor()
   {
     if(edfheaderlist[0]->annots_not_read)
     {
-      edfplus_annotation_delete_list(&annotationlist[0]);
+      edfplus_annotation_empty_list(&edfheaderlist[files_open]->annot_list);
 
       if(annotations_dock[0] != NULL)
       {
@@ -1289,7 +1299,7 @@ void UI_Mainwindow::annotation_editor()
 
       EDF_annotations annotations;
 
-      annotations.get_annotations(0, edfheaderlist[0], &annotationlist[0], read_nk_trigger_signal);
+      annotations.get_annotations(edfheaderlist[0], read_nk_trigger_signal);
 
       if(edfheaderlist[0]->annots_not_read)
       {
@@ -1544,7 +1554,7 @@ void UI_Mainwindow::open_new_file()
 
     edfheaderlist[files_open] = edfhdr;
 
-    annotationlist[files_open] = NULL;
+    memset(&edfheaderlist[files_open]->annot_list, 0, sizeof(struct annotation_list));
 
     annotations_dock[files_open] = NULL;
 
@@ -1554,11 +1564,11 @@ void UI_Mainwindow::open_new_file()
       {
         EDF_annotations annotations;
 
-        annotations.get_annotations(files_open, edfhdr, &annotationlist[files_open], read_nk_trigger_signal);
+        annotations.get_annotations(edfhdr, read_nk_trigger_signal);
 
         if(edfhdr->annots_not_read)
         {
-          edfplus_annotation_delete_list(&annotationlist[files_open]);
+          edfplus_annotation_empty_list(&edfheaderlist[files_open]->annot_list);
         }
         else
         {
@@ -1566,7 +1576,7 @@ void UI_Mainwindow::open_new_file()
 
           addDockWidget(Qt::RightDockWidgetArea, annotations_dock[files_open]->docklist, Qt::Vertical);
 
-          if(!annotationlist[files_open])
+          if(!edfheaderlist[files_open]->annot_list.sz)
           {
             annotations_dock[files_open]->docklist->hide();
           }
@@ -1584,13 +1594,13 @@ void UI_Mainwindow::open_new_file()
       {
         BDF_triggers bdf_triggers_obj;
 
-        bdf_triggers_obj.get_triggers(edfhdr, &annotationlist[files_open]);
+        bdf_triggers_obj.get_triggers(edfhdr);
 
         annotations_dock[files_open] = new UI_Annotationswindow(files_open, this);
 
         addDockWidget(Qt::RightDockWidgetArea, annotations_dock[files_open]->docklist, Qt::Vertical);
 
-        if(!annotationlist[files_open])
+        if(!edfhdr->annot_list.sz)
         {
           annotations_dock[files_open]->docklist->hide();
         }
@@ -2146,10 +2156,10 @@ void UI_Mainwindow::close_file_action_func(QAction *action)
     }
   }
 
+  edfplus_annotation_empty_list(&edfheaderlist[file_n]->annot_list);
   fclose(edfheaderlist[file_n]->file_hdl);
   free(edfheaderlist[file_n]->edfparam);
   free(edfheaderlist[file_n]);
-  edfplus_annotation_delete_list(&annotationlist[file_n]);
 
   if(annotations_dock[file_n] != NULL)
   {
@@ -2180,8 +2190,6 @@ void UI_Mainwindow::close_file_action_func(QAction *action)
   {
     edfheaderlist[i] = edfheaderlist[i + 1];
 
-    annotationlist[i] = annotationlist[i + 1];
-
     annotations_dock[i] = annotations_dock[i + 1];
 
     sel_viewtime_act[i] = sel_viewtime_act[i + 1];
@@ -2242,9 +2250,9 @@ void UI_Mainwindow::close_all_files()
     {
       fclose(edfheaderlist[files_open]->file_hdl);
     }
+    edfplus_annotation_empty_list(&edfheaderlist[files_open]->annot_list);
     free(edfheaderlist[files_open]->edfparam);
     free(edfheaderlist[files_open]);
-    edfplus_annotation_delete_list(&annotationlist[files_open]);
 
     if(annotations_dock[files_open] != NULL)
     {
@@ -2256,7 +2264,14 @@ void UI_Mainwindow::close_all_files()
     delete sel_viewtime_act[files_open];
   }
 
-  edfplus_annotation_delete_list(&annotationlist_backup);
+  if(annotationlist_backup != NULL)
+  {
+    edfplus_annotation_empty_list(annotationlist_backup);
+
+    free(annotationlist_backup);
+
+    annotationlist_backup = NULL;
+  }
 
   sel_viewtime = 0;
 
@@ -3401,7 +3416,6 @@ QString UI_Mainwindow::specialFolder(int type)
 #endif
 
 
-
 int UI_Mainwindow::file_is_opened(const char *o_path)
 {
   int i;
@@ -3425,13 +3439,11 @@ void UI_Mainwindow::organize_signals()
 }
 
 
-void UI_Mainwindow::edfplus_annotation_remove_duplicates()
+void UI_Mainwindow::edfplus_remove_duplicate_annotations()
 {
-  int i, j, k, list_size, dup_cnt=0;
-
-  char str[256];
+  int i, dup_cnt=0, cnt;
 
-  struct annotationblock **list, *annot, *annot_cmp;
+  char str[1024];
 
   if(!files_open)
   {
@@ -3444,71 +3456,22 @@ void UI_Mainwindow::edfplus_annotation_remove_duplicates()
   progress.setWindowModality(Qt::WindowModal);
   progress.setMinimumDuration(200);
 
-  for(k=0; k<files_open; k++)
+  for(i=0; i<files_open; i++)
   {
-    list = &annotationlist[k];
-
-    if(*list==NULL)
-    {
-      continue;
-    }
+    cnt = edfplus_annotation_remove_duplicates(&edfheaderlist[i]->annot_list);
 
-    list_size = edfplus_annotation_count(list);
-
-    if(list_size < 2)  continue;
-
-    progress.setMaximum(list_size);
-
-    for(j=0; j<list_size; j++)
-    {
-      progress.setValue(j);
-
-      qApp->processEvents();
-
-      if(progress.wasCanceled() == true)
-      {
-        break;
-      }
-
-      annot_cmp = edfplus_annotation_item(list, j);
-
-      for(i=j; i<list_size; i++)
-      {
-        if(i!=j)
-        {
-          annot = edfplus_annotation_item(list, i);
-
-          if(annot->onset != annot_cmp->onset)  continue;
-
-          if(annot->file_num != annot_cmp->file_num)  continue;
-
-          if(strcmp(annot->annotation, annot_cmp->annotation))  continue;
-
-          if(strcmp(annot->duration, annot_cmp->duration))  continue;
-
-          edfplus_annotation_delete(list, i);
-
-          dup_cnt++;
-
-          list_size--;
-
-          if(j)  j--;
-
-          if(i)  i--;
-        }
-      }
-    }
+    dup_cnt += cnt;
   }
 
   progress.reset();
 
   if(dup_cnt)
   {
-    for(k=0; k<files_open; k++)
+    for(i=0; i<files_open; i++)
     {
-      if(annotations_dock[k] != NULL)
+      if(annotations_dock[i] != NULL)
       {
-        annotations_dock[k]->updateList();
+        annotations_dock[i]->updateList();
       }
     }
 
diff --git a/mainwindow.h b/mainwindow.h
index 7e79914..66dd591 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -258,9 +258,7 @@ public:
 
   struct zoomhistoryblock *zoomhistory;
 
-  struct annotationblock *annotationlist[MAXFILES];
-
-  struct annotationblock *annotationlist_backup;
+  struct annotation_list *annotationlist_backup;
 
   struct spectrum_markersblock *spectrum_colorbar;
 
@@ -454,7 +452,7 @@ private:
 
 public slots:
   void remove_all_signals();
-  void edfplus_annotation_remove_duplicates();
+  void edfplus_remove_duplicate_annotations();
   void video_player_seek(int);
   void video_player_toggle_pause();
 
diff --git a/mainwindow_constr.cpp b/mainwindow_constr.cpp
index eb052fa..25d0f63 100644
--- a/mainwindow_constr.cpp
+++ b/mainwindow_constr.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -677,7 +677,7 @@ UI_Mainwindow::UI_Mainwindow()
   toolsmenu->addSeparator();
   toolsmenu->addAction("Header editor", this, SLOT(edit_header()));
   toolsmenu->addAction("Reduce signals, duration or samplerate", this, SLOT(reduce_signals()));
-  toolsmenu->addAction("Remove duplicates in annotations", this, SLOT(edfplus_annotation_remove_duplicates()));
+  toolsmenu->addAction("Remove duplicates in annotations", this, SLOT(edfplus_remove_duplicate_annotations()));
   toolsmenu->addSeparator();
   toolsmenu->addAction("Import annotations/events", this, SLOT(import_annotations()));
   toolsmenu->addAction("Export annotations/events", this, SLOT(export_annotations()));
@@ -688,7 +688,7 @@ UI_Mainwindow::UI_Mainwindow()
   toolsmenu->addAction("Convert ASCII to EDF/BDF", this, SLOT(convert_ascii_to_edf()));
   toolsmenu->addAction("Convert Manscan to EDF+", this, SLOT(convert_manscan_to_edf()));
   toolsmenu->addAction("Convert SCP ECG to EDF+", this, SLOT(convert_scpecg_to_edf()));
-  toolsmenu->addAction("Convert MIT to EDF+", this, SLOT(convert_mit_to_edf()));
+  toolsmenu->addAction("Convert MIT (PhysioBank) to EDF+", this, SLOT(convert_mit_to_edf()));
   toolsmenu->addAction("Convert Finometer to EDF", this, SLOT(convert_fino_to_edf()));
   toolsmenu->addAction("Convert Nexfin to EDF", this, SLOT(convert_nexfin_to_edf()));
   toolsmenu->addAction("Convert Emsa to EDF+", this, SLOT(convert_emsa_to_edf()));
@@ -856,7 +856,6 @@ UI_Mainwindow::UI_Mainwindow()
 
   for(i=0; i<MAXFILES; i++)
   {
-    annotationlist[i] = NULL;
     annotations_dock[i] = NULL;
   }
 
@@ -913,7 +912,7 @@ UI_Mainwindow::UI_Mainwindow()
     }
   }
 
-  annotationEditDock = new UI_AnnotationEditwindow(files_open, this);
+  annotationEditDock = new UI_AnnotationEditwindow(this);
 
   addDockWidget(Qt::BottomDockWidgetArea, annotationEditDock->dockedit, Qt::Horizontal);
 
diff --git a/manscan2edf.cpp b/manscan2edf.cpp
index f74de23..0faf983 100644
--- a/manscan2edf.cpp
+++ b/manscan2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/manscan2edf.h b/manscan2edf.h
index b6218ad..913b834 100644
--- a/manscan2edf.h
+++ b/manscan2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/mit2edf.cpp b/mit2edf.cpp
index d8309eb..d4cb2d9 100644
--- a/mit2edf.cpp
+++ b/mit2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -79,26 +79,42 @@
 #define ACMAX 49  /* value of largest valid annot code (must be < 50) */
 
 
-char annotdescrlist[42][48]={"not-QRS","normal beat",
-                            "left bundle branch block beat", "right bundle branch block beat",
-                            "aberrated atrial premature beat", "premature ventricular contraction",
-                            "fusion of ventricular and normal beat", "nodal (junctional) premature beat",
-                            "atrial premature contraction", "premature or ectopic supraventricular beat",
-                            "ventricular escape beat", "nodal (junctional) escape beat",
-                            "paced beat", "unclassifiable beat",
-                            "signal quality change", "isolated QRS-like artifact",
-                            "ST change", "T-wave change",
-                            "systole", "diastole",
-                            "comment annotation", "measurement annotation",
-                            "P-wave peak", "left or right bundle branch block",
-                            "non-conducted pacer spike", "T-wave peak",
-                            "rhythm change", "U-wave peak",
-                            "learning", "ventricular flutter wave",
-                            "start of ventricular flutter/fibrillation", "end of ventricular flutter/fibrillation",
-                            "atrial escape beat", "supraventricular escape beat",
-                            "link to external data (aux contains URL)", "non-conducted P-wave (blocked APB)",
-                            "fusion of paced and normal beat", "waveform onset",
-                            "waveform end", "R-on-T premature ventricular contraction"};
+static char annotdescrlist[42][48]=
+  {"not-QRS","normal beat",
+  "left bundle branch block beat", "right bundle branch block beat",
+  "aberrated atrial premature beat", "premature ventricular contraction",
+  "fusion of ventricular and normal beat", "nodal (junctional) premature beat",
+  "atrial premature contraction", "premature or ectopic supraventricular beat",
+  "ventricular escape beat", "nodal (junctional) escape beat",
+  "paced beat", "unclassifiable beat",
+  "signal quality change", "isolated QRS-like artifact",
+  "ST change", "T-wave change",
+  "systole", "diastole",
+  "comment annotation", "measurement annotation",
+  "P-wave peak", "left or right bundle branch block",
+  "non-conducted pacer spike", "T-wave peak",
+  "rhythm change", "U-wave peak",
+  "learning", "ventricular flutter wave",
+  "start of ventricular flutter/fibrillation", "end of ventricular flutter/fibrillation",
+  "atrial escape beat", "supraventricular escape beat",
+  "link to external data (aux contains URL)", "non-conducted P-wave (blocked APB)",
+  "fusion of paced and normal beat", "waveform onset",
+  "waveform end", "R-on-T premature ventricular contraction"};
+
+
+#define ANNOT_EXT_CNT   7
+
+
+char annotextlist[ANNOT_EXT_CNT][16]=
+  {
+    ".ari",
+    ".ecg",
+    ".trigger",
+    ".qrs",
+    ".atr",
+    ".apn",
+    ".st"
+  };
 
 
 UI_MIT2EDFwindow::UI_MIT2EDFwindow(char *recent_dir, char *save_dir)
@@ -129,7 +145,7 @@ UI_MIT2EDFwindow::UI_MIT2EDFwindow(char *recent_dir, char *save_dir)
   textEdit1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
   textEdit1->setReadOnly(true);
   textEdit1->setLineWrapMode(QTextEdit::NoWrap);
-  sprintf(txt_string, "MIT to EDF+ converter.\n");
+  sprintf(txt_string, "MIT (PhysioBank) to EDF+ converter.\n");
   textEdit1->append(txt_string);
 
   QObject::connect(pushButton1, SIGNAL(clicked()), this, SLOT(SelectFileButton()));
@@ -390,7 +406,9 @@ void UI_MIT2EDFwindow::SelectFileButton()
 
     mit_hdr.format[j] = atoi(charpntr + p);
 
-    if((mit_hdr.format[j] != 212) && (mit_hdr.format[j] != 16))
+    if((mit_hdr.format[j] != 212) &&
+      (mit_hdr.format[j] != 16) &&
+      (mit_hdr.format[j] != 61))
     {
       snprintf(txt_string, 2048, "Error, unsupported format: %i  (error 16)\n", mit_hdr.format[j]);
       textEdit1->append(txt_string);
@@ -427,7 +445,10 @@ void UI_MIT2EDFwindow::SelectFileButton()
       continue;
     }
 
-    mit_hdr.adc_gain[j] = atoi(charpntr + p);
+    if(atoi(charpntr + p) != 0)
+    {
+      mit_hdr.adc_gain[j] = atoi(charpntr + p);
+    }
 
     p = ++i;
 
@@ -571,6 +592,13 @@ void UI_MIT2EDFwindow::SelectFileButton()
     return;
   }
 
+  get_filename_from_path(filename_x, data_filename, MAX_PATH_LENGTH);
+
+  snprintf(txt_string, 2048, "Read file: %s (format: %i)", filename_x, mit_hdr.format[0]);
+  textEdit1->append(QString::fromLocal8Bit(txt_string));
+
+  remove_extension_from_filename(filename_x);
+
   fseeko(data_inputfile, 0LL, SEEK_END);
   filesize = ftello(data_inputfile);
   if(filesize < (mit_hdr.chns * mit_hdr.sf * 45 / 10))
@@ -581,34 +609,14 @@ void UI_MIT2EDFwindow::SelectFileButton()
     return;
   }
 
-  mit_hdr.sf_div = 1;
-
-  mit_hdr.sf_block = mit_hdr.sf;
-
-  if(!(mit_hdr.sf % 10))
+  for(mit_hdr.sf_div=12; mit_hdr.sf_div>0; mit_hdr.sf_div--)
   {
-    mit_hdr.sf_div = 10;
-
-    mit_hdr.sf_block /= mit_hdr.sf_div;
+    if(!(mit_hdr.sf % mit_hdr.sf_div))  break;
   }
-  else if(!(mit_hdr.sf % 8))
-    {
-      mit_hdr.sf_div = 8;
 
-      mit_hdr.sf_block /= mit_hdr.sf_div;
-    }
-    else if(!(mit_hdr.sf % 4))
-      {
-        mit_hdr.sf_div = 4;
+  if(mit_hdr.sf_div < 1)  mit_hdr.sf_div = 1;
 
-        mit_hdr.sf_block /= mit_hdr.sf_div;
-      }
-      else if(!(mit_hdr.sf % 2))
-        {
-          mit_hdr.sf_div = 2;
-
-          mit_hdr.sf_block /= mit_hdr.sf_div;
-        }
+  mit_hdr.sf_block = mit_hdr.sf / mit_hdr.sf_div;
 
   hdl = edfopen_file_writeonly(edf_filename, EDFLIB_FILETYPE_EDFPLUS, mit_hdr.chns);
 
@@ -720,7 +728,7 @@ void UI_MIT2EDFwindow::SelectFileButton()
 
 /////////////////// Start conversion //////////////////////////////////////////
 
-  int k, blocks, tmp1, tmp2;
+  int k, blocks, tmp1, tmp2, l_end=0;
 
   fseeko(data_inputfile, 0LL, SEEK_SET);
 
@@ -807,8 +815,10 @@ void UI_MIT2EDFwindow::SelectFileButton()
     }
   }
 
-  if(mit_hdr.format[0] == 16)
+  if((mit_hdr.format[0] == 16) || (mit_hdr.format[0] == 61))
   {
+    if(mit_hdr.format[0] == 16)  l_end = 1;
+
     blocks /= 2;
 
     progress.setMaximum(blocks);
@@ -842,14 +852,23 @@ void UI_MIT2EDFwindow::SelectFileButton()
             goto OUT;
           }
 
-          tmp1 += (fgetc(data_inputfile) << 8);
+          if(l_end)
+          {
+            tmp1 += (fgetc(data_inputfile) << 8);
 
-          if(tmp1 & 0x8000)
+            if(tmp1 & 0x8000)
+            {
+              tmp1 |= 0xffff0000;
+            }
+          }
+          else
           {
-            tmp1 |= 0xffff0000;
+            tmp1 <<= 8;
+
+            tmp1 += fgetc(data_inputfile);
           }
 
-         buf[j * mit_hdr.sf_block + i] = tmp1;
+          buf[j * mit_hdr.sf_block + i] = tmp1;
         }
       }
 
@@ -878,128 +897,134 @@ OUT:
 
   free(buf);
 
-  int annot_code, tc=0, skip;
+  int annot_code, tc, skip, total_annots=0;
 
   long long bytes_read;
 
   get_filename_from_path(filename_x, annot_filename, MAX_PATH_LENGTH);
 
-  annot_inputfile = fopeno(annot_filename, "rb");
-  if(annot_inputfile==NULL)
+  for(k=0; k<ANNOT_EXT_CNT; k++)
   {
-    remove_extension_from_filename(annot_filename);
-
-    strcat(annot_filename, ".ari");
+    tc = 0;
 
-    annot_inputfile = fopeno(annot_filename, "rb");
-  }
-
-  if(annot_inputfile==NULL)
-  {
     remove_extension_from_filename(annot_filename);
 
-    strcat(annot_filename, ".ecg");
+    strcat(annot_filename, annotextlist[k]);
 
     annot_inputfile = fopeno(annot_filename, "rb");
-  }
+    if(annot_inputfile==NULL)
+    {
+      continue;
+    }
 
-  if(annot_inputfile==NULL)
-  {
-    snprintf(txt_string, 2048, "Can not open file %s for reading.\n"
-                               "Annotations can not be included.", filename_x);
-    textEdit1->append(QString::fromLocal8Bit(txt_string));
-  }
-  else
-  {
-    snprintf(txt_string, 2048, "Read file: %s", filename_x);
-    textEdit1->append(QString::fromLocal8Bit(txt_string));
+    get_filename_from_path(filename_x, annot_filename, MAX_PATH_LENGTH);
 
-    fseeko(annot_inputfile, 0LL, SEEK_END);
-    filesize = ftello(annot_inputfile);
+    if(annot_inputfile==NULL)
+    {
+      snprintf(txt_string, 2048, "Can not open file %s for reading.\n"
+                                 "Annotations can not be included.", filename_x);
+      textEdit1->append(QString::fromLocal8Bit(txt_string));
+    }
+    else
+    {
+      snprintf(txt_string, 2048, "Read file: %s", filename_x);
+      textEdit1->append(QString::fromLocal8Bit(txt_string));
 
-    progress.setLabelText("Converting annotations ...");
-    progress.setMinimum(0);
-    progress.setMaximum(filesize);
+      fseeko(annot_inputfile, 0LL, SEEK_END);
+      filesize = ftello(annot_inputfile);
 
-    fseeko(annot_inputfile, 0LL, SEEK_SET);
+      progress.setLabelText("Converting annotations ...");
+      progress.setMinimum(0);
+      progress.setMaximum(filesize);
 
-    for(bytes_read=0LL; bytes_read < filesize; bytes_read += 2LL)
-    {
-      if(!(bytes_read % 100))
-      {
-        progress.setValue(bytes_read);
-
-        qApp->processEvents();
+      fseeko(annot_inputfile, 0LL, SEEK_SET);
 
-        if(progress.wasCanceled() == true)
+      for(bytes_read=0LL; bytes_read < filesize; bytes_read += 2LL)
+      {
+        if(!(bytes_read % 100))
         {
-          textEdit1->append("Conversion aborted by user.\n");
+          progress.setValue(bytes_read);
 
-          break;
-        }
-      }
+          qApp->processEvents();
 
-      skip = 0;
+          if(progress.wasCanceled() == true)
+          {
+            textEdit1->append("Conversion aborted by user.\n");
 
-      if(fread(a_buf, 2, 1, annot_inputfile) != 1)
-      {
-        break;
-      }
+            break;
+          }
+        }
 
-#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+        skip = 0;
 
-      if(*((unsigned short *)a_buf) == 0)  // end of file
-      {
-        break;
-      }
+        if(fread(a_buf, 2, 1, annot_inputfile) != 1)
+        {
+          break;
+        }
 
-      annot_code = a_buf[1] >> 2;
+  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 
-      if(annot_code == 59)
-      {
-        if(fread(a_buf, 4, 1, annot_inputfile) != 1)
+        if(*((unsigned short *)a_buf) == 0)  // end of file
         {
           break;
         }
 
-        tc += (*((unsigned short *)a_buf) << 16);
+        annot_code = a_buf[1] >> 2;
 
-        tc += *((unsigned short *)(a_buf + 2));
-      }
-      else if(annot_code == 63)
+        if(annot_code == 59)
         {
-          skip = *((unsigned short *)a_buf) & 0x3ff;
+          if(fread(a_buf, 4, 1, annot_inputfile) != 1)
+          {
+            break;
+          }
 
-          if(skip % 2) skip++;
+          tc += (*((unsigned short *)a_buf) << 16);
+
+          tc += *((unsigned short *)(a_buf + 2));
         }
-        else if((annot_code >= 0) && (annot_code <= ACMAX))
+        else if(annot_code == 63)
           {
-            tc += *((unsigned short *)a_buf) & 0x3ff;
-
-#pragma GCC diagnostic warning "-Wstrict-aliasing"
+            skip = *((unsigned short *)a_buf) & 0x3ff;
 
-            if(annot_code < 42)
-            {
-              edfwrite_annotation_latin1(hdl, ((long long)tc * mit_hdr.smp_period) / 100000LL, -1, annotdescrlist[annot_code]);
-            }
-            else
+            if(skip % 2) skip++;
+          }
+          else if((annot_code >= 0) && (annot_code <= ACMAX))
             {
-              edfwrite_annotation_latin1(hdl, ((long long)tc * mit_hdr.smp_period) / 100000LL, -1, "user-defined");
+              tc += *((unsigned short *)a_buf) & 0x3ff;
+
+  #pragma GCC diagnostic warning "-Wstrict-aliasing"
+
+              if(annot_code < 42)
+              {
+                edfwrite_annotation_latin1(hdl, ((long long)tc * mit_hdr.smp_period) / 100000LL, -1, annotdescrlist[annot_code]);
+              }
+              else
+              {
+                edfwrite_annotation_latin1(hdl, ((long long)tc * mit_hdr.smp_period) / 100000LL, -1, "user-defined");
+              }
+
+              total_annots++;
             }
-          }
 
-      if(skip)
-      {
-        if(fseek(annot_inputfile, skip, SEEK_CUR) < 0)
+        if(skip)
         {
-          break;
-        }
+          if(fseek(annot_inputfile, skip, SEEK_CUR) < 0)
+          {
+            break;
+          }
 
-        bytes_read += skip;
+          bytes_read += skip;
+        }
       }
+
+      fclose(annot_inputfile);
     }
+  }
 
-    fclose(annot_inputfile);
+  if(total_annots)
+  {
+    snprintf(txt_string, 2048, "Read %i annotations.", total_annots);
+    textEdit1->append(txt_string);
   }
 
   progress.reset();
diff --git a/mit2edf.h b/mit2edf.h
index c7627d9..ad25c08 100644
--- a/mit2edf.h
+++ b/mit2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/nexfin2edf.cpp b/nexfin2edf.cpp
index 7701b90..8dbd092 100644
--- a/nexfin2edf.cpp
+++ b/nexfin2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/nexfin2edf.h b/nexfin2edf.h
index 857749c..b4e8823 100644
--- a/nexfin2edf.h
+++ b/nexfin2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/nk2edf.cpp b/nk2edf.cpp
index a9a3e7e..93896c3 100644
--- a/nk2edf.cpp
+++ b/nk2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/nk2edf.h b/nk2edf.h
index ac9e110..d1cb9b8 100644
--- a/nk2edf.h
+++ b/nk2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/options_dialog.cpp b/options_dialog.cpp
index eee271a..c700d30 100644
--- a/options_dialog.cpp
+++ b/options_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -1391,7 +1391,7 @@ void UI_OptionsDialog::TxtColorButtonClicked(SpecialButton *)
 
     for(i=0; i<mainwindow->files_open; i++)
     {
-      if(mainwindow->annotationlist[i])
+      if(edfplus_annotation_size(&mainwindow->edfheaderlist[i]->annot_list) > 0)
       {
         mainwindow->annotations_dock[i]->list->setPalette(palette);
       }
diff --git a/options_dialog.h b/options_dialog.h
index 03734ec..82c535f 100644
--- a/options_dialog.h
+++ b/options_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -67,7 +67,7 @@
 #include "colordialog.h"
 #include "special_button.h"
 #include "signalcurve.h"
-
+#include "edf_annot_list.h"
 
 
 class UI_Mainwindow;
diff --git a/pagetime_dialog.cpp b/pagetime_dialog.cpp
index 684b20a..d09c5ea 100644
--- a/pagetime_dialog.cpp
+++ b/pagetime_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/pagetime_dialog.h b/pagetime_dialog.h
index 2fa7bb2..d9f0aef 100644
--- a/pagetime_dialog.h
+++ b/pagetime_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/popup_save_cancelwindow.cpp b/popup_save_cancelwindow.cpp
index 06813d5..7ffc428 100644
--- a/popup_save_cancelwindow.cpp
+++ b/popup_save_cancelwindow.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/popup_save_cancelwindow.h b/popup_save_cancelwindow.h
index 9f2a542..4c2e64e 100644
--- a/popup_save_cancelwindow.h
+++ b/popup_save_cancelwindow.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/print_to_bdf.cpp b/print_to_bdf.cpp
index 782f089..7413069 100644
--- a/print_to_bdf.cpp
+++ b/print_to_bdf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -41,10 +41,12 @@ void print_screen_to_bdf(UI_Mainwindow *mainwindow)
       temp=0,
       bdfplus=0,
       tallen,
-      annotationlist_nr=0,
+      annotationlist_nr=-1,
       annotations_left=1,
       add_one_sec=0,
       annot_smp_per_record=16,
+      annot_list_sz=0,
+      annot_cnt=0,
       type,
       len;
 
@@ -92,9 +94,11 @@ void print_screen_to_bdf(UI_Mainwindow *mainwindow)
           unsigned char four[4];
         } var;
 
-struct annotationblock *annotations_pntr;
+  struct date_time_struct date_time;
 
-struct date_time_struct date_time;
+  struct annotation_list *annot_list=NULL;
+
+  struct annotationblock *annot_ptr=NULL;
 
 /////////////////////////////////////////////////////////////////////////
 
@@ -102,8 +106,6 @@ struct date_time_struct date_time;
   signalcomp = mainwindow->signalcomp;
   viewbuf = mainwindow->viewbuf;
 
-  annotations_pntr = mainwindow->annotationlist[0];
-
   if((!mainwindow->files_open)||(!signalcomps))
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Print to BDF", "Put a signal on the screen and try again.");
@@ -1121,44 +1123,23 @@ struct date_time_struct date_time;
 
       tallen += 3;
 
-      if(annotations_left)
-      {
-        if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[annotationlist_nr]->utc_starttime) * TIME_DIMENSION;
-        }
-
-        if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_OFFSET)
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->utc_starttime) * TIME_DIMENSION;
-        }
-
-        if((mainwindow->viewtime_sync==VIEWTIME_UNSYNCED) || (mainwindow->viewtime_sync==VIEWTIME_USER_DEF_SYNCED))
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->utc_starttime) * TIME_DIMENSION;
-          annot_difftime += (mainwindow->edfheaderlist[annotationlist_nr]->viewtime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->viewtime);
-        }
-
-        if(annotationlist_nr != mainwindow->sel_viewtime)
-        {
-          annot_difftime -= mainwindow->edfheaderlist[mainwindow->sel_viewtime]->starttime_offset;
-          annot_difftime += mainwindow->edfheaderlist[annotationlist_nr]->starttime_offset;
-        }
-      }
-
       while(annotations_left)
       {
-        while(!annotations_pntr)
+        while((annot_list_sz < 1) || (annot_cnt >= annot_list_sz))
         {
           annotationlist_nr++;
           if(annotationlist_nr>=mainwindow->files_open)
           {
             annotations_left = 0;
-            annotations_pntr = NULL;
-
+            annot_list = NULL;
+            annot_list_sz = 0;
             break;
           }
-          annotations_pntr = mainwindow->annotationlist[annotationlist_nr];
+          annot_list = &mainwindow->edfheaderlist[annotationlist_nr]->annot_list;
+
+          annot_list_sz = edfplus_annotation_size(annot_list);
+
+          annot_cnt = 0;
 
           if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)
           {
@@ -1185,9 +1166,11 @@ struct date_time_struct date_time;
 
         if(!annotations_left)  break;
 
-        if(annotations_pntr)
+        if((annot_list != NULL) && (annot_cnt < annot_list_sz))
         {
-          l_temp = annotations_pntr->onset - annot_difftime;
+          annot_ptr = edfplus_annotation_get_item(annot_list, annot_cnt);
+
+          l_temp = annot_ptr->onset - annot_difftime;
 
           if((l_temp >= 0LL) && (l_temp < (mainwindow->pagetime + TIME_DIMENSION)))
           {
@@ -1195,30 +1178,30 @@ struct date_time_struct date_time;
             (int)(l_temp / TIME_DIMENSION),
             (int)(l_temp % TIME_DIMENSION));
 
-            if(annotations_pntr->duration[0]!=0)
+            if(annot_ptr->duration[0]!=0)
             {
               fputc(21, outputfile);
               tallen++;
 
-              tallen += fprintf(outputfile, "%s", annotations_pntr->duration);
+              tallen += fprintf(outputfile, "%s", annot_ptr->duration);
             }
 
             fputc(20, outputfile);
             tallen++;
 
-            tallen += fprintf(outputfile, "%s", annotations_pntr->annotation);
+            tallen += fprintf(outputfile, "%s", annot_ptr->annotation);
 
             fputc(20, outputfile);
             fputc(0, outputfile);
             tallen += 2;
 
-            annotations_pntr = annotations_pntr->next_annotation;
+            annot_cnt++;
 
             break;
           }
           else
           {
-            annotations_pntr = annotations_pntr->next_annotation;
+            annot_cnt++;
 
             continue;
           }
diff --git a/print_to_bdf.h b/print_to_bdf.h
index 117b07b..288ec5b 100644
--- a/print_to_bdf.h
+++ b/print_to_bdf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -48,6 +48,8 @@
 #include "mainwindow.h"
 #include "filter.h"
 #include "utc_date_time.h"
+#include "edf_helper.h"
+#include "edf_annot_list.h"
 
 #include "third_party/fidlib/fidlib.h"
 
diff --git a/print_to_edf.cpp b/print_to_edf.cpp
index ef10cb1..87b7ec4 100644
--- a/print_to_edf.cpp
+++ b/print_to_edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -41,10 +41,12 @@ void print_screen_to_edf(UI_Mainwindow *mainwindow)
       temp=0,
       edfplus=0,
       tallen,
-      annotationlist_nr=0,
+      annotationlist_nr=-1,
       annotations_left=1,
       add_one_sec=0,
       annot_smp_per_record=16,
+      annot_list_sz=0,
+      annot_cnt=0,
       type,
       len;
 
@@ -83,9 +85,11 @@ void print_screen_to_edf(UI_Mainwindow *mainwindow)
           unsigned char two[2];
         } null_bytes[MAXSIGNALS];
 
-struct annotationblock *annotations_pntr;
+  struct date_time_struct date_time;
 
-struct date_time_struct date_time;
+  struct annotation_list *annot_list=NULL;
+
+  struct annotationblock *annot_ptr=NULL;
 
 /////////////////////////////////////////////////////////////////////////
 
@@ -93,8 +97,6 @@ struct date_time_struct date_time;
   signalcomp = mainwindow->signalcomp;
   viewbuf = mainwindow->viewbuf;
 
-  annotations_pntr = mainwindow->annotationlist[0];
-
   if((!mainwindow->files_open)||(!signalcomps))
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Print to EDF", "Put a signal on the screen and try again.");
@@ -118,6 +120,8 @@ struct date_time_struct date_time;
       return;
     }
 
+    annot_list = &mainwindow->edfheaderlist[i]->annot_list;
+
     if(mainwindow->edfheaderlist[i]->edfplus)
     {
       edfplus = 1;
@@ -1079,44 +1083,23 @@ struct date_time_struct date_time;
 
       tallen += 3;
 
-      if(annotations_left)
-      {
-        if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[annotationlist_nr]->utc_starttime) * TIME_DIMENSION;
-        }
-
-        if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_OFFSET)
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->utc_starttime) * TIME_DIMENSION;
-        }
-
-        if((mainwindow->viewtime_sync==VIEWTIME_UNSYNCED) || (mainwindow->viewtime_sync==VIEWTIME_USER_DEF_SYNCED))
-        {
-          annot_difftime = (referencetime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->utc_starttime) * TIME_DIMENSION;
-          annot_difftime += (mainwindow->edfheaderlist[annotationlist_nr]->viewtime - mainwindow->edfheaderlist[mainwindow->sel_viewtime]->viewtime);
-        }
-
-        if(annotationlist_nr != mainwindow->sel_viewtime)
-        {
-          annot_difftime -= mainwindow->edfheaderlist[mainwindow->sel_viewtime]->starttime_offset;
-          annot_difftime += mainwindow->edfheaderlist[annotationlist_nr]->starttime_offset;
-        }
-      }
-
       while(annotations_left)
       {
-        while(!annotations_pntr)
+        while((annot_list_sz < 1) || (annot_cnt >= annot_list_sz))
         {
           annotationlist_nr++;
           if(annotationlist_nr>=mainwindow->files_open)
           {
             annotations_left = 0;
-            annotations_pntr = NULL;
-
+            annot_list = NULL;
+            annot_list_sz = 0;
             break;
           }
-          annotations_pntr = mainwindow->annotationlist[annotationlist_nr];
+          annot_list = &mainwindow->edfheaderlist[annotationlist_nr]->annot_list;
+
+          annot_list_sz = edfplus_annotation_size(annot_list);
+
+          annot_cnt = 0;
 
           if(mainwindow->viewtime_sync==VIEWTIME_SYNCED_ABSOLUT)
           {
@@ -1143,9 +1126,11 @@ struct date_time_struct date_time;
 
         if(!annotations_left)  break;
 
-        if(annotations_pntr)
+        if((annot_list != NULL) && (annot_cnt < annot_list_sz))
         {
-          l_temp = annotations_pntr->onset - annot_difftime;
+          annot_ptr = edfplus_annotation_get_item(annot_list, annot_cnt);
+
+          l_temp = annot_ptr->onset - annot_difftime;
 
           if((l_temp >= 0LL) && (l_temp < (mainwindow->pagetime + TIME_DIMENSION)))
           {
@@ -1153,30 +1138,30 @@ struct date_time_struct date_time;
             (int)(l_temp / TIME_DIMENSION),
             (int)(l_temp % TIME_DIMENSION));
 
-            if(annotations_pntr->duration[0]!=0)
+            if(annot_ptr->duration[0]!=0)
             {
               fputc(21, outputfile);
               tallen++;
 
-              tallen += fprintf(outputfile, "%s", annotations_pntr->duration);
+              tallen += fprintf(outputfile, "%s", annot_ptr->duration);
             }
 
             fputc(20, outputfile);
             tallen++;
 
-            tallen += fprintf(outputfile, "%s", annotations_pntr->annotation);
+            tallen += fprintf(outputfile, "%s", annot_ptr->annotation);
 
             fputc(20, outputfile);
             fputc(0, outputfile);
             tallen += 2;
 
-            annotations_pntr = annotations_pntr->next_annotation;
+            annot_cnt++;
 
             break;
           }
           else
           {
-            annotations_pntr = annotations_pntr->next_annotation;
+            annot_cnt++;
 
             continue;
           }
diff --git a/print_to_edf.h b/print_to_edf.h
index 5e7469b..3d4aba5 100644
--- a/print_to_edf.h
+++ b/print_to_edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -48,6 +48,8 @@
 #include "mainwindow.h"
 #include "filter.h"
 #include "utc_date_time.h"
+#include "edf_helper.h"
+#include "edf_annot_list.h"
 
 #include "third_party/fidlib/fidlib.h"
 
diff --git a/ravg_filter.cpp b/ravg_filter.cpp
index ebe8531..a251573 100644
--- a/ravg_filter.cpp
+++ b/ravg_filter.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/ravg_filter.h b/ravg_filter.h
index b72c8d5..d6e658c 100644
--- a/ravg_filter.h
+++ b/ravg_filter.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/raw2edf.cpp b/raw2edf.cpp
index 25eab1c..3b9fc79 100644
--- a/raw2edf.cpp
+++ b/raw2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/raw2edf.h b/raw2edf.h
index 31b6f1e..0528af8 100644
--- a/raw2edf.h
+++ b/raw2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/read_write_settings.cpp b/read_write_settings.cpp
index fdbd8de..d65f24e 100644
--- a/read_write_settings.cpp
+++ b/read_write_settings.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -1673,7 +1673,7 @@ void UI_Mainwindow::read_general_settings()
 
 void UI_Mainwindow::write_settings()
 {
-  int i, len;
+  int i;
 
   char cfg_path[MAX_PATH_LENGTH],
        str[1024];
@@ -1789,43 +1789,35 @@ void UI_Mainwindow::write_settings()
     fprintf(cfgfile, "      <show_baselines>%i</show_baselines>\n",
                     show_baselines);
 
-    fprintf(cfgfile, "      <clip_to_pane>%i</clip_to_pane>\n",
+    fprintf(cfgfile, "    </colors>\n");
+
+    fprintf(cfgfile, "    <clip_to_pane>%i</clip_to_pane>\n",
                     clip_to_pane);
 
-    fprintf(cfgfile, "      <auto_reload_mtg>%i</auto_reload_mtg>\n",
+    fprintf(cfgfile, "    <auto_reload_mtg>%i</auto_reload_mtg>\n",
                     auto_reload_mtg);
 
-    fprintf(cfgfile, "      <read_biosemi_status_signal>%i</read_biosemi_status_signal>\n",
+    fprintf(cfgfile, "    <read_biosemi_status_signal>%i</read_biosemi_status_signal>\n",
                     read_biosemi_status_signal);
 
-    fprintf(cfgfile, "      <read_nk_trigger_signal>%i</read_nk_trigger_signal>\n",
+    fprintf(cfgfile, "    <read_nk_trigger_signal>%i</read_nk_trigger_signal>\n",
                     read_nk_trigger_signal);
 
-    fprintf(cfgfile, "      <use_threads>%i</use_threads>\n",
+    fprintf(cfgfile, "    <use_threads>%i</use_threads>\n",
                     use_threads);
 
 #ifdef Q_OS_WIN32
-    __mingw_fprintf(cfgfile, "      <maxfilesize_to_readin_annotations>%lli</maxfilesize_to_readin_annotations>\n",
+    __mingw_fprintf(cfgfile, "    <maxfilesize_to_readin_annotations>%lli</maxfilesize_to_readin_annotations>\n",
                     maxfilesize_to_readin_annotations);
 #else
-    fprintf(cfgfile, "      <maxfilesize_to_readin_annotations>%lli</maxfilesize_to_readin_annotations>\n",
+    fprintf(cfgfile, "    <maxfilesize_to_readin_annotations>%lli</maxfilesize_to_readin_annotations>\n",
                     maxfilesize_to_readin_annotations);
 #endif
 
-    len = strlen(path);
-    for(i=len-1; i>=0; i--)
-    {
-      if((path[i] == '/')||(path[i] == '\\'))
-      {
-        break;
-      }
-    }
-    path[i+1] = 0;
-
-    fprintf(cfgfile, "    </colors>\n    <pixelsizefactor>%.10f</pixelsizefactor>\n    <auto_dpi>%i</auto_dpi>\n    <x_pixelsizefactor>%.10f</x_pixelsizefactor>\n    <recent_dir>",
+    fprintf(cfgfile, "    <pixelsizefactor>%.10f</pixelsizefactor>\n    <auto_dpi>%i</auto_dpi>\n    <x_pixelsizefactor>%.10f</x_pixelsizefactor>\n    <recent_dir>",
                      pixelsizefactor, auto_dpi, x_pixelsizefactor);
 
-    xml_fwrite_encode_entity(cfgfile, path);
+    xml_fwrite_encode_entity(cfgfile, recent_opendir);
 
     fprintf(cfgfile, "</recent_dir>\n");
 
diff --git a/reduce_signals.cpp b/reduce_signals.cpp
index 1e699ce..e9c0de0 100644
--- a/reduce_signals.cpp
+++ b/reduce_signals.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -71,7 +71,7 @@ UI_ReduceSignalsWindow::UI_ReduceSignalsWindow(QWidget *w_parent)
   label6->setText("Anti-aliasing filter order");
 
   radioButton1 = new QRadioButton("whole duration", myobjectDialog);
-  radioButton1->setGeometry(485, 299, 100, 25);
+  radioButton1->setGeometry(485, 299, 120, 25);
   radioButton1->setChecked(true);
   radioButton1->setEnabled(false);
 
@@ -100,7 +100,7 @@ UI_ReduceSignalsWindow::UI_ReduceSignalsWindow(QWidget *w_parent)
   spinBox4 = new QSpinBox(myobjectDialog);
   spinBox4->setGeometry(595, 232, 100, 25);
   spinBox4->setRange(1, REDUCER_MAX_AA_FILTERS + 1);
-  spinBox4->setValue(REDUCER_MAX_AA_FILTERS + 1);
+  spinBox4->setValue(REDUCER_MAX_AA_FILTERS);
   spinBox4->setEnabled(false);
 
   SignalsTablewidget = new QTableWidget(myobjectDialog);
@@ -555,15 +555,16 @@ void UI_ReduceSignalsWindow::StartConversion()
       timestamp_digits=0,
       timestamp_decimals=0,
       annot_len,
+      annot_cnt=0,
       tallen=0,
       len,
-      annot_cnt,
       annots_per_datrec=0,
       smplrt,
       tmp,
       val,
       progress_steps,
-      datrecs_processed;
+      datrecs_processed,
+      annot_list_sz=0;
 
   char *readbuf=NULL,
        scratchpad[256];
@@ -578,10 +579,11 @@ void UI_ReduceSignalsWindow::StartConversion()
 
   struct date_time_struct dts;
 
-  struct annotationblock *new_annot_list=NULL,
-                         *root_new_annot_list=NULL,
+  struct annotation_list new_annot_list,
                          *annot_list=NULL;
 
+  struct annotationblock *annot_ptr=NULL;
+
   union {
           unsigned int one;
           signed int one_signed;
@@ -590,6 +592,8 @@ void UI_ReduceSignalsWindow::StartConversion()
           unsigned char four[4];
         } var;
 
+  memset(&new_annot_list, 0, sizeof(struct annotation_list));
+
   QProgressDialog progress("Processing file...", "Abort", 0, 1);
   progress.setWindowModality(Qt::WindowModal);
   progress.setMinimumDuration(200);
@@ -622,8 +626,6 @@ void UI_ReduceSignalsWindow::StartConversion()
 
   annot_smp_per_record = 0;
 
-  annot_cnt = 0;
-
   aa_filter_order = spinBox4->value() - 1;
 
   time_diff = (long long)(spinBox1->value() - 1) * edfhdr->long_data_record_duration;
@@ -651,67 +653,67 @@ void UI_ReduceSignalsWindow::StartConversion()
 
   if(edfhdr->edfplus || edfhdr->bdfplus)
   {
-    timestamp_decimals = get_tal_timestamp_decimal_cnt(edfhdr);
+    timestamp_decimals = edfplus_annotation_get_tal_timestamp_decimal_cnt(edfhdr);
     if(timestamp_decimals < 0)
     {
       showpopupmessage("Error", "Internal error, get_tal_timestamp_decimal_cnt(");
       goto END_1;
     }
 
-    timestamp_digits = get_tal_timestamp_digit_cnt(edfhdr);
+    timestamp_digits = edfplus_annotation_get_tal_timestamp_digit_cnt(edfhdr);
     if(timestamp_digits < 0)
     {
       showpopupmessage("Error", "Internal error, get_tal_timestamp_digit_cnt(");
       goto END_1;
     }
 
-    annot_list = mainwindow->annotationlist[file_num];
+    annot_list = &mainwindow->edfheaderlist[file_num]->annot_list;
 
-    while(annot_list != NULL)
+    annot_list_sz = edfplus_annotation_size(annot_list);
+
+    for(i=0; i<annot_list_sz; i++)
     {
-      l_temp = annot_list->onset - time_diff;
+      annot_ptr = edfplus_annotation_get_item(annot_list, i);
+
+      l_temp = annot_ptr->onset - time_diff;
 
       if((l_temp >= 0LL) && (l_temp <= endtime))
       {
-        annot_cnt++;
-
-        edfplus_annotation_add_copy(&new_annot_list, annot_list);
+        edfplus_annotation_add_item(&new_annot_list, *(edfplus_annotation_get_item(annot_list, i)));
       }
-
-      annot_list = annot_list->next_annotation;
     }
 
-    annot_list = new_annot_list;
-
-    root_new_annot_list = new_annot_list;
-
     new_starttime = edfhdr->utc_starttime + ((time_diff + edfhdr->starttime_offset) / TIME_DIMENSION);
 
     onset_diff = (new_starttime - edfhdr->utc_starttime) * TIME_DIMENSION;
 
-    while(annot_list != NULL)
+    annot_list_sz = edfplus_annotation_size(&new_annot_list);
+
+    if(annot_list_sz > 0)
     {
-      annot_list->onset -= onset_diff;
+      for(i=0; i<annot_list_sz; i++)
+      {
+        annot_ptr = edfplus_annotation_get_item(&new_annot_list, i);
 
-      annot_list = annot_list->next_annotation;
-    }
+        annot_ptr->onset -= onset_diff;
+      }
 
-    edfplus_annotation_sort(&new_annot_list);
+      edfplus_annotation_sort(&new_annot_list, NULL);
 
-    annots_per_datrec = annot_cnt / datarecords;
+      annots_per_datrec = annot_list_sz / datarecords;
 
-    if(annot_cnt % datarecords)
-    {
-      annots_per_datrec++;
+      if(annot_list_sz % datarecords)
+      {
+        annots_per_datrec++;
+      }
     }
-
-    annot_len = get_max_annotation_strlen(&new_annot_list);
-
-    if(!annot_cnt)
+    else
     {
       annots_per_datrec = 0;
     }
 
+    annot_len = edfplus_annotation_get_max_annotation_strlen(&new_annot_list);
+
     annot_recordsize = (annot_len * annots_per_datrec) + timestamp_digits + timestamp_decimals + 4;
 
     if(timestamp_decimals)
@@ -1200,15 +1202,17 @@ void UI_ReduceSignalsWindow::StartConversion()
 
       tallen += 3;
 
-      if(new_annot_list != NULL)
+      if(annot_cnt < annot_list_sz)
       {
         for(i=0; i<annots_per_datrec; i++)
         {
-          if(new_annot_list != NULL)
+          if(annot_cnt < annot_list_sz)
           {
+            annot_ptr = edfplus_annotation_get_item(&new_annot_list, annot_cnt);
+
             len = snprintf(scratchpad, 256, "%+i.%07i",
-            (int)(new_annot_list->onset / TIME_DIMENSION),
-            (int)(new_annot_list->onset % TIME_DIMENSION));
+            (int)(annot_ptr->onset / TIME_DIMENSION),
+            (int)(annot_ptr->onset % TIME_DIMENSION));
 
             for(j=0; j<7; j++)
             {
@@ -1237,24 +1241,24 @@ void UI_ReduceSignalsWindow::StartConversion()
 
             tallen += len;
 
-            if(new_annot_list->duration[0]!=0)
+            if(annot_ptr->duration[0]!=0)
             {
               fputc(21, outputfile);
               tallen++;
 
-              tallen += fprintf(outputfile, "%s", new_annot_list->duration);
+              tallen += fprintf(outputfile, "%s", annot_ptr->duration);
             }
 
             fputc(20, outputfile);
             tallen++;
 
-            tallen += fprintf(outputfile, "%s", new_annot_list->annotation);
+            tallen += fprintf(outputfile, "%s", annot_ptr->annotation);
 
             fputc(20, outputfile);
             fputc(0, outputfile);
             tallen += 2;
 
-            new_annot_list = new_annot_list->next_annotation;
+            annot_cnt--;
           }
         }
       }
@@ -1311,9 +1315,7 @@ END_1:
 
   edfhdr = NULL;
 
-  edfplus_annotation_delete_list(&root_new_annot_list);
-
-  root_new_annot_list = NULL;
+  edfplus_annotation_empty_list(&new_annot_list);
 
   SignalsTablewidget->setRowCount(0);
 }
@@ -1330,7 +1332,7 @@ void UI_ReduceSignalsWindow::showpopupmessage(const char *str1, const char *str2
 void UI_ReduceSignalsWindow::helpbuttonpressed()
 {
 #ifdef Q_OS_LINUX
-  QDesktopServices::openUrl(QUrl("file:///usr/share/doc/edfbrowser/manual.html#Header_editor"));
+  QDesktopServices::openUrl(QUrl("file:///usr/share/doc/edfbrowser/manual.html#Reduce_signals"));
 #endif
 
 #ifdef Q_OS_WIN32
@@ -1338,7 +1340,7 @@ void UI_ReduceSignalsWindow::helpbuttonpressed()
 
   strcpy(p_path, "file:///");
   strcat(p_path, mainwindow->specialFolder(CSIDL_PROGRAM_FILES).toLocal8Bit().data());
-  strcat(p_path, "\\EDFbrowser\\manual.html#Header_editor");
+  strcat(p_path, "\\EDFbrowser\\manual.html#Reduce_signals");
   QDesktopServices::openUrl(QUrl(p_path));
 #endif
 }
diff --git a/reduce_signals.h b/reduce_signals.h
index 482e243..4eecc8f 100644
--- a/reduce_signals.h
+++ b/reduce_signals.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -62,6 +62,7 @@
 #include "active_file_chooser.h"
 #include "edf_annot_list.h"
 #include "ravg_filter.h"
+#include "edf_helper.h"
 
 
 #define REDUCER_MAX_AA_FILTERS   4
diff --git a/save_annots.cpp b/save_annots.cpp
index b40e0b4..22f0d31 100644
--- a/save_annots.cpp
+++ b/save_annots.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -31,9 +31,9 @@
 
 
 
-int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrblock *hdr, struct annotationblock *annotlist)
+int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrblock *hdr)
 {
-  int i, j, k, n, p=0,
+  int i, j, k, n, p=0, r,
       new_edfsignals=0,
       signalslist[MAXSIGNALS],
       datarecords,
@@ -44,7 +44,8 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
       timestamp_digits,
       annots_per_datrec,
       space,
-      progress_steps;
+      progress_steps,
+      annot_cnt;
 
   char *readbuf,
        scratchpad[256],
@@ -54,8 +55,6 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
 
   FILE *inputfile;
 
-  struct annotationblock *annot;
-
   inputfile = hdr->file_hdl;
 
   for(i=0; i<hdr->edfsignals; i++)
@@ -72,23 +71,25 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
 
   time = (hdr->datarecords * hdr->long_data_record_duration) / TIME_DIMENSION;
 
-  timestamp_decimals = get_tal_timestamp_decimal_cnt(hdr);
+  timestamp_decimals = edfplus_annotation_get_tal_timestamp_decimal_cnt(hdr);
   if(timestamp_decimals < 0)
   {
     return(1);
   }
 
-  timestamp_digits = get_tal_timestamp_digit_cnt(hdr);
+  timestamp_digits = edfplus_annotation_get_tal_timestamp_digit_cnt(hdr);
   if(timestamp_digits < 0)
   {
     return(1);
   }
 
-  annot = annotlist;
+  struct annotation_list *annot_list = &hdr->annot_list;
+
+  struct annotationblock *annot_ptr;
 
-  annot_len = get_max_annotation_strlen(&annot);
+  annot_len = edfplus_annotation_get_max_annotation_strlen(annot_list);
 
-  i = edfplus_annotation_count(&annot);
+  i = edfplus_annotation_size(annot_list);
 
   annots_per_datrec = i / datarecords;
 
@@ -414,10 +415,12 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
 
   fseeko(inputfile, (long long)(hdr->hdrsize), SEEK_SET);
 
-  annot = annotlist;
-
   time = hdr->starttime_offset;
 
+  annot_cnt = edfplus_annotation_size(annot_list);
+
+  r = 0;
+
   for(k=0; k<datarecords; k++)
   {
     if(!(k%progress_steps))
@@ -511,26 +514,32 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
     annot_buf[p++] = 20;
     annot_buf[p++] = 0;
 
-    if(annot!=NULL)
+    if(r < annot_cnt)
     {
       for(i=0; i<annots_per_datrec; i++)
       {
-        if(annot!=NULL)
+        if(r < annot_cnt)
         {
-          if(annot->onset<0)
+          annot_ptr = edfplus_annotation_get_item(annot_list, r);
+
+          if(annot_ptr == NULL)  break;
+
+          r++;
+
+          if(annot_ptr->onset<0)
           {
 #ifdef Q_OS_WIN32
-            p += __mingw_snprintf(annot_buf + p, 20, "-%lli.%07lli", -(annot->onset / TIME_DIMENSION), -(annot->onset % TIME_DIMENSION));
+            p += __mingw_snprintf(annot_buf + p, 20, "-%lli.%07lli", -(annot_ptr->onset / TIME_DIMENSION), -(annot_ptr->onset % TIME_DIMENSION));
 #else
-            p += snprintf(annot_buf + p, 20, "-%lli.%07lli", -(annot->onset / TIME_DIMENSION), -(annot->onset % TIME_DIMENSION));
+            p += snprintf(annot_buf + p, 20, "-%lli.%07lli", -(annot_ptr->onset / TIME_DIMENSION), -(annot_ptr->onset % TIME_DIMENSION));
 #endif
           }
           else
           {
 #ifdef Q_OS_WIN32
-            p += __mingw_snprintf(annot_buf + p, 20, "+%lli.%07lli", annot->onset / TIME_DIMENSION, annot->onset % TIME_DIMENSION);
+            p += __mingw_snprintf(annot_buf + p, 20, "+%lli.%07lli", annot_ptr->onset / TIME_DIMENSION, annot_ptr->onset % TIME_DIMENSION);
 #else
-            p += snprintf(annot_buf + p, 20, "+%lli.%07lli", annot->onset / TIME_DIMENSION, annot->onset % TIME_DIMENSION);
+            p += snprintf(annot_buf + p, 20, "+%lli.%07lli", annot_ptr->onset / TIME_DIMENSION, annot_ptr->onset % TIME_DIMENSION);
 #endif
           }
 
@@ -552,21 +561,19 @@ int save_annotations(UI_Mainwindow *mainwindow, FILE *outputfile, struct edfhdrb
             }
           }
 
-          if(annot->duration[0])
+          if(annot_ptr->duration[0])
           {
             annot_buf[p++] = 21;
 
-            p += sprintf(annot_buf + p, "%s", annot->duration);
+            p += sprintf(annot_buf + p, "%s", annot_ptr->duration);
           }
 
           annot_buf[p++] = 20;
 
-          p += sprintf(annot_buf + p, "%s", annot->annotation);
+          p += sprintf(annot_buf + p, "%s", annot_ptr->annotation);
 
           annot_buf[p++] = 20;
           annot_buf[p++] = 0;
-
-          annot = annot->next_annotation;
         }
       }
     }
diff --git a/save_annots.h b/save_annots.h
index ab33459..8416446 100644
--- a/save_annots.h
+++ b/save_annots.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -46,12 +46,13 @@
 #include "mainwindow.h"
 #include "utils.h"
 #include "edf_annot_list.h"
+#include "edf_helper.h"
 
 
 
 
 
-int save_annotations(UI_Mainwindow *, FILE *, struct edfhdrblock *, struct annotationblock *);
+int save_annotations(UI_Mainwindow *, FILE *, struct edfhdrblock *);
 
 
 
diff --git a/save_montage_dialog.cpp b/save_montage_dialog.cpp
index 68eba6c..f5c3d5e 100644
--- a/save_montage_dialog.cpp
+++ b/save_montage_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -150,6 +150,10 @@ void UI_SaveMontagewindow::SaveButtonClicked()
       {
         fprintf(mtgfile, "    <spike_filter_cnt>%i</spike_filter_cnt>\n", 1);
       }
+      else
+      {
+        fprintf(mtgfile, "    <spike_filter_cnt>%i</spike_filter_cnt>\n", 0);
+      }
 
       fprintf(mtgfile, "    <filter_cnt>%i</filter_cnt>\n", mainwindow->signalcomp[i]->filter_cnt);
 
diff --git a/save_montage_dialog.h b/save_montage_dialog.h
index 0c2967b..87165eb 100644
--- a/save_montage_dialog.h
+++ b/save_montage_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/scp_ecg2edf.cpp b/scp_ecg2edf.cpp
index 1ac040b..ad19da8 100644
--- a/scp_ecg2edf.cpp
+++ b/scp_ecg2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/scp_ecg2edf.h b/scp_ecg2edf.h
index 2f32a74..79993c5 100644
--- a/scp_ecg2edf.h
+++ b/scp_ecg2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/show_actual_montage_dialog.cpp b/show_actual_montage_dialog.cpp
index 73dd5ce..7425f17 100644
--- a/show_actual_montage_dialog.cpp
+++ b/show_actual_montage_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/show_actual_montage_dialog.h b/show_actual_montage_dialog.h
index 12efad0..a8b7763 100644
--- a/show_actual_montage_dialog.h
+++ b/show_actual_montage_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/show_edf_hdr.cpp b/show_edf_hdr.cpp
index 92e6c03..4bdac66 100644
--- a/show_edf_hdr.cpp
+++ b/show_edf_hdr.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/show_edf_hdr.h b/show_edf_hdr.h
index 27956ad..57dba79 100644
--- a/show_edf_hdr.h
+++ b/show_edf_hdr.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/signal_chooser.cpp b/signal_chooser.cpp
index 441fa19..3a1fc97 100644
--- a/signal_chooser.cpp
+++ b/signal_chooser.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/signal_chooser.h b/signal_chooser.h
index e9b653b..b2b2fce 100644
--- a/signal_chooser.h
+++ b/signal_chooser.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/signalcurve.cpp b/signalcurve.cpp
index ada6bd6..d2babaa 100644
--- a/signalcurve.cpp
+++ b/signalcurve.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -596,7 +596,7 @@ void SignalCurve::print_to_ascii()
   get_directory_from_path(recent_savedir, path, SC_MAX_PATH_LEN);
 
   outputfile = fopen(path, "wb");
-  if(path == NULL)
+  if(outputfile == NULL)
   {
     QMessageBox messagewindow(QMessageBox::Critical, "Error", "Can not open outputfile for writing.");
     messagewindow.exec();
diff --git a/signalcurve.h b/signalcurve.h
index fa08377..1243b87 100644
--- a/signalcurve.h
+++ b/signalcurve.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/signals_dialog.cpp b/signals_dialog.cpp
index 10dd572..0846513 100644
--- a/signals_dialog.cpp
+++ b/signals_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/signals_dialog.h b/signals_dialog.h
index 61f16e7..08e6303 100644
--- a/signals_dialog.h
+++ b/signals_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/special_button.cpp b/special_button.cpp
index ade79bd..e3708ee 100644
--- a/special_button.cpp
+++ b/special_button.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/special_button.h b/special_button.h
index 49235bf..0283bf8 100644
--- a/special_button.h
+++ b/special_button.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spectrum_dock.cpp b/spectrum_dock.cpp
index 80f4c90..de19c0a 100644
--- a/spectrum_dock.cpp
+++ b/spectrum_dock.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spectrum_dock.h b/spectrum_dock.h
index 8b6bc1c..37aa11a 100644
--- a/spectrum_dock.h
+++ b/spectrum_dock.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spectrumanalyzer.cpp b/spectrumanalyzer.cpp
index 26bd5a1..4933c80 100644
--- a/spectrumanalyzer.cpp
+++ b/spectrumanalyzer.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spectrumanalyzer.h b/spectrumanalyzer.h
index af74b1c..bddd996 100644
--- a/spectrumanalyzer.h
+++ b/spectrumanalyzer.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spike_filter.cpp b/spike_filter.cpp
index c860c89..b65400e 100644
--- a/spike_filter.cpp
+++ b/spike_filter.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spike_filter.h b/spike_filter.h
index 7701b6a..9e47b83 100644
--- a/spike_filter.h
+++ b/spike_filter.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spike_filter_dialog.cpp b/spike_filter_dialog.cpp
index 12a5020..1d5ac8e 100644
--- a/spike_filter_dialog.cpp
+++ b/spike_filter_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/spike_filter_dialog.h b/spike_filter_dialog.h
index efb6fc4..f38b192 100644
--- a/spike_filter_dialog.h
+++ b/spike_filter_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/statistics_dialog.cpp b/statistics_dialog.cpp
index adb6ec9..bb74ecd 100644
--- a/statistics_dialog.cpp
+++ b/statistics_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/statistics_dialog.h b/statistics_dialog.h
index 32295c8..01f6883 100644
--- a/statistics_dialog.h
+++ b/statistics_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/unisens2edf.cpp b/unisens2edf.cpp
index ffe36c4..1862756 100644
--- a/unisens2edf.cpp
+++ b/unisens2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -2030,7 +2030,11 @@ int UI_UNISENS2EDFwindow::get_signalparameters_from_BIN_attributes(struct xml_ha
     }
   }
 
-  if(!xml_get_attribute_of_element(xml_hdl, "baseline", str, 255) < 0)
+  if(xml_get_attribute_of_element(xml_hdl, "baseline", str, 255) < 0)
+  {
+    baseline[file_nr] = 0LL;
+  }
+  else
   {
     if(strlen(str) < 1)
     {
@@ -2040,12 +2044,12 @@ int UI_UNISENS2EDFwindow::get_signalparameters_from_BIN_attributes(struct xml_ha
 
     baseline[file_nr] = strtoll(str, NULL, 0);
   }
-  else
+
+  if(xml_get_attribute_of_element(xml_hdl, "adcZero", str, 255) < 0)
   {
-    baseline[file_nr] = 0LL;
+    adczero[file_nr] = 0LL;
   }
-
-  if(!xml_get_attribute_of_element(xml_hdl, "adcZero", str, 255) < 0)
+  else
   {
     if(strlen(str) < 1)
     {
@@ -2055,10 +2059,6 @@ int UI_UNISENS2EDFwindow::get_signalparameters_from_BIN_attributes(struct xml_ha
 
     adczero[file_nr] = strtoll(str, NULL, 0);
   }
-  else
-  {
-    adczero[file_nr] = 0LL;
-  }
 
   if(xml_get_attribute_of_element(xml_hdl, "lsbValue", str, 255) < 0)
   {
diff --git a/unisens2edf.h b/unisens2edf.h
index 4132d8e..0bdebef 100644
--- a/unisens2edf.h
+++ b/unisens2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/utc_date_time.c b/utc_date_time.c
index 846b8ea..efb6ef7 100644
--- a/utc_date_time.c
+++ b/utc_date_time.c
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/utc_date_time.h b/utc_date_time.h
index 2d2f7d5..d27ff63 100644
--- a/utc_date_time.h
+++ b/utc_date_time.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/utils.c b/utils.c
index e2cf61d..6532ff3 100644
--- a/utils.c
+++ b/utils.c
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/utils.h b/utils.h
index 71917cc..13a739f 100644
--- a/utils.h
+++ b/utils.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/version.txt b/version.txt
index 65f087f..fa73b17 100644
--- a/version.txt
+++ b/version.txt
@@ -1,4 +1,29 @@
 
+ version 1.59      May 8, 2017
+ --------------
+
+ - Improved memory management of annotations and annotations sorting algorithm,
+   which results in faster processing when a file contains many annotations (> 10000).
+
+ - Fixed a bug with the realtime playback function that caused to playback only the
+   first file when multiple files were opened.
+
+ - Fixed a bug in the Timesync -> Jump to dialog.
+
+ - Bugfix in MIT (PhysioBank) converter: use default gain of 200 when adc gain is set to 0.
+   From now on, all PhysioBank files can be converted to EDF+ including events/annotations.
+
+ - Don't update the onset time in the annotation editor when changing file position.
+
+ - Solved a bug that that could cause the creation of an incompatible montage file.
+
+ - Don't invert the heartrate trace when the parent trace is inverted.
+
+ - Fixed a bug in the EDF header editor.
+
+ - Fixed a bug that resetted some settings of the program to the standard settings.
+
+
 
  version 1.58      July 10, 2016
  --------------
diff --git a/videoplayer.cpp b/videoplayer.cpp
index 38ab411..cf65b10 100644
--- a/videoplayer.cpp
+++ b/videoplayer.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/view_montage_dialog.cpp b/view_montage_dialog.cpp
index b710add..e1e37b8 100644
--- a/view_montage_dialog.cpp
+++ b/view_montage_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/view_montage_dialog.h b/view_montage_dialog.h
index efb2da7..89538a4 100644
--- a/view_montage_dialog.h
+++ b/view_montage_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/viewbuf.cpp b/viewbuf.cpp
index 027f185..d4974ac 100644
--- a/viewbuf.cpp
+++ b/viewbuf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/viewcurve.cpp b/viewcurve.cpp
index d2fbf13..04ddfe6 100644
--- a/viewcurve.cpp
+++ b/viewcurve.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -599,11 +599,18 @@ void ViewCurve::mouseReleaseEvent(QMouseEvent *release_event)
     if(crosshair_1.moving)
     {
       mainwindow->annotationEditDock->annotEditSetOnset(crosshair_1.time_relative);
+
+      if(crosshair_2.active)
+      {
+        mainwindow->annotationEditDock->annotEditSetDuration(crosshair_2.time_relative - mainwindow->annotationEditDock->annotEditGetOnset());
+      }
     }
 
     if(crosshair_2.moving)
     {
-      mainwindow->annotationEditDock->annotEditSetDuration(crosshair_2.time_relative - crosshair_1.time_relative);
+          // Don't update the onset time when changing file position
+//      mainwindow->annotationEditDock->annotEditSetDuration(crosshair_2.time_relative - crosshair_1.time_relative);
+      mainwindow->annotationEditDock->annotEditSetDuration(crosshair_2.time_relative - mainwindow->annotationEditDock->annotEditGetOnset());
     }
 
     if(annot_marker_moving)
@@ -1407,7 +1414,7 @@ void ViewCurve::drawCurve_stage_2(QPainter *painter, int w_width, int w_height,
 
   struct signalcompblock **signalcomp;
 
-  struct annotationblock *annot;
+  struct annotation_list *annot_list;
 
   QFont paintersfont;
 
@@ -1859,6 +1866,8 @@ void ViewCurve::drawCurve_stage_2(QPainter *painter, int w_width, int w_height,
     }
   }
 
+  struct annotationblock *annot;
+
   if(mainwindow->show_annot_markers)
   {
     annot_marker_pen->setColor(annot_marker_color);
@@ -1874,12 +1883,12 @@ void ViewCurve::drawCurve_stage_2(QPainter *painter, int w_width, int w_height,
 
     for(i=0; i<mainwindow->files_open; i++)
     {
-      annot = mainwindow->annotationlist[i];
-
-      j = 0;
+      annot_list = &mainwindow->edfheaderlist[i]->annot_list;
 
-      while(annot!=NULL)
+      for(j=0; j<annot_list->sz; j++)
       {
+        annot = edfplus_annotation_get_item(annot_list, j);
+
         l_tmp = annot->onset - mainwindow->edfheaderlist[i]->starttime_offset;
 
         if((l_tmp > (mainwindow->edfheaderlist[i]->viewtime - TIME_DIMENSION)) && (!annot->hided) && (!annot->hided_in_list))
@@ -1961,10 +1970,6 @@ void ViewCurve::drawCurve_stage_2(QPainter *painter, int w_width, int w_height,
             }
           }
         }
-
-        annot = annot->next_annotation;
-
-        j++;
       }
     }
   }
@@ -2079,7 +2084,8 @@ void ViewCurve::drawCurve_stage_2(QPainter *painter, int w_width, int w_height,
         }
         painter->setPen((Qt::GlobalColor)signalcomp[i]->color);
 
-        mainwindow->annotationEditDock->annotEditSetOnset(crosshair_1.time_relative);
+          // Don't update the onset time when changing file position
+//        mainwindow->annotationEditDock->annotEditSetOnset(crosshair_1.time_relative);
       }
     }
 
@@ -3509,6 +3515,7 @@ void ViewCurve::ECGdetectButton()
   strcpy(newsignalcomp->physdimension_bu, newsignalcomp->physdimension);
   strcpy(newsignalcomp->physdimension, "bpm");
   newsignalcomp->alias[0] = 0;
+  newsignalcomp->polarity = 1;
 
   if(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].bitvalue < 0.0)
   {
diff --git a/viewcurve.h b/viewcurve.h
index 462c926..df6af25 100644
--- a/viewcurve.h
+++ b/viewcurve.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/wav2edf.cpp b/wav2edf.cpp
index 8e50c9c..5140ed6 100644
--- a/wav2edf.cpp
+++ b/wav2edf.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/wav2edf.h b/wav2edf.h
index 19cc984..5973484 100644
--- a/wav2edf.h
+++ b/wav2edf.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/xml.cpp b/xml.cpp
index ab9f1a1..7adf069 100644
--- a/xml.cpp
+++ b/xml.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -873,11 +873,6 @@ int xml_goto_next_element_at_same_level(struct xml_handle *handle_p)
   {
     offset = xml_next_tag(offset, handle_p);
     if(offset < 0)  return offset;
-
-    if(handle_p->tag_search_result==NULL)
-    {
-      return XML_ERROR_GEN;
-    }
   }
 
   if(handle_p->tag_search_result[0]=='/')
diff --git a/xml.h b/xml.h
index 261a287..4a418a5 100644
--- a/xml.h
+++ b/xml.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/z_ratio_filter.cpp b/z_ratio_filter.cpp
index 1e2a880..2f537e5 100644
--- a/z_ratio_filter.cpp
+++ b/z_ratio_filter.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/z_ratio_filter.h b/z_ratio_filter.h
index 9cb0e69..5b74470 100644
--- a/z_ratio_filter.h
+++ b/z_ratio_filter.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
diff --git a/z_score_dialog.cpp b/z_score_dialog.cpp
index f47dcd7..7b7eb25 100644
--- a/z_score_dialog.cpp
+++ b/z_score_dialog.cpp
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *
@@ -1028,8 +1028,7 @@ void UI_ZScoreWindow::get_annotationsButtonClicked()
       marker_start,
       marker_end;
 
-  struct annotationblock *annotation;
-
+  struct annotationblock annotation;
 
   if((epoch_cntr < 2) || (zscore_pages < 1))
   {
@@ -1058,23 +1057,18 @@ void UI_ZScoreWindow::get_annotationsButtonClicked()
 
       if(i >= marker_start)
       {
-        annotation = (struct annotationblock *)calloc(1, sizeof(struct annotationblock));
-        if(annotation == NULL)
-        {
-          QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred (annotation).");
-          messagewindow.exec();
-          return;
-        }
-        annotation->onset = i * zscore_page_len * 2LL * TIME_DIMENSION;
+        memset(&annotation, 0, sizeof(struct annotationblock));
+
+        annotation.onset = i * zscore_page_len * 2LL * TIME_DIMENSION;
         if(awake)
         {
-          strcpy(annotation->annotation, "Wake");
+          strcpy(annotation.annotation, "Wake");
         }
         else
         {
-          strcpy(annotation->annotation, "Sleep");
+          strcpy(annotation.annotation, "Sleep");
         }
-        edfplus_annotation_add_item(&mainwindow->annotationlist[filenum], annotation);
+        edfplus_annotation_add_item(&mainwindow->edfheaderlist[filenum]->annot_list, annotation);
       }
     }
   }
@@ -1085,13 +1079,13 @@ void UI_ZScoreWindow::get_annotationsButtonClicked()
 
     mainwindow->addDockWidget(Qt::RightDockWidgetArea, mainwindow->annotations_dock[filenum]->docklist, Qt::Vertical);
 
-    if(!mainwindow->annotationlist[filenum])
+    if(edfplus_annotation_size(&mainwindow->edfheaderlist[filenum]->annot_list) < 1)
     {
       mainwindow->annotations_dock[filenum]->docklist->hide();
     }
   }
 
-  if(mainwindow->annotationlist[filenum])
+  if(edfplus_annotation_size(&mainwindow->edfheaderlist[filenum]->annot_list) > 0)
   {
     mainwindow->annotations_dock[filenum]->docklist->show();
 
diff --git a/z_score_dialog.h b/z_score_dialog.h
index bb3c518..63d4a51 100644
--- a/z_score_dialog.h
+++ b/z_score_dialog.h
@@ -3,7 +3,7 @@
 *
 * Author: Teunis van Beelen
 *
-* Copyright (C) 2012, 2013, 2014, 2015, 2016 Teunis van Beelen
+* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Teunis van Beelen
 *
 * Email: teuniz at gmail.com
 *

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/edfbrowser.git



More information about the debian-med-commit mailing list