multiple colors in smoothbar theme

I'm currently working on a customized beamer theme, and I decided that I like the smoothbars theme a lot. However, what I'd like to change is that I want the bar itself to be split in several horizontal compartments, one per section, with every section having a different color selected from a cycle, instead of the entire bar being unicolor.

As I figured that this would require me looking into the actual code of the smoothbars theme, this is what I did.

I started with looking in the code and finding the line

\insertnavigation{\paperwidth}


which expands to an expression with a wealth of skipping and boxing commands, but also contains

\dohead


which then expands to a loop

\beamer@headcounter =0\relax
\loop
\repeat


Naively, I thought that this loop would run over the sections and just print the section titles in some box environment, so I looked at the contents of \csname @@head\the \beamer@headcounter \endcsname. Interestingly, these precisely expand to the contents of the lines of the *.nav file, for example

\sectionentry {1}{Introduction}{2}{Introduction}{0}


which sort of makes sense, given how the .nav file contains all the necessary information - but I'm confused by the fact that not only the section headings, but all sorts of other things turn up as well, like

\beamer@framepages {1}{1}


or

\beamer@sectionpages {1}{1}
\beamer@subsectionpages {1}{1}


I don't really understand what is going on here. What is the most sensible part to intervene in order to change the background color of the smoothbar behind every section in a cycle of, say, 5 different colors?

Edit

As requested, here is an MWE. It's not really an MWE in the sense that it produces the problem, as I just don't understand what's going on well enough to make any serious attempt at getting the coloring right. However, I don't understand why uncommenting the \colorbox command results in the layout being completely disrupted, so this might be a good place to start.

\documentclass{beamer}
\usecolortheme{orchid}
\usecolortheme{whale}

\makeatletter
% this code is the result of me collecting the bits & pieces
% from the macro definitions in beamerouterthemesmoothbars.sty
\vbox {%
\beamer@xpos =0\relax \beamer@ypos=1\relax
\hbox to \paperwidth{
% this is some spacing that I don't really understand what it does
\hskip .3cm\setbox\beamer@sectionbox =\hbox {\kern 1sp}
\hskip -1.875ex plus-1fill
\global \beamer@section@min@dim \z@
% loop over the entries of the *.nav file
\loop
% I would have expected that putting a 'colorbox' here would do the trick of coloring the individual section headings
% however, very strange things happen when uncommenting the following line, which probably has to do with the fact
% that the loop runs over 17 entries (instead of just 2, as I would have expected)
%\colorbox{red}{
%}
\repeat
% some more spacing commands
\beamer@section@set@min@width \box \beamer@sectionbox
\hfil \hskip .3cm
}
}
}%
\makeatother

% now comes some dummy code just to have some slides to look at
\title{Hello World}

\begin{document}

\maketitle

\section{Introduction}

\begin{frame}{Hello!}
\begin{itemize}
\item Hello!
\end{itemize}
\end{frame}

\section{Further stuff}

\begin{frame}{Hello!}
\begin{itemize}
\item Hello!
\end{itemize}
\end{frame}

\end{document}

• Can you add a MWE in order to give us something to start with? – user36296 Feb 6 '17 at 18:22
• Thanks for the suggestion. I've added an MWE, if you want to call it like that :-) I hope somebody can make me understand what's happening here :-) – carsten Feb 7 '17 at 0:53
• What is the purpose of the additional package you tried to edit in? – user36296 Feb 7 '17 at 14:02
• It doesn't compile for me without it, as it defines the \pretocmd command. – carsten Feb 7 '17 at 14:26
• With pdflatex from texlive 2016 I had no problems. – user36296 Feb 7 '17 at 14:27

Why didn't I discover colorseries earlier? They are really handy!

The following assumes sections of a similar length:

\documentclass{beamer}
\usecolortheme{orchid}
\usecolortheme{whale}
\useoutertheme{smoothbars}

\usepackage{tikz}

\definecolorseries{foo}{rgb}{last}{red}{blue}
\resetcolorseries[3]{foo}

\makeatletter
\foreach \i in {1,...,\number\totvalue{totalsection}}{%
{\color{foo!![\i]}\rule{\dimexpr\paperwidth/\number\totvalue{totalsection}\relax}{7ex}}%
}
\vskip-7ex%
\end{beamercolorbox}%
}%
\makeatother

\usepackage{totcount}

\newcounter{totalsection}
\regtotcounter{totalsection}

\AtBeginDocument{%
\pretocmd{\section}{\refstepcounter{totalsection}}{\typeout{Yes, prepending was successful}}{\typeout{No, prepending was not it was successful}}%
}%

\title{Hello World}

\begin{document}

\maketitle

\section{Introduction}

\begin{frame}{Hello!}
\begin{itemize}
\item Hello!
\end{itemize}
\end{frame}

\section{Further stuff}

\begin{frame}{Hello!}
\begin{itemize}
\item Hello!
\end{itemize}
\end{frame}

\section{some stuff}

\begin{frame}{Hello!}
\begin{itemize}
\item Hello!
\end{itemize}
\end{frame}

\end{document}