Recent

Author Topic: [SOLVED]TaChart not showing by itself in Mac OS X  (Read 990 times)

AL

  • Full Member
  • ***
  • Posts: 211
[SOLVED]TaChart not showing by itself in Mac OS X
« on: March 05, 2020, 04:38:11 am »
I have 2 charts in a form that use several tlineseries.
In my drawing routine I use
BeginUpdate
  AddXY about 2000 points
EndUpdate.

In windows the chart is drawn and shown nicely by itself.
In Darwin the chart disapear totally.
I have to click in the chart to make it appear.
I have tried show, setfocus, click, repaint, ect. without success.
Is there a way to cure that?

Thanks for the help!
« Last Edit: March 10, 2020, 12:00:03 am by AL »
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 7948
Re: TaChart not showing by itself in Mac OS X
« Reply #1 on: March 05, 2020, 10:04:42 am »
In my drawing routine [...]
What do you understand as "drawing routine"? An OnPaint event handler? Don't do this: adding points to a series will trigger another repaint probably.

Called by a standard event, such as a button OnClick, populating a chart works flawlessly, even on the Mac:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.   N = 1000;
  4. var
  5.   i: Integer;
  6. begin
  7.   Chart1LineSeries1.BeginUpdate;
  8.   try
  9.     for i:=1 to N do
  10.       Chart1LineSeries1.AddXY(i, i+Random);
  11.   finally
  12.     Chart1LineSeries1.EndUpdate;
  13.   end;
  14. end;

NOTE: Make sure to use the BeginUpdate/EndUpdate pair only together with a try-finally block. Otherwise the series will not be repainted when an exception occurs.
           
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

AL

  • Full Member
  • ***
  • Posts: 211
Re: TaChart not showing by itself in Mac OS X
« Reply #2 on: March 06, 2020, 04:06:22 am »
The try/finally/end did not help.
The chart and series are drawing just fine.  It is the whole chart that is not visible until I click in it or move the cursor in it.  I have a stringlist that does the same thing.
As soon as I click in one of the chart ( I have 2 on my form) both charts are visible and the stringlist also.  It seems to me , the main form is not updated.
The data is gathered from the microphone in a CallBack procedure.  Then copied within the callback in a global variable, then an event is set (also from within the callback) to signal that the data is ready and this draw the chart.
I believe this not related directly to TaChart but may be to the main form which is not in the same thread as the callback?  (Os X is making the threads, not me)

This is may be too complicated, but it is working fine in Windows.

Is there a way to simulate a mouse movement in the chart.  I have a crosshair tool attached to the chart

I tried a simulation of this same process but without the Callback and the chart is drawing and showing fine.
So this is really a matter of bringing back the focus in the main thread
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1201
  • Former Delphi 1-7, 10.2 User
Re: TaChart not showing by itself in Mac OS X
« Reply #3 on: March 06, 2020, 12:38:09 pm »
I believe this not related directly to TaChart but may be to the main form which is not in the same thread as the callback?  (Os X is making the threads, not me)

Have you tried programmatically setting focus to the main form after the callback?
o Lazarus 2.1.0 r64368, FPC 3.3.1 r48100, macOS 10.14.6, Xcode 11.3.1
o Lazarus 2.1.0 r64392, FPC 3.3.1 Jan 13 21:24, macOS 11.1 (aarch64), Xcode 12.3
o Lazarus 2.1.0 r61574, FPC 3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus 2.1.0 r61574, FPC 3.0.4, Ubuntu 20.04 (Parallels VM)

wp

  • Hero Member
  • *****
  • Posts: 7948
Re: TaChart not showing by itself in Mac OS X
« Reply #4 on: March 06, 2020, 02:52:12 pm »
It's hard to help because I don't know what you are doing exactly.

"The data is gathered from the microphone in a CallBack procedure." - What kind of callback? Is it fired from a separate measurment thread? Does the thread follow the synchronizations rules (i.e. call Synchronize before communicating with the LCL)? Which software is providing the callback?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

AL

  • Full Member
  • ***
  • Posts: 211
Re: TaChart not showing by itself in Mac OS X
« Reply #5 on: March 06, 2020, 04:04:19 pm »
Have you tried programmatically setting focus to the main form after the callback?
[/quote]
I have tried Mainform.setfocus without success, is there some other command I can use?
[/quote]
It's hard to help because I don't know what you are doing exactly.
[/quote]
I realize that.
I use AudioQueue service from OS X to capture microphone input.
The audioQueue service delivers the data in its own internal buffer in a callBack procedure which is called when a buffer is full.
In the callback, I stop the Queue, I move the captured bytes to a globally declared variable to make it accessible to the main form(thread).
To inform the mainform that the chart can be drawn I set a tcheckbox to true (In the CallBack).  In the tcheckbox.change event I call a fft on the data, do some calculations, etc. and finally draw the chart with tlineseries.addxy .
As I said this is working fine in Windows where I use WaveIn which also use a CallBack.
It seems OS X is different!
I have seen in the console that After I called AudioQueuStop and exit the callback, there are still instructions that are executed parrallel to the instructions in the mainform.  This mean the AudioQueue thread is still active doing some work.
Maybe I should try AudioQueueDispose which should close the thread.  Preferably I would call that only at program closure,but I will make a test and see the outcome.
Thanks all for the help.

Edit:  Dispose Queue did not change anything.
        Application.processmessages  produce a crash
« Last Edit: March 06, 2020, 04:24:09 pm by AL »
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 211
Re: TaChart not showing by itself in Mac OS X
« Reply #6 on: March 06, 2020, 04:43:48 pm »
OK, I made some more tests.
It seemed the problem was that I called my trigger event from within the CallBack .
I made 2 tests:
1- I removed the RadioButton.checked := true from within the callback and used a timer in the main form ( before the StartQueue line) to make this call.
Result:  The chart showed normally.

2- I used a second event.
   I created a second RadioButton2.  Place the RadioButton2.checked=true in the call Back
In Radiobutton2.onchange, I call RadioButton1.checked := true
And this work!  A little weird and "Spaghetti" but it work.
If someone has a cleaner solution, please let me know.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 211
Re: TaChart not showing by itself in Mac OS X
« Reply #7 on: March 06, 2020, 07:50:04 pm »
Well, I was too quick on the trigger!

Option 2 does not work, I guess my timer in option 1 was still running and doing the job .

As far as Option 1 :
This work and display the chart:

Timer is set to 3000

Procedure TMainForm.Timer2Timer(Sender: TObject);
Begin
MainForm.RBDataReady.check := true ;
end;

This DOES NOT work :
Procedure TMainForm.Timer2Timer(Sender: TObject);
Begin
MainForm.RBDataReady.check := true ;
Timer2.enabled := False ;
end;

Strange.  If I stop the Timer then it does not work.  I cannot undertstand.

This is becomming complicated.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1201
  • Former Delphi 1-7, 10.2 User
Re: TaChart not showing by itself in Mac OS X
« Reply #8 on: March 07, 2020, 01:31:17 am »
I suspect thread synchronization or timing issues, all way out of my area of expertise I'm afraid.
o Lazarus 2.1.0 r64368, FPC 3.3.1 r48100, macOS 10.14.6, Xcode 11.3.1
o Lazarus 2.1.0 r64392, FPC 3.3.1 Jan 13 21:24, macOS 11.1 (aarch64), Xcode 12.3
o Lazarus 2.1.0 r61574, FPC 3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus 2.1.0 r61574, FPC 3.0.4, Ubuntu 20.04 (Parallels VM)

AL

  • Full Member
  • ***
  • Posts: 211
Re: TaChart not showing by itself in Mac OS X
« Reply #9 on: March 07, 2020, 03:33:59 pm »
Finally solved my problem by doing:

Do as little as possible in the CallBack.
I removed almost all from the CallBack except the move from AudioQueue buffer to the global buffer.
Also removed the NSLog instructions that surely slow things down.
AudioQueue is not reliable on the data size.  The buffer transmitted is not always full and you may need 2 callback to fill the global buffer.
I set a "BufferIsFull" boolean in the callback and watch it from outside of the callback with a wait loop that is:
====================
AudioQueueStart ;
While not BufferIsFull do
  begin
  Sleep(100);
  Application.processmessages; // this keep the main form up to date
 end;
... do logic here and AudioQueueStop if buffer is satisfactory
call event that draw the charts.
=====================

So far this is working.
Thank you for the help
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

 

TinyPortal © 2005-2018