Modularity of class number generating functions