Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / WPF

PSAM WPF Control Library

Rate me:
Please Sign up or sign in to vote.
5.00/5 (20 votes)
19 Jul 2018BSD2 min read 94K   8.2K   56   26
PSAM Control Library ported over to WPF

Introduction

UPDATE: This article describes an old .NET project which eventually evolved into bigger open source framework Manufaktura.Controls. You can read about it here: https://www.codeproject.com/Articles/1252423/Music-Notation-in-NET 

PSAM WPF Control Library is a WPF version of PSAM Control Library containing the IncipitViewer control for drawing musical notes which can be read from MusicXml file or added programmatically. PSAM WPF Control Library requires PSAM Control Library to run because it uses some of PSAM Control Library's classes. PSAM WPF Control Library is written in C# and XAML under Microsoft Visual Studio Express.

Using the Code

IncipitViewerWPF control requires special font to draw notes and other musical symbols. You can create your own font or use the included font Polihymnia which is based on Ben Laenen's Euterpe font and distributed under Sil Open Font Licence. Of course, you have to install the font in your fonts directory to display notes properly.

You can load a MusicXml file or add notes programmatically the same way as it is done in PSAM Control Library. Read the article about PSAM Control Library for details.

The control looks like that:

psamwpfcontrollibrary/example1.png

Because it's a WPF control, you can apply fancy effects like these:

psamwpfcontrollibrary/example2.png

psamwpfcontrollibrary/example3.png

Printing is even simpler than in PSAM Control Library. You just have to write the following code:

C#
PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{
     dialog.PrintVisual(viewer, "Test");
} 

where viewer is a IncipitViewerWPF control. Sample printout:

psamwpfcontrollibrary/example4.png

Points of Interest

Porting PSAM Control Library to WPF was quite simple. I made some changes to PSAM Control Library, namely I added a new interface IIncipitViewer which represents IncipitViewer's methods and properties and then I implemented this interface in IncipitViewerWPF class. I also moved ParseXml method from IncipitViewer to a new class called XmlParser so I didn't have to rewrite this method in IncipitViewerWPF class. To draw notes and musical symbols, I use an overridden OnRender method and a DrawingContext object.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Poland Poland
I graduated from Adam Mickiewicz University in Poznań where I completed a MA degree in computer science (MA thesis: Analysis of Sound of Viola da Gamba and Human Voice and an Attempt of Comparison of Their Timbres Using Various Techniques of Digital Signal Analysis) and a bachelor degree in musicology (BA thesis: Continuity and Transitions in European Music Theory Illustrated by the Example of 3rd part of Zarlino's Institutioni Harmoniche and Bernhard's Tractatus Compositionis Augmentatus). I also graduated from a solo singing class in Fryderyk Chopin Musical School in Poznań. I'm a self-taught composer and a member of informal international group Vox Saeculorum, gathering composers, which common goal is to revive the old (mainly baroque) styles and composing traditions in contemporary written music. I'm the annual participant of International Summer School of Early Music in Lidzbark Warmiński.

Comments and Discussions

 
Questionexcuseme! how to install? Pin
Fausto Ivan Felix Lespron4-Jan-16 20:11
Fausto Ivan Felix Lespron4-Jan-16 20:11 
AnswerRe: excuseme! how to install? Pin
Ajcek847-Jun-16 22:13
Ajcek847-Jun-16 22:13 
Questionadding library to references Pin
MTaunton19-Aug-15 9:39
MTaunton19-Aug-15 9:39 
AnswerRe: adding library to references Pin
Ajcek847-Jun-16 22:12
Ajcek847-Jun-16 22:12 
SuggestionRefactoring & Silverlight porting Pin
Ivan Kochurkin26-Jun-11 22:09
Ivan Kochurkin26-Jun-11 22:09 
GeneralRe: Refactoring & Silverlight porting Pin
Ajcek8426-Jun-11 22:24
Ajcek8426-Jun-11 22:24 
GeneralRe: Refactoring & Silverlight porting Pin
Ivan Kochurkin26-Jun-11 22:45
Ivan Kochurkin26-Jun-11 22:45 
GeneralRe: Refactoring & Silverlight porting Pin
Ajcek8424-Jul-11 2:54
Ajcek8424-Jul-11 2:54 
GeneralRe: Refactoring & Silverlight porting Pin
mcraig1555-Aug-11 4:28
mcraig1555-Aug-11 4:28 
Kvanttt, I'm excited to see the port to silverlight. When do you plan on posting it CodeProject?

Thanks in advance
NewsRe: Refactoring & Silverlight porting Pin
Ivan Kochurkin14-Aug-11 2:01
Ivan Kochurkin14-Aug-11 2:01 
GeneralRe: Refactoring & Silverlight porting Pin
mcraig1553-Oct-11 5:20
mcraig1553-Oct-11 5:20 
GeneralRe: Refactoring & Silverlight porting Pin
Ajcek8417-May-14 1:43
Ajcek8417-May-14 1:43 
GeneralRe: Refactoring & Silverlight porting Pin
Ajcek844-Jan-15 22:41
Ajcek844-Jan-15 22:41 
GeneralVery good work! Question about multiple staves Pin
mcraig15520-May-11 7:48
mcraig15520-May-11 7:48 
GeneralRe: Very good work! Question about multiple staves Pin
Ajcek8421-May-11 0:17
Ajcek8421-May-11 0:17 
GeneralRe: Very good work! Question about multiple staves Pin
mcraig15521-May-11 1:41
mcraig15521-May-11 1:41 
GeneralRe: Very good work! Question about multiple staves Pin
Tipochek2-Dec-13 15:23
Tipochek2-Dec-13 15:23 
GeneralExcellent! Vote of 5, and two questions: Pin
GProssliner29-Mar-11 3:22
GProssliner29-Mar-11 3:22 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
Ajcek8429-Mar-11 4:06
Ajcek8429-Mar-11 4:06 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
GProssliner30-Mar-11 0:06
GProssliner30-Mar-11 0:06 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
Ajcek8431-Mar-11 0:13
Ajcek8431-Mar-11 0:13 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
GProssliner31-Mar-11 22:45
GProssliner31-Mar-11 22:45 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
Ajcek841-Apr-11 0:53
Ajcek841-Apr-11 0:53 
GeneralRe: Excellent! Vote of 5, and two questions: Pin
davidorn25-Jul-11 19:10
davidorn25-Jul-11 19:10 
GeneralMy vote of 5 Pin
KenJohnson9-Jul-10 20:48
KenJohnson9-Jul-10 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.