How can I output Stream_event variables on the console?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I output Stream_event variables on the console?

Marc Hohl
Hello,

assuming that I define

Stream_event *event = note_events_[i];

(within a for-loop, of course)

how can I print the contents of "event" on the console?
I will trace some variables to get an idea of whats
going on inside the loop; I didn't need some fancy well-formatted
output.

Thanks in advance

Marc

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Carl Sorensen



On 2/24/10 1:51 AM, "Marc Hohl" <[hidden email]> wrote:

> Hello,
>
> assuming that I define
>
> Stream_event *event = note_events_[i];
>
> (within a for-loop, of course)
>
> how can I print the contents of "event" on the console?
> I will trace some variables to get an idea of whats
> going on inside the loop; I didn't need some fancy well-formatted
> output.

IIRC, you can get a display on the console by using gdb with the .gdbinit
file listed in the CG, section 9.6.2, setting a breakpoint in your routine,
and issuing the following command from the console when you've reached the
breakpoint:

pmusic event

Once you've verified that this works, you could also execute those same
Scheme procedures by using scm_call_1 from the C++ code if you didn't want
to go through the debugger.

HTH,

Carl


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

reinhold
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am Mittwoch, 24. Februar 2010 12:26:15 schrieb Carl Sorensen:

> On 2/24/10 1:51 AM, "Marc Hohl" <[hidden email]> wrote:
> > Hello,
> >
> > assuming that I define
> >
> > Stream_event *event = note_events_[i];
> >
> > (within a for-loop, of course)
> >
> > how can I print the contents of "event" on the console?
> > I will trace some variables to get an idea of whats
> > going on inside the loop; I didn't need some fancy well-formatted
> > output.
>
> IIRC, you can get a display on the console by using gdb with the .gdbinit
> file listed in the CG, section 9.6.2, setting a breakpoint in your routine,
> and issuing the following command from the console when you've reached the
> breakpoint:
>
> pmusic event
>
> Once you've verified that this works, you could also execute those same
> Scheme procedures by using scm_call_1 from the C++ code if you didn't want
> to go through the debugger.

Or you can simply call
  int Prob::print_smob (SCM smob, SCM port, scm_print_state*)
(Stream_event is a class derived from Prob)


Cheers,
Reinhold
- --
- ------------------------------------------------------------------
Reinhold Kainhofer, [hidden email], http://reinhold.kainhofer.com/
 * Financial & Actuarial Math., Vienna Univ. of Technology, Austria
 * http://www.fam.tuwien.ac.at/, DVR: 0005886
 * LilyPond, Music typesetting, http://www.lilypond.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFLhRvZTqjEwhXvPN0RAuWnAJ0QNFwDUt21z7V/43YCL2Qt+F/nNwCcDefK
sTn4XXBhI36VlDUPPXALlmY=
=Lkj9
-----END PGP SIGNATURE-----

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Carl Sorensen



On 2/24/10 5:30 AM, "Reinhold Kainhofer" <[hidden email]> wrote:


> Or you can simply call
>   int Prob::print_smob (SCM smob, SCM port, scm_print_state*)
> (Stream_event is a class derived from Prob)
>

Yes, that would definitely be the easiest way.

Thanks!

Carl


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Marc Hohl
In reply to this post by reinhold
Hello Reinhold, hello Carl,

Reinhold Kainhofer schrieb:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Am Mittwoch, 24. Februar 2010 12:26:15 schrieb Carl Sorensen:
>  
>> On 2/24/10 1:51 AM, "Marc Hohl" <[hidden email]> wrote:
>>    
>>> Hello,
>>>
>>> assuming that I define
>>>
>>> Stream_event *event = note_events_[i];
>>>
>>> (within a for-loop, of course)
>>>
>>> how can I print the contents of "event" on the console?
>>> I will trace some variables to get an idea of whats
>>> going on inside the loop; I didn't need some fancy well-formatted
>>> output.
>>>      
>> IIRC, you can get a display on the console by using gdb with the .gdbinit
>> file listed in the CG, section 9.6.2, setting a breakpoint in your routine,
>>    
How can I set a breakpoint?

>> and issuing the following command from the console when you've reached the
>> breakpoint:
>>
>> pmusic event
>>
>> Once you've verified that this works, you could also execute those same
>> Scheme procedures by using scm_call_1 from the C++ code if you didn't want
>> to go through the debugger.
>>    
>
> Or you can simply call
>   int Prob::print_smob (SCM smob, SCM port, scm_print_state*)
> (Stream_event is a class derived from Prob)
>  
I assume that just pasting this line under

Stream_event *event = note_events_[i];

is not the whole deal (I tried this, it didn't work).

I'm sorry to say, but at the moment I am writing C stuff by looking at some
engraver files and copy/paste everything into my file that looks as if
it could
work. That's not really satisfying, but I try to learn it that way.

Marc



---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Neil Puttock
On 24 February 2010 19:28, Marc Hohl <[hidden email]> wrote:

> How can I set a breakpoint?

break file-name:line-no

or

break Class_name::method

> I assume that just pasting this line under
>
> Stream_event *event = note_events_[i];
>
> is not the whole deal (I tried this, it didn't work).

I don't think you can use print_smob () here; it's part of Guile's
requirements for creating a smob, but isn't meant to be called
directly from C++ (in fact, it's private so you can't call it anyway).

I'd suggest using ly_display_scm () instead, e.g.,

// display mutable properties of ev
ly_display_scm (ev->get_property_alist (true));

Cheers,
Neil

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Carl Sorensen
In reply to this post by Marc Hohl



On 2/24/10 12:28 PM, "Marc Hohl" <[hidden email]> wrote:

> Hello Reinhold, hello Carl,
>
> Reinhold Kainhofer schrieb:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Am Mittwoch, 24. Februar 2010 12:26:15 schrieb Carl Sorensen:
>>  
>>> On 2/24/10 1:51 AM, "Marc Hohl" <[hidden email]> wrote:
>>>    
> How can I set a breakpoint?

Start by running gdb for lilypond:

gdb lilypond

at the gdb prompt, set a breakpoint:

b Class::function

(with Class::function replaced by the actual routine you want to stop in)

or

b sourcefile.cc:line

where sourcefile.cc is the name of the source file of the code you're trying
to test (no lily/ is necessary) and line is the line number.

Once you have your breakpoint set, run the code

run myfile.ly

lilypond will then run, and stop at the breakpoint.

Once it's stopped at the breakpoint, use pmusic to print the music event.

>>> and issuing the following command from the console when you've reached the
>>> breakpoint:
>>>
>>> pmusic event
>>>
>>> Once you've verified that this works, you could also execute those same
>>> Scheme procedures by using scm_call_1 from the C++ code if you didn't want
>>> to go through the debugger.
>>>    
>>
>> Or you can simply call
>>   int Prob::print_smob (SCM smob, SCM port, scm_print_state*)
>> (Stream_event is a class derived from Prob)
>>  
> I assume that just pasting this line under
>
> Stream_event *event = note_events_[i];
>
> is not the whole deal (I tried this, it didn't work).

The way it would work if it did would be to write

event->print_smob(event->self_scm());

or something similar to that.


>
> I'm sorry to say, but at the moment I am writing C stuff by looking at some
> engraver files and copy/paste everything into my file that looks as if
> it could
> work. That's not really satisfying, but I try to learn it that way.

Ouch, that's really hard.  Even if you have the right idea, the syntax of
C++ can be so picky that you get errors from bad syntax.

Perhaps you could post some test code, and get some feedback on it.

Thanks,

Carl


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Marc Hohl
In reply to this post by Neil Puttock
Neil Puttock schrieb:

> On 24 February 2010 19:28, Marc Hohl <[hidden email]> wrote:
>
>  
> [...]
>
> I'd suggest using ly_display_scm () instead, e.g.,
>
> // display mutable properties of ev
> ly_display_scm (ev->get_property_alist (true));
>  
Great! This was exactly the command I was looking for.

Marc
> Cheers,
> Neil
>
> ---
> ----
> Join the Frogs!
>
>
>  


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Marc Hohl
In reply to this post by Carl Sorensen
Carl Sorensen schrieb:

>
> On 2/24/10 12:28 PM, "Marc Hohl" <[hidden email]> wrote:
>
>  
>> Hello Reinhold, hello Carl,
>>
>> Reinhold Kainhofer schrieb:
>>    
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Am Mittwoch, 24. Februar 2010 12:26:15 schrieb Carl Sorensen:
>>>  
>>>      
>>>> On 2/24/10 1:51 AM, "Marc Hohl" <[hidden email]> wrote:
>>>>    
>>>>        
>> How can I set a breakpoint?
>>    
>
> Start by running gdb for lilypond:
>
> gdb lilypond
>
> at the gdb prompt, set a breakpoint:
>
> b Class::function
>
> (with Class::function replaced by the actual routine you want to stop in)
>
> or
>
> b sourcefile.cc:line
>
> where sourcefile.cc is the name of the source file of the code you're trying
> to test (no lily/ is necessary) and line is the line number.
>
> Once you have your breakpoint set, run the code
>
> run myfile.ly
>
> lilypond will then run, and stop at the breakpoint.
>
> Once it's stopped at the breakpoint, use pmusic to print the music event.
>  
I see. Thanks for the detailed explanation. I read through CG 9.6.2
several times without
getting a glimpse. And now I see that the first commands in .gdbinit do
exactly the same, i.e.
defining breakpoints ("b" stands for "breakpoint", well sure).

Should this information be included in 9.6.2? Probably not, because most
people who want
to do some C++ hacking are familiar enogh with this stuff.

> [...]
>
>
>  
>> I'm sorry to say, but at the moment I am writing C stuff by looking at some
>> engraver files and copy/paste everything into my file that looks as if
>> it could
>> work. That's not really satisfying, but I try to learn it that way.
>>    
>
> Ouch, that's really hard.  Even if you have the right idea, the syntax of
> C++ can be so picky that you get errors from bad syntax.
>
> Perhaps you could post some test code, and get some feedback on it.
>  
I have Bjarne Stroustrup's C++ book on my desk, but 720 pages are a lot
of stuff,
and it looks as if the book is mostly helpful to poeple who have already
some (more) experience in writing bigger projects in C.

I started uploading patches to rietveld, and from time to time, I will
update the
files and include comments describing what I want to achieve if I can't
get it
to work.

Thanks for your patience ...

Marc
> Thanks,
>
> Carl
>
>
>  


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Marc Hohl
In reply to this post by Carl Sorensen
Carl Sorensen schrieb:
> [...]
>
> Perhaps you could post some test code, and get some feedback on it.
>  
I have uploaded a new patch set (http://codereview.appspot.com/216051)
where I need some help. It is described in the
string-bend-engraver.cc, but here's a quick summary:

1) am I on the right track? I did some changes in the roadmap, and I am
    quite sure that I described the way the new engraver has to be
estabished
    properly according to Carl's suggestions - or am I still missing
something?

2) I need to convert the entries in the vector string_events into integers
which serve as indices for the pitch vector. How can I achieve that?

3) I need to extract the corresponding pitch information. Would
  Pitch *pitch = unsmob_pitch (note_events_[i]->get_property ("pitch"));
  do what I want?


Thanks in advance.

Marc



---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: How can I output Stream_event variables on the console?

Carl Sorensen



On 2/25/10 1:07 AM, "Marc Hohl" <[hidden email]> wrote:

> Carl Sorensen schrieb:
>> [...]
>>
>> Perhaps you could post some test code, and get some feedback on it.
>>  
> I have uploaded a new patch set (http://codereview.appspot.com/216051)
> where I need some help. It is described in the
> string-bend-engraver.cc, but here's a quick summary:
>
> 1) am I on the right track? I did some changes in the roadmap, and I am
>     quite sure that I described the way the new engraver has to be
> estabished
>     properly according to Carl's suggestions - or am I still missing
> something?

On the right track, but one change -- reference pitches should be
established in the tab_note_heads engraver, not the string_bend engraver.
See my comments in the file.

>
> 2) I need to convert the entries in the vector string_events into integers
> which serve as indices for the pitch vector. How can I achieve that?

string_events[i]->get-property("string-number")
 
> 3) I need to extract the corresponding pitch information. Would
>   Pitch *pitch = unsmob_pitch (note_events_[i]->get_property ("pitch"));
>   do what I want?

Yes, it should.

Thanks,

Carl


---
----
Join the Frogs!